StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiCompositeLeafIterator.h
1 //StiCompositeLeafIterator.h
2 //M.L. Miller (Yale Software)
3 //07/01
4 
35 #ifndef StiCompositeLeafIterator_HH
36 #define StiCompositeLeafIterator_HH
37 
38 #include <vector>
39 using std::vector;
40 
41 #include "StiCompositeTreeNode.h"
42 #include "StlUtilities.h"
43 
44 template <class T>
46 {
47 public:
50 
52  typedef vector<tnode_t*> tnode_vec;
53 
56 
58  virtual ~StiCompositeLeafIterator();
59 
61  void reset();
62  void unset(){;}
63 
65  tnode_t* operator*() const;
66 
68  void operator++();
69 
71  bool operator!=(const typename tnode_vec::const_iterator& rhs) {
72  return (mcurrentleaf != rhs);
73  }
74 
77  unsigned int getLeafCount() const;
78 
79 public:
80  //Safe forward Access to leaves
81 
83  typename tnode_vec::iterator begin() { return mleaves.begin();}
84 
85 
87  typename tnode_vec::iterator end() { return mleaves.end(); }
88 
89 
91  typename tnode_vec::const_iterator const_begin() const {return mleaves.begin();}
92 
94  typename tnode_vec::const_iterator const_end() const {return mleaves.end();}
95 
96 protected:
100 
102  void findLeaves();
103 
106 
108  typename tnode_vec::const_iterator mcurrentleaf;
109 
112 
113 private:
114 };
115 
126 template <class T>
128  : mcurrentnode(node)
129 {
130  findLeaves();
131 }
132 
133 template <class T>
135 {
136 }
137 
146 template <class T>
148 {
149  mcurrentleaf=mleaves.begin();
150 }
151 
164 template <class T>
167 {
168  return (*mcurrentleaf);
169 }
170 
174 template <class T>
176 {
177  ++mcurrentleaf;
178 }
179 
185 /*
186  template <class T>
187  inline bool StiCompositeLeafIterator<T>::operator != (const tnode_vec::const_iterator& rhs)
188  {
189  return (mcurrentleaf != rhs);
190  }
191 */
192 
196 template <class T>
197 inline unsigned int StiCompositeLeafIterator<T>::getLeafCount() const
198 {
199  return mleaves.size();
200 }
201 
202 
210 /*
211  template <class T>
212  inline StiCompositeLeafIterator<T>::tnode_vec::iterator //return type
213  StiCompositeLeafIterator<T>::begin()
214  {
215  return mleaves.begin();
216  }
217 */
218 
219 
227 /*
228  template <class T>
229  inline StiCompositeLeafIterator<T>::tnode_vec::iterator //return type
230  StiCompositeLeafIterator<T>::end()
231  {
232  return mleaves.end();
233  }
234 */
235 
243 /*
244  template <class T>
245  inline StiCompositeLeafIterator<T>::tnode_vec::const_iterator //return type
246  StiCompositeLeafIterator<T>::const_begin() const
247  {
248  return mleaves.begin();
249  }
250 */
251 
259 /*
260  template <class T>
261  inline StiCompositeLeafIterator<T>::tnode_vec::const_iterator //return type
262  StiCompositeLeafIterator<T>::const_end() const
263  {
264  return mleaves.end();
265  }
266 
267 */
268 
269 template <class T>
271 {
272  LeafFinder<T> myLeafFinder(mleaves);
273  myLeafFinder(mcurrentnode);
274  reset();
275 }
276 
277 #endif
void findLeaves()
Internal function used to find leaves. It is called in the constructor.
void operator++()
Define only prefix of ++ (only a forward iterator)
void reset()
Reset iterator to point to first leaf.
bool operator!=(const typename tnode_vec::const_iterator &rhs)
Define !=.
tnode_t * mcurrentnode
We store a pointer to the root of the tree for internal convenience.
unsigned int getLeafCount() const
vector< tnode_t * > tnode_vec
For internal convenience.
tnode_vec::iterator begin()
Return an iterator marking the beginning of the leaf vector.
tnode_vec::const_iterator const_end() const
Return a const_iterator marking the end of the leaf vector.
tnode_vec::iterator end()
Return an iterator marking the end of the leaf vector.
StiCompositeTreeNode< T > tnode_t
For internal convenience.
tnode_t * operator*() const
Dereference iterator, just as an STL iterator.
virtual ~StiCompositeLeafIterator()
Defualt destructor.
tnode_vec mleaves
The vector of leaves.
tnode_vec::const_iterator mcurrentleaf
We have to store an interator into the leaf vector for traversal.
tnode_vec::const_iterator const_begin() const
Return a const_iterator marking the beginning of the leaf vector.