00001 //StiCompositeLeafIterator.h 00002 //M.L. Miller (Yale Software) 00003 //07/01 00004 00035 #ifndef StiCompositeLeafIterator_HH 00036 #define StiCompositeLeafIterator_HH 00037 00038 #include <vector> 00039 using std::vector; 00040 00041 #include "StiCompositeTreeNode.h" 00042 #include "StlUtilities.h" 00043 00044 template <class T> 00045 class StiCompositeLeafIterator 00046 { 00047 public: 00049 typedef StiCompositeTreeNode<T> tnode_t; 00050 00052 typedef vector<tnode_t*> tnode_vec; 00053 00055 StiCompositeLeafIterator(tnode_t* node); 00056 00058 virtual ~StiCompositeLeafIterator(); 00059 00061 void reset(); 00062 void unset(){;} 00063 00065 tnode_t* operator*() const; 00066 00068 void operator++(); 00069 00071 bool operator!=(const typename tnode_vec::const_iterator& rhs) { 00072 return (mcurrentleaf != rhs); 00073 } 00074 00077 unsigned int getLeafCount() const; 00078 00079 public: 00080 //Safe forward Access to leaves 00081 00083 typename tnode_vec::iterator begin() { return mleaves.begin();} 00084 00085 00087 typename tnode_vec::iterator end() { return mleaves.end(); } 00088 00089 00091 typename tnode_vec::const_iterator const_begin() const {return mleaves.begin();} 00092 00094 typename tnode_vec::const_iterator const_end() const {return mleaves.end();} 00095 00096 protected: 00099 StiCompositeLeafIterator(); 00100 00102 void findLeaves(); 00103 00105 tnode_t* mcurrentnode; 00106 00108 typename tnode_vec::const_iterator mcurrentleaf; 00109 00111 tnode_vec mleaves; 00112 00113 private: 00114 }; 00115 00126 template <class T> 00127 StiCompositeLeafIterator<T>::StiCompositeLeafIterator(tnode_t* node) 00128 : mcurrentnode(node) 00129 { 00130 findLeaves(); 00131 } 00132 00133 template <class T> 00134 StiCompositeLeafIterator<T>::~StiCompositeLeafIterator() 00135 { 00136 } 00137 00146 template <class T> 00147 inline void StiCompositeLeafIterator<T>::reset() 00148 { 00149 mcurrentleaf=mleaves.begin(); 00150 } 00151 00164 template <class T> 00165 inline typename StiCompositeLeafIterator<T>::tnode_t* 00166 StiCompositeLeafIterator<T>::operator*() const 00167 { 00168 return (*mcurrentleaf); 00169 } 00170 00174 template <class T> 00175 inline void StiCompositeLeafIterator<T>::operator ++() 00176 { 00177 ++mcurrentleaf; 00178 } 00179 00185 /* 00186 template <class T> 00187 inline bool StiCompositeLeafIterator<T>::operator != (const tnode_vec::const_iterator& rhs) 00188 { 00189 return (mcurrentleaf != rhs); 00190 } 00191 */ 00192 00196 template <class T> 00197 inline unsigned int StiCompositeLeafIterator<T>::getLeafCount() const 00198 { 00199 return mleaves.size(); 00200 } 00201 00202 00210 /* 00211 template <class T> 00212 inline StiCompositeLeafIterator<T>::tnode_vec::iterator //return type 00213 StiCompositeLeafIterator<T>::begin() 00214 { 00215 return mleaves.begin(); 00216 } 00217 */ 00218 00219 00227 /* 00228 template <class T> 00229 inline StiCompositeLeafIterator<T>::tnode_vec::iterator //return type 00230 StiCompositeLeafIterator<T>::end() 00231 { 00232 return mleaves.end(); 00233 } 00234 */ 00235 00243 /* 00244 template <class T> 00245 inline StiCompositeLeafIterator<T>::tnode_vec::const_iterator //return type 00246 StiCompositeLeafIterator<T>::const_begin() const 00247 { 00248 return mleaves.begin(); 00249 } 00250 */ 00251 00259 /* 00260 template <class T> 00261 inline StiCompositeLeafIterator<T>::tnode_vec::const_iterator //return type 00262 StiCompositeLeafIterator<T>::const_end() const 00263 { 00264 return mleaves.end(); 00265 } 00266 00267 */ 00268 00269 template <class T> 00270 void StiCompositeLeafIterator<T>::findLeaves() 00271 { 00272 LeafFinder<T> myLeafFinder(mleaves); 00273 myLeafFinder(mcurrentnode); 00274 reset(); 00275 } 00276 00277 #endif
1.5.9