note
	description: "Objects that traverse object graphs starting at the root object in a breadth first manner."
	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: 2013-03-27 07:34:50 +0000 (Wed, 27 Mar 2013) $"
	revision: "$Revision: 92359 $"

class interface
	OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE

create 
	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)

feature -- Access

	generating_type: TYPE [detachable OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generating_type_not_void: Result /= Void

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty

	object_action: detachable PROCEDURE [separate ANY]
			-- Action called on every object in object graph
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	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.
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	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.
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	root_object: detachable ANY
			-- Starting point of graph traversing
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	visited_objects: detachable ARRAYED_LIST [separate ANY]
			-- List referencing objects of object graph that have been visited in traverse.
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	visited_types: detachable HASH_TABLE [INTEGER_32, INTEGER_32]
			-- List of all types encountered during traversal
			-- (from OBJECT_GRAPH_TRAVERSABLE)
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))

	frozen is_deep_equal alias "≡≡≡" (other: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)

	is_equal (other: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))

	frozen standard_is_equal alias "" (other: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void

	has_failed: BOOLEAN
			-- Was the last traversal successful?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	has_reference_with_copy_semantics: BOOLEAN
			-- Does the traversed graph of objects contain reference with copy semantics?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	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.
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	is_exception_propagated: BOOLEAN
			-- Does the algorithm propagate any exceptions to the user?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	is_object_action_set: BOOLEAN
			-- Is procedure to call on every object set?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	is_root_object_set: BOOLEAN
			-- Is starting point of graph traversing set?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	is_skip_copy_semantics_reference: BOOLEAN
			-- Do we skip copy semantics reference from visited_objects during traversal?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	is_skip_transient: BOOLEAN
			-- Do we skip transient attribute during traversal?
			-- (from OBJECT_GRAPH_TRAVERSABLE)

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
	
feature -- Element change

	set_is_exception_on_copy_suppressed (v: like is_exception_on_copy_suppressed)
			-- Set set_is_exception_on_copy_suppressed with v.
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			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.
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			is_exception_propagated_set: is_exception_propagated = v

	set_is_skip_copy_semantics_reference (v: like is_skip_copy_semantics_reference)
			-- Set is_skip_copy_semantics_reference with v.
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			is_skip_copy_semantics_reference_set: is_skip_copy_semantics_reference = v

	set_is_skip_transient (v: like is_skip_transient)
			-- Set is_skip_transient with v.
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			is_skip_transient_set: is_skip_transient = v

	set_on_processing_object_action (an_action: like on_processing_object_action)
			-- Set on_processing_object_action with an_action
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		require -- from OBJECT_GRAPH_TRAVERSABLE
			an_action_not_void: an_action /= Void
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			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
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		require -- from OBJECT_GRAPH_TRAVERSABLE
			an_action_not_void: an_action /= Void
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			on_processing_reference_action_set: on_processing_reference_action = an_action

	set_root_object (an_object: like root_object)
			-- Set root_object with 'an_object'.
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		require -- from OBJECT_GRAPH_TRAVERSABLE
			an_object_not_void: an_object /= Void
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			root_object_set: root_object = an_object and is_root_object_set
	
feature -- Duplication

	copy (other: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE)
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		ensure -- from ANY
			is_equal: Current ~ other

	frozen deep_copy (other: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE)
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)

	frozen deep_twin: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)

	frozen standard_copy (other: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE)
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)

	frozen standard_twin: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)

	frozen twin: OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
	
feature -- Basic operations

	frozen default: detachable OBJECT_GRAPH_BREADTH_FIRST_TRAVERSABLE
			-- Default value of object's type
			-- (from ANY)

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		ensure -- from ANY
			instance_free: class

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		ensure -- from ANY
			instance_free: class

	frozen traverse
			-- Traverse object structure starting at 'root_object' and call object_action
			-- on every object in the graph.
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		require -- from OBJECT_GRAPH_TRAVERSABLE
			root_object_available: is_root_object_set

	wipe_out
			-- Clear current to default values
			-- (from OBJECT_GRAPH_TRAVERSABLE)
		ensure -- from OBJECT_GRAPH_TRAVERSABLE
			visited_objects_reset: visited_objects = Void
			object_action_not_set: not is_object_action_set
			root_object_not_set: not is_root_object_set
	
feature -- Output

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		ensure -- from ANY
			out_not_void: Result /= Void

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		ensure -- from ANY
			instance_free: class

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
	
invariant
		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

note
	copyright: "Copyright (c) 1984-2013, 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_BREADTH_FIRST_TRAVERSABLE

Generated by ISE EiffelStudio