indexing
	namespace: "candidate"
	cluster: "collection"
	description: "Bidirectional iterator with preorder traversal of tree structure. Objects of this type are bounded within the starting object and its children."
	original_author: "Justin Finnerty"
	original_date: "August 2005"
	current_date: "$Date: 2005/09/03 01:39:40 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.2 $"
	--  $Log: bounded_tree_cursor.e,v $
	--  Revision 2.2  2005/09/03 01:39:40  finnerty
	--  Updated to conform to cursors/containers in the GOBO library
	--
	--  Revision 2.1  2005/09/03 00:50:39  finnerty
	--  renamed iterator_bound_tree to bounded_tree_cursor
	--
	--  Revision 2.0  2005/08/26 23:19:46  finnerty
	--  == alpha version ==
	--
	--  Revision 1.1  2005/08/06 12:30:58  finnerty
	--  Iterator for traversing trees in preorder. Bound refers to being restricted to sub-tree with root at the given node.
	--
class BOUNDED_TREE_CURSOR[T_NODE->TREE_NODE]
	-- Bidirectional iterator with preorder traversal of tree
	-- structures. Objects of this type are bounded within the starting
	-- object and its children.
inherit
	TREE_CURSOR[T_NODE]
		redefine
			make, forth, back
		end

creation {ANY}
	-- Create an iterator
	make

feature {ANY}
	-- Cursor movement
	forth is
			-- Move iterator forward one.
		do
			-- Step cursor
			if item.has_children then
				-- Move into directory with children
				item := item.first_child
			else
				-- Move up the parent tree and then to sibling
				from
				until
					not item.has_parent or else
					(item.has_sibling and item /= item.parent.last_child) or else
					item = container
				loop
					item := item.parent
				end
				if
					item /= container and then
					item.has_parent and then
					(item.has_sibling and item /= item.parent.last_child)
				 then
					item := item.next_sibling
				else
					item := Void
				end
			end
		end

	back is		
			-- Move iterator backward one.
		local
			l_node: T_NODE
		do
			-- Check to see if at end. 
			if item = container then
				item := Void
			else
				-- Step cursor
				if item.parent.first_child /= item then
					from
						l_node := item.parent.first_child
					until
						l_node.next_sibling = item
					loop
						l_node := l_node.next_sibling
					end
					item := l_node
					-- Move to bottom of directory with children
					from
					until
						not item.has_children
					loop
						item := item.last_child
					end
				else
					-- Move up the parent tree
					item := item.parent
				end
			end
		end

feature {NONE}
	-- creation implementation
	make(a_start_point: T_NODE) is
			-- Make with the given starting point
		do
			item := a_start_point
			container := a_start_point
		end
end -- class BOUNDED_TREE_CURSOR

