1 /*
2 	Copyright (C) 2005-2007 Feeling Software Inc.
3 	Portions of the code are:
4 	Copyright (C) 2005-2007 Sony Computer Entertainment America
5 
6 	MIT License: http://www.opensource.org/licenses/mit-license.php
7 */
8 /**
9 	@file FCDSceneNodeIterator.h
10 	This file contains the FCDSceneNodeIteratorT template
11 	and its two definitions: FCDSceneNodeIterator and FCDSceneNodeConstIterator.
12 */
13 
14 #ifndef _FCD_SCENE_NODE_ITERATOR_H_
15 #define _FCD_SCENE_NODE_ITERATOR_H_
16 
17 class FCDSceneNode;
18 
19 /**
20 	This template is used to process a given scene node and its full sub-tree.
21 	We use a template here in order to easily support both const
22 	and non-const scene node data, with the same code.
23 
24 	Do not use this template directly, instead use the
25 	FCDSceneNodeIterator and FCDSceneNodeConstIterator definitions.
26 
27 	This template does not care whether multiple instances of the same node is processed.
28 */
29 template <class _NODE>
30 class FCOLLADA_EXPORT FCDSceneNodeIteratorT
31 {
32 private:
33 	fm::pvector<_NODE> queue;
34 	size_t iterator;
35 
36 public:
37 	/** The order in which the scene nodes should be iterated. */
38 	enum SearchType
39 	{
40 		/** Iterate over the scene nodes one level at a time. Starts from the root
41 			and terminates with the leaves. Each node level is processed fully
42 			before processing the next one. */
43 		BREADTH_FIRST,
44 
45 		/** Standard tree traversal. Processes the root, the first child of the root,
46 			then the child's first child... until a leaf is reached. Then, the leaf's siblings
47 			are iterated over before iterating over the leaf's parent's siblings. */
48 		DEPTH_FIRST_PREORDER,
49 
50 		/** Iterate over the scene nodes one level at a time. Starts at the leaves
51 			and terminates with the root. Each node level is processed fully
52 			before processing the next one. */
53 		DEPTH_FIRST_POSTORDER,
54 	};
55 
56 	/** Constructor.
57 		@param root The scene root of the sub-tree to iterate over.
58 		@param searchType The search type determines the ordering of the scene nodes returned by Next.
59 		@param pureChildOnly Only process nodes that are direct children of the root. All node
60 			instances will be discarded. */
61 	FCDSceneNodeIteratorT(_NODE* root, SearchType searchType=BREADTH_FIRST, bool pureChildOnly=false);
62 
63 	/** Destructor. */
64 	~FCDSceneNodeIteratorT();
65 
66 	/** Retrieves the current node to process.
67 		@return The current node. */
68 	_NODE* GetNode();
69 
70 	/** Advances the iteration pointer and retrieves the next node to process.
71 		@return The node to process. */
72 	_NODE* Next();
73 
74 	/** Retrieves whether the full sub-tree has been processed. */
IsDone()75 	inline bool IsDone() { return iterator >= queue.size(); }
76 
77 	/** Advances the iteration pointer.
78 		@return The iterator. */
79 	inline FCDSceneNodeIteratorT& operator++() { Next(); return (*this); }
80 
81 	/** Retrieves the current node to process.
82 		@return The current node. */
83 	inline _NODE* operator*() { return GetNode(); }
84 };
85 
86 typedef FCDSceneNodeIteratorT<FCDSceneNode> FCDSceneNodeIterator; /**< A scene node iterator. */
87 typedef FCDSceneNodeIteratorT<const FCDSceneNode> FCDSceneNodeConstIterator; /**< A constant scene node iterator. */
88 
89 #ifdef __APPLE__
90 #include "FCDocument/FCDSceneNodeIterator.hpp"
91 #endif // __APPLE__
92 
93 #endif // _FCD_SCENE_NODE_ITERATOR_H_
94