note description: "[ Utility class to traverse object graphs starting at a root object. When traversing a graph the class distinguishes four different types of references: (1) Normal references (2) References with copy-semantics, which are usually seen when attaching an expanded object to an ANY reference (3) User-defined expanded objects, embedded inside another object. Semantically this is a special case of a copy-semantics reference. (4) Language-defined expanded objects (INTEGER, POINTER etc) embedded inside another object. Semantically, this is a special case of a copy-semantics reference. This class will follow all reference types except (4). During traversal the agent on_processing_object_action will be called for each object and the agent on_processing_reference_action for each reference, if present. This includes references to objects that have already been processed. The algorighm has two output values: visited_objects and visited_types: Any standard object without copy-semantics (i.e. reference type (1)) will be stored by aliasing inside visited_object. For references of type (2) and (3) a copy will be stored. The visited_types hash table contains the dynamic type id of all types encountered during traversal. The key and value in the hashtable are the same. Setting is_skip_copy_semantics_reference to true means that references of (2) and (3) will not be stored in visited_types. Note that this is the only effect of this setting - i.e. the traversal algorithm will still follow the references, the agents will be called, and the visited_types array will be extended anyway. NOTE: Due to a limitation in the reflection library, references of type (2) and (3) within TUPLE and references of type (3) within SPECIAL cannot be handled without causing a copy. This is problematic for agents, especially when they want to change the object. Therefore the algorithm will raise an exception when an agent is attached. In read-only situations it may be acceptable to use a copy of an object. Therefore to disable the exception behaviour you can set is_exception_on_copy_suppressed to True. NOTE: To maintain backwards compatibility the traversal algorithm will silently ignore any kind of exception and just return normally, with traversed_objects set to whatever value it had before invoking traverse. In order to get exceptions you need to set is_exception_propagated to True. ]" library: "Free implementation of ELKS library" legal: "See notice at end of class." status: "See notice at end of class." author: "Stephanie Balzer" date: "$Date: 2017-03-23 19:18:26 +0000 (Thu, 23 Mar 2017) $" revision: "$Revision: 100033 $" deferred class interface OBJECT_GRAPH_TRAVERSABLE feature -- Access root_object: detachable ANY -- Starting point of graph traversing on_processing_object_action: detachable PROCEDURE [REFLECTED_OBJECT] -- Action called on every object in the object graph. -- Note: The argument is reused later for a different object. Do not alias it. on_processing_reference_action: detachable PROCEDURE [REFLECTED_OBJECT, REFLECTED_OBJECT] -- Action called on every reference in the object graph. -- Note: The arguments are reused later for different objects. Do not alias them. object_action: detachable PROCEDURE [separate ANY] -- Action called on every object in object graph visited_objects: detachable ARRAYED_LIST [separate ANY] -- List referencing objects of object graph that have been visited in traverse. visited_types: detachable HASH_TABLE [INTEGER_32, INTEGER_32] -- List of all types encountered during traversal feature -- Status report has_failed: BOOLEAN -- Was the last traversal successful? is_root_object_set: BOOLEAN -- Is starting point of graph traversing set? is_object_action_set: BOOLEAN -- Is procedure to call on every object set? has_reference_with_copy_semantics: BOOLEAN -- Does the traversed graph of objects contain reference with copy semantics? is_skip_transient: BOOLEAN -- Do we skip transient attribute during traversal? is_skip_copy_semantics_reference: BOOLEAN -- Do we skip copy semantics reference from visited_objects during traversal? is_exception_on_copy_suppressed: BOOLEAN -- Do we suppress an exception when object_action is called on a copied object? -- A copy happens when encountering tuples containing copy-semantics references -- or with SPECIAL[XX], where XX is a user-defined expanded type. is_exception_propagated: BOOLEAN -- Does the algorithm propagate any exceptions to the user? feature -- Element change set_root_object (an_object: like root_object) -- Set root_object with 'an_object'. require an_object_not_void: an_object /= Void ensure root_object_set: root_object = an_object and is_root_object_set set_on_processing_object_action (an_action: like on_processing_object_action) -- Set on_processing_object_action with an_action require an_action_not_void: an_action /= Void ensure on_processing_object_action_set: on_processing_object_action = an_action set_on_processing_reference_action (an_action: like on_processing_reference_action) -- Set on_processing_object_action with an_action require an_action_not_void: an_action /= Void ensure on_processing_reference_action_set: on_processing_reference_action = an_action set_is_skip_transient (v: like is_skip_transient) -- Set is_skip_transient with v. ensure is_skip_transient_set: is_skip_transient = v set_is_skip_copy_semantics_reference (v: like is_skip_copy_semantics_reference) -- Set is_skip_copy_semantics_reference with v. ensure is_skip_copy_semantics_reference_set: is_skip_copy_semantics_reference = v set_is_exception_on_copy_suppressed (v: like is_exception_on_copy_suppressed) -- Set set_is_exception_on_copy_suppressed with v. ensure is_exception_on_copy_suppressed_set: is_exception_on_copy_suppressed = v set_is_exception_propagated (v: like is_exception_propagated) -- Set is_exception_propagated with v. ensure is_exception_propagated_set: is_exception_propagated = v feature -- Basic operations frozen traverse -- Traverse object structure starting at 'root_object' and call object_action -- on every object in the graph. require root_object_available: is_root_object_set wipe_out -- Clear current to default values ensure visited_objects_reset: visited_objects = Void object_action_not_set: not is_object_action_set root_object_not_set: not is_root_object_set note copyright: "Copyright (c) 1984-2017, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software 5949 Hollister Ave., Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Website http://www.eiffel.com Customer support http://support.eiffel.com ]" end -- class OBJECT_GRAPH_TRAVERSABLE
Generated by ISE EiffelStudio