示例#1
0
        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);
        }
示例#2
0
        public static object clone(object Current, object other)
        // Void if `other' is void; otherwise new object
        // equal to `other'
        //
        // For non-void `other', `clone' calls `copy';
        // to change copying/cloning semantics, redefine `copy'.
        {
            object Result = null;

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                if (other != null)
                {
                    Result = twin(other);
                }
            }
                #if ASSERTIONS
            ASSERTIONS.ENSURE("equal", equal(Current, Result, other));
                #endif

            return(Result);
        }
示例#3
0
        public static void copy(object Current, object other)
        // Update current object using fields of object attached
        // to `other', so as to yield equal objects.
        {
            EIFFEL_TYPE_INFO l_current = Current as EIFFEL_TYPE_INFO;

                #if ASSERTIONS
            ASSERTIONS.REQUIRE("other_not_void", other != null);
            ASSERTIONS.REQUIRE("same_type", same_type(Current, other));
                #endif

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                if (l_current != null)
                {
                    l_current.____copy(other);
                }
                else
                {
                    internal_standard_copy(Current, other);
                }
            }
                #if ASSERTIONS
            ASSERTIONS.ENSURE("is_equal", is_equal(Current, other));
                #endif
        }
示例#4
0
 public EIFFEL_EXCEPTION(int a_code, string a_tag) : base(exception_message(a_code, a_tag))
     // New instance with `code' set to `a_code' and `tag' with `a_tag'.
 {
     code = a_code;
     tag  = a_tag;
         #if ASSERTIONS
     ASSERTIONS.ENSURE("code_set", code == a_code);
     ASSERTIONS.ENSURE("tag_set", tag == a_tag);
         #endif
 }
示例#5
0
 public EIFFEL_EXCEPTION(int a_code, string a_tag, Exception an_inner_exception) : base(exception_message(a_code, a_tag), an_inner_exception)
     // New instance with `code' set to `a_code' and `tag' with `a_tag'
     // and `InnerException' set to `an_inner_exception'.
 {
     code = a_code;
     tag  = a_tag;
         #if ASSERTIONS
     ASSERTIONS.ENSURE("code_set", code == a_code);
     ASSERTIONS.ENSURE("tag_set", tag == a_tag);
     ASSERTIONS.ENSURE("InnerException_set", InnerException == an_inner_exception);
         #endif
 }
示例#6
0
        public static bool same_type(object Current, object other)
        // Is type of current object identical to type of `other'?
        {
            bool             Result = false;
            RT_GENERIC_TYPE  l_current_type, l_other_type;
            EIFFEL_TYPE_INFO l_current;

                #if ASSERTIONS
            ASSERTIONS.REQUIRE("other_not_void", other != null);
                #endif
            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                Result = Current.GetType().Equals(other.GetType());
                if (Result)
                {
                    l_current = Current as EIFFEL_TYPE_INFO;
                    if (l_current != null)
                    {
                        // We perform generic conformance in case it is needed.
                        l_current_type = l_current.____type();
                        if (l_current_type != null)
                        {
                            // Because we already know that `Current' and `other' have
                            // the same type, therefore cast to EIFFEL_TYPE_INFO is
                            // going to succeed.
                            l_other_type = ((EIFFEL_TYPE_INFO)other).____type();
                                                #if ASSERTIONS
                            ASSERTIONS.CHECK("has_derivation", l_other_type != null);
                            ASSERTIONS.CHECK("Same base type", l_current_type.type.Equals(l_other_type.type));
                                                #endif
                            Result = l_current_type.Equals(l_other_type);
                        }
                    }
                    else
                    {
                        // It is not generic, then they definitely have the same type.
                        // No need to assign Result again, as it is already holding the true value.
                    }
                }
            }
#if ASSERTIONS
            ASSERTIONS.ENSURE("definition", Result == (conforms_to(Current, other) &&
                                                       conforms_to(other, Current)));
#endif
            return(Result);
        }
示例#7
0
        public static void deep_copy(object Current, object other)
        // Effect equivalent to that of:
        //		`copy' (`other' . `deep_twin')
        {
                #if ASSERTIONS
            ASSERTIONS.REQUIRE("other_not_void", other != null);
                #endif

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                copy(Current, deep_twin(other));
            }

                #if ASSERTIONS
            ASSERTIONS.ENSURE("deep_equal", deep_equal(Current, Current, other));
                #endif
        }
示例#8
0
        public static object deep_clone(object Current, object other)
        // Void if `other' is void: otherwise, new object structure
        // recursively duplicated from the one attached to `other'
        {
            object Result = null;

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else if (other != null)
            {
                Result = deep_twin(other);
            }

                #if ASSERTIONS
            ASSERTIONS.ENSURE("deep_equal", deep_equal(Current, other, Result));
                #endif

            return(Result);
        }
示例#9
0
        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);
        }
示例#10
0
        public static object standard_clone(object Current, object other)
        // Void if `other' is void; otherwise new object
        // field-by-field identical to `other'.
        // Always uses default copying semantics.
        {
            object Result = null;

            if (Current == null)
            {
                generate_call_on_void_target_exception();
            }
            else
            {
                if (other != null)
                {
                    Result = standard_twin(other);
                }
            }
                #if ASSERTIONS
            ASSERTIONS.ENSURE("standard_equal", standard_equal(Current, Result, other));
                #endif

            return(Result);
        }