deep-copy

Force deep copy of Django FileField object (mainly new file itself)

两盒软妹~` 提交于 2020-01-05 18:36:22
问题 I have this model: class DocVersion(Commentable): name = models.CharField( 'Version', max_length=100, ) docfile = models.FileField( 'File', upload_to='content/%Y/%m/%d/%H/%M/%S', ) created = models.DateTimeField( 'Created', auto_now_add=True, ) creater = models.ForeignKey( User, ) class Document(DocumentBase): #..... blah ..... versions = models.ManyToManyField( DocVersion, ) In a function in a view, I have this function to do a deep copy of the DocVersion like so: def cp_document(transfer

Cloning WPF controls and object hierarchies

*爱你&永不变心* 提交于 2020-01-04 15:31:12
问题 I have some problems cloning an object hierarchie. It's a toolkit for modelling applications, the toolbox contains class instances as prototypes. But I'm having a hard time cloning these :) The following code shows the problem: public abstract class Shape { protected List<UIElement> elements; private Canvas canvas; ... public Canvas getCanvas() { ... }; } public class MovableShape : Shape { protected ... propertyA; private ... propertyXY; ... } public abstract class AbstractLayout :

Deep copy entity with NHibernate

雨燕双飞 提交于 2020-01-04 05:09:52
问题 I am currently starting a new ASP.NET MVC Project at work where we need to generate a project cost estimate. We are using NHibernate, ASP.NET MVC 1.0 and StructureMap. The client wants to be able to fill all the information about the project, the information is in different pages and we need to persist in between each post back. The client does not want to have the option to Save it under a name when it is completed, but we want to persist it in the database even when he did not save it yet.

java - copying array list

眉间皱痕 提交于 2020-01-03 15:33:24
问题 So the below method I'm aware causes both variables to point to the same object, but if I did want to find the simplest method to has ArrayList s2 exactly the same as s1, how would I do this? public static void main(String[] args) { ArrayList<String> s1 = new ArrayList<String>(); for (int i = 1; i <= 3; i++) { s1.add(""+i); } ArrayList<String> s2 = s1; } 回答1: You should create s2 with s1 as parameter. public static void main(String[] args) { ArrayList<String> s1 = new ArrayList<String>(); for

Polymorphic copy in Java

大憨熊 提交于 2020-01-03 13:20:09
问题 I've suddenly encountered a problem of making a deep polymorphic copy in Java. Implementing Clonable solves the problem in my case, but it is often referred as a "bad" technique. So, here are my attempts to find a "no-Clonable" solution: public class Parent { int x; public Parent() {} public Parent(int x0) { x = x0; } public Parent copy() { Parent b = new Parent(); b.assign(this); return b; } protected void assign(Parent c) { x = c.x; } @Override public String toString() { return getClass()

Cloning objects in C#

依然范特西╮ 提交于 2020-01-02 06:12:11
问题 I defined next class with virtual properties: public class Order: BaseEPharmObject { public Order() { } public virtual Guid Id { get; set; } public virtual DateTime Created { get; set; } public virtual DateTime? Closed { get; set; } public virtual OrderResult OrderResult { get; set; } public virtual decimal Balance { get; set; } public virtual Customer Customer { get; set; } public virtual Shift Shift { get; set; } public virtual Order LinkedOrder { get; set; } public virtual User CreatedBy {

R: deep copy a function argument

痞子三分冷 提交于 2020-01-02 03:37:09
问题 Consider the following code i = 3 j = i i = 4 # j != i However, what I want is i = 3 f <- function(x, j=i) x * j i = 4 f(4) # 16, but i want it to be 12 In case you are wondering why I want to do this you could consider this code - the application is a multiple decrements model. The diagonals of a transition matrix are the sum of the other decrements in that row. I would like to define the decrements I need than calculate the other functions using those decrements. In this case, I only need

copy constructor of a class which has self-pointer to itself in C++?

大兔子大兔子 提交于 2020-01-01 19:34:07
问题 I wanted to ask that how will we implement a copy constructor of a class which has self pointer to itself as its data member, i want to implement a deep copy, class City { string name; City* parent; public: City(string nam, double dcov); City(string nam, double dcov, City* c); City(const City& obj) { this-> name = obj.name; // how to assign parent parent = new City(??) } ~City(); void setName(string name1); void setDistanceCovered(int dist); string getName(); double getDistanceCovered(); City

Copy constructor: deep copying an abstract class

拜拜、爱过 提交于 2020-01-01 08:26:20
问题 Suppose I have the following (simplified case): class Color; class IColor { public: virtual Color getValue(const float u, const float v) const = 0; }; class Color : public IColor { public: float r,g,b; Color(float ar, float ag, float ab) : r(ar), g(ag), b(ab) {} Color getValue(const float u, const float v) const { return Color(r, g, b) } } class Material { private: IColor* _color; public: Material(); Material(const Material& m); } Now, is there any way for me to do a deep copy of the abstract

Deep Copy of OpenCV cv::Mat

巧了我就是萌 提交于 2019-12-31 09:11:53
问题 The behaviour of copying cv::Mat is confusing me. I understand from the documentation that Mat::copyTo() is deep copy while the assignment operator is not. My questions: what should I do to return a cv::Mat from a function, such as: cv::Mat func() ? According to the documentation, if I return a cv::Mat it'll have no use, because after the function returns the local copy of the cv::Mat in that function will be destroyed and therefore the one accepting the returned value outside the function