private static void sub_internal_native_array_deep_twin( Array target_array, int i, EIFFEL_TYPE_INFO source_attribute, Hashtable traversed_objects ) // Helper feature that given a `target' object and its associated `attribute' // perform a deep copy of `source_attribute' and assign it back to `target'. // Assume arguments are not Void. { EIFFEL_TYPE_INFO target_attribute; if (traversed_objects.Contains(source_attribute)) { // We already processed `obj', we simply assign current // attribute to computed value. target_array.SetValue(traversed_objects [source_attribute], i); } else { // Ojbect was not yet duplicated. target_attribute = GENERIC_CONFORMANCE.create_like_object(source_attribute); traversed_objects.Add(source_attribute, target_attribute); internal_deep_twin(target_attribute, source_attribute, traversed_objects); target_array.SetValue(target_attribute, i); } }
public static object deep_twin(object Current) // New object structure recursively duplicated from Current. { object Result = null; Hashtable traversed_objects; if (Current == null) { generate_call_on_void_target_exception(); } else { // `traversed_objects' is a correspondance between processed // objects reachable from `obj' and newly created one that // are reachable from `Result'. traversed_objects = new Hashtable(100, new RT_REFERENCE_COMPARER()); // Create an empty copy of `Current'. Result = GENERIC_CONFORMANCE.create_like_object(Current); // Add `Current' and associates it with `Result' to // resolve future references to `Current' into `Result'. traversed_objects.Add(Current, Result); // Performs deep traversal. internal_deep_twin(Result, Current, traversed_objects); } #if ASSERTIONS ASSERTIONS.ENSURE("deep_equal", deep_equal(Current, Result, Current)); #endif return(Result); }
/* * feature -- Duplication */ public static object standard_clone(object obj) // { #if ASSERTIONS ASSERTIONS.REQUIRE("Valid type", obj is EIFFEL_TYPE_INFO); #endif return(GENERIC_CONFORMANCE.create_like_object((EIFFEL_TYPE_INFO)obj)); }
/* * feature -- Duplication */ public static object twin(object Current) // New object equal to `Current' // `twin' calls `copy'; to change copying/twining semantics, redefine `copy'. { object Result = null; bool l_check_assert; if (Current == null) { generate_call_on_void_target_exception(); } else { l_check_assert = ISE_RUNTIME.check_assert(false); Result = GENERIC_CONFORMANCE.create_like_object(Current); copy(Result, Current); l_check_assert = ISE_RUNTIME.check_assert(l_check_assert); } return(Result); }
public static object standard_twin(object Current) // New object field-by-field identical to `other'. // Always uses default copying semantics. { object Result = null; bool l_check_assert; EIFFEL_TYPE_INFO l_current = Current as EIFFEL_TYPE_INFO; if (Current == null) { generate_call_on_void_target_exception(); } else { if (l_current != null) { // For Eiffel object we can use our efficient implementation // which is using `MemberwiseClone'. Result = l_current.____standard_twin(); } else { // For .NET object, we have to do it the slow way, allocate // a new object, and then copy field by field. l_check_assert = ISE_RUNTIME.check_assert(false); Result = GENERIC_CONFORMANCE.create_like_object(Current); internal_standard_copy(Result, Current); l_check_assert = ISE_RUNTIME.check_assert(l_check_assert); } } #if ASSERTIONS ASSERTIONS.ENSURE("standard_twin_not_void", Result != null); ASSERTIONS.ENSURE("standard_equal", standard_equal(Current, Result, Current)); #endif return(Result); }