deep-copy

Library of Objects - Access Index Value or Object Itself? (e.g., deep vs. shallow copy perhaps?)

I've always been confused/unsure about how .Net copies references. Let's say I have a Bitmap object for GDI+. dim foo as new bitmap("c:\foo.bmp") 'Foo' holds the bitmap object. Now let's say I do this. dim bar as bitmap = foo Is this a shallow copy or a deep copy? If I set foo equal to nothing, does bar suddenly reference 'nothing...

How to create an operator for deep copy/cloning of objects in Ruby?

I would like to achieve the following by introducing a new operator (e.g. :=) a := b = {} b[1] = 2 p a # => {} p b # => {1=>2} As far as I understand, I need to modify the Object class, but I don't know what to do in order to get what I want. require 'superators' class Object superator ":=" operand # update, must be: superator ":=...

CXF: Cloneable classes from wsdl2java?

Hi, Is it possible to have CXF's wsdl2java emit cloneable classes? Maybe via some option or a plug-in? What I need to do is copy by value a rather complex schema structure from one object tree to another and would rather not get/set each member value by hand or touch the generated classes by hand. /Björn ...

Problem with deepcopy?

Source from copy import deepcopy class Field(object): def __init__(self): self.errors = [] class BaseForm(object): pass class MetaForm(type): def __new__(cls, name, bases, attrs): attrs['fields'] = dict([(name, deepcopy(attrs.pop(name))) for name, obj in attrs.items() if isinstance(obj, Field)]) re...

How to do deep copy of NHibernate Objects ?

Hi all, I am trying to do a deep copy of a NHibernate object (proxy wrapper). I want to do a copy of lazily loaded things also, except the Id of each inner object of the parent object, as it should be generated when I save the new object which is the result of deep copy. I have tried to use serialization and also tried using AutoMapper...

Simple Question - Shallow Copy (VB.Net)

OK, I always get confused about this. Let's say I have this code. Public Sub Bar(byRef pMap as clsMap) Dim foo as new FooClass() pMap.listOfFoo.Add(foo) end Sub This would mean that referencing 'Foo' or the item stored in 'listOfFoo' would reference the same object, right? If I was to change a property of 'foo' - but not change it t...

Deep copy duplicate() of Java's ByteBuffer

java.nio.ByteBuffer#duplicate() returns a new byte buffer that shares the old buffer's content. Changes to the old buffer's content will be visible in the new buffer, and vice versa. What if I want a deep copy of the byte buffer? ...

deep copy of doctrine record

I want to make a deep copy/clone of a doctrine record in a symfony project. The existing copy($deep)-method doesn't work properly with $deep=true. For an example let's have a look at a classroom lesson. This lesson has a start and end date and between them there are several breaks. This classroom is in a buildung. lesson-break is a one...

Custom class instance copying

Hi, I'm new to programming and Python. The problem I have is with removing list elements that are instances of custom class. import copy class some_class: pass x = some_class() x.attr1 = 5 y = some_class() y.attr1 = 5 z = [x,y] zcopy = copy.deepcopy(z) z.remove(zcopy[0]) This returns: ValueError: list.remove(x): x not in list ...

C++: Updating pointers in deep copy (efficiently)

My question is best illustrated with a code sample, so let's just start off with that: class Game { // All this vector does is establish ownership over the Card objects // It is initialized with data when Game is created and then is never // changed. vector<shared_ptr<Card> > m_cards; // And then we have a bunch of ...

C# Deep Copying Tree Structures with BinaryFormatter

EDIT 1 Kent has alleviated my fears. However, I've found one exception to the rule. I wrote a method for the Node class that would traverse up through the hierarchy until it got to the root Node and return its hash code. The hash code's the same all the way down the line except for one single object. In a word, RAGE. I'm at the end o...

Create a Deep Copy in C#

I want to make a deep copy of an object so I could change the the new copy and still have the option to cancel my changes and get back the original object. My problem here is that the object can be of any type, even from an unknown assembly. I can not use BinaryFormatter or XmlSerializer, because the object unnecessarily have [Serializa...

Python: problem with deepcopy(ing) a TypedList class inheriting from list and overriding append

I don't understand why the new instance of the TypeList class does not have a my_type attribute. t.i.a. for any help Here is my code: import copy class TypedList(list): def __init__(self, typeof, iterable=''): """ Initialize the typed list. Examples: tmp = TypedList(str, 'foobar') # OK tmp...

Deep copy of a derived python object

I have an object in python that is derived from QtGui.QGraphicsPixmapItem with a few basic attributes and methods. After calling deepcopy on a reference to this object, I get an error saying that underlying C/C++ object has been deleted when I try to use the copy. I had received this error before, and it occured when I didn't call the ba...

Cant copy construction be done without creating an explicit function in the pure virtual base class?

My objective is to do a deep copy of a class, but a virtual class is causing trouble. #include<iostream> using namespace std; class Vir//pure virtual class { public: virtual void hi()=0; }; class Handler:public Vir { public: int i; Handler() {} Handler(int val):i(val) {} void hi() {cout<<"Value of i="<<i<<e...

Creating clone of an object not working with virtual base class

#include<iostream> using namespace std; class Something { public: int j; Something():j(20) {cout<<"Something initialized. j="<<j<<endl;} }; class Base { private: Base(const Base&) {} public: Base() {} virtual Base *clone() { return new Base(*this); } virtual void ID() { cout<<"BASE"<<endl; } }; class Derived ...

Deep copy of vector<Point> myArr

In order to make a deep copy of myArr, vector <Point> myArr; where Point is a class with 2 ints as members, Do I need to do something special? or is ok with vector <Point> otherArr = myArr; I need to delete some points in otherArr but at the same time I need all the points in myArr for later usage. thanks in advance ...

How to (deep)copy a map from a const object

Hello, I have another problem I can't seem to solve..., or find on this site... I have an object (called DataObject) with a map, declared as follows: std::map<size_t, DataElement*> dataElements; Now i have a copy function (used in the copy constructor): void DataObject::copy(DataObject const &other) { //here some code to clean...