deep-copy

Deep Copy ASP.NET GridView

I'm creating a custom control for a group of peers and I'm running into a road block. The purpose of the control is to provide an easy way to implement grids with nesting, sorting, etc. To create the nesting, I have a child GridView that serves as a blueprint for the rest of the children. I allow the developer to configure it how they w...

Deep copy of 2D array in Scala?

How do I do a deep copy of a 2D array in Scala? For example val a = Array[Array[Int]](2,3) a(1,0) = 12 I want val b to copy values of a but without pointing to the same array. ...

C++: shallow/deep copy of std::map

How would I best implement these? I thought of something like this: using namespace std; shape_container shape_container::clone_deep () const { shape_container* ptr = new shape_container(); copy( data.begin(), data.end(), (*ptr).begin() ); return *ptr; } shape_container shape_contai...

Deepcopy a simple Python object

I have an object which defines a __deepcopy__ method. I would like a function that will deepcopy it not by the method given by it, but in the default way that objects of the class object are copied. How could I do that? I think I could try to code it but there are probably many "gotchas" I won't be thinking of. The reason I'm doing it ...

How to deep copy an object containing a lambda expression?

It's me again, about my Mega Man game. I switched over to a component system so that objects could be data driven. It's going ok but I've hit a problem. My objects have states, specified with an input file. Those states have triggers to transition them to other states. The conditions for a state change are also in the input file, and ar...

Does Enumerable.Repeat() do a deep copy ?

Hi all, If I use the following: var myList = Enumerable.Repeat(myCustomObject, 2); Will the Second element in the list be a deep copy of the first one? Note: myCustomObject can be any Object Edit: Could you also please let me know the potential use of Enumerable.Repeat when dealing with custom objets? Thanks ...

Exclude parent object on binary serialization in C#

I have a question about binary serialization in C# I need to be able to deep clone objects of class B (along with all it's subobjects in the graph of course). I'd like to implement this by using binary serialization. The discussion if that's the best method is irrelevant in the context of this question. Say I have this class structure:...

LinkedHashMap<String,Object>.clone();

does the above command produce a deep copy of a LinkedHashMap's elements? ...

When does it make sense for a Java object to be Serializable but not Cloneable?

If a Java class implements the Serializable interface but does not have a public clone() method, it is usually possible to create a deep copy like this: class CloneHelper { @SuppressWarnings("unchecked") public static <T extends Serializable> T clone(T obj) { try { ByteArrayOutputStream baos = new ByteArrayOu...

Deep Copy a .NET Class Instance Without Serialization

I am using an instance class from a third-party DLL, and I need to do a deep copy on a particular instance. The class is not marked as Serializable, and therefore I can not use this suggested method using BinaryFormatter. How can I get a deep copy of this object without using serialization? ...

Rails, Attachment_fu - deep copy of database storage attachments

I have a model, let's say Attachments, that uses attachment_fu to accept file uploads from the user. I want to "deep copy" (or in Ruby-ese, deep clone) an Attachment, thus creating a completely new binary object in the "db_files" table. I've found that it is not quite a solved problem yet. This blog posting: http://www.williambharding.c...

Deep copy entity with NHibernate

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 ...

Python: Inheritance of a class attribute (list)

Hi everyone, inheriting a class attribute from a super class and later changing the value for the subclass works fine: class Unit(object): value = 10 class Archer(Unit): pass print Unit.value print Archer.value Archer.value = 5 print Unit.value print Archer.value leads to the output: 10 10 10 5 which is just fine: Archer ...

Methods for deep cloning objects in C#

I have a class: 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; } ...

Clone List Elements in Java

Hi all, I have a variable of type List<RelationHeader>. Now I want to copy all the elements in this list to a new list, but I want to actually copy all the members by value (clone them). Is there a quick command to do this, or do I need to iterate over the list and copy them one at a time? ...

DRYing out implementation of ICloneable in several classes

I have several different classes that I want to be cloneable: GenericRow, GenericRows, ParticularRow, and ParticularRows. There is the following class hierarchy: GenericRow is the parent of ParticularRow, and GenericRows is the parent of ParticularRows. Each class implements ICloneable because I want to be able to create deep copies ...

Trouble with copying dictionaries and using deepcopy on an SQLAlchemy ORM object

Hi there, I'm doing a Simulated Annealing algorithm to optimise a given allocation of students and projects. This is language-agnostic pseudocode from Wikipedia: s ← s0; e ← E(s) // Initial state, energy. sbest ← s; ebest ← e // Initial "best" solution k ← 0 ...

How can I "override" deepcopy in Python?

Hi there, I'd like to override __deepcopy__ for a given SQLAlchemy-mapped class such that it ignores any SQLA attributes but deepcopies everything else that's part of the class. I'm not particularly familiar with overriding any of Python's built-in objects in particular but I've got some idea as to what I want. Let's just make a very ...

Object to Object Property mapping in collections

Im creating a collection of (dynamically generated type) for display in a silverlight grid and one of the processes involves creating an import (dynamically generated type) type then mapping the properties on the import type to the collection of (dynamically generated type) both types share a Id property that identifies the item ( be it ...

Java object copy best option?

I need to copy an object in Java (i.e. copy the object "by value not by reference" so that the new object is not just a reference to the old). I'm weary of implementing clonable and would prefer to use a copy constructor. However, the class I need to copy has MANY member variables that need to be copied (over 100) so adding a new const...