FreeLing  4.0
tree.h
Go to the documentation of this file.
00001 
00002 //
00003 //    STL-like n-ary tree template 
00004 //
00005 //    Copyright (C) 2006   TALP Research Center
00006 //                         Universitat Politecnica de Catalunya
00007 //
00008 //    This program is free software; you can redistribute it 
00009 //    and/or modify it under the terms of the GNU General Public
00010 //    License as published by the Free Software Foundation; either
00011 //    version 3 of the License, or (at your option) any later version.
00012 //
00013 //    This library is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //    General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU General Public
00019 //    License along with this library; if not, write to the Free Software
00020 //    Foundation, Inc., 51 Franklin St, 5th Floor, Boston, MA 02110-1301 USA
00021 //
00022 //    contact: Lluis Padro (padro@lsi.upc.es)
00023 //             TALP Research Center
00024 //             despatx Omega.S112 - Campus Nord UPC
00025 //             08034 Barcelona.  SPAIN
00026 //
00028 
00029 #ifndef _TREE_TEMPLATE
00030 #define _TREE_TEMPLATE
00031 
00032 #include "freeling/windll.h"
00033 
00034 namespace freeling {
00035 
00036   // predeclaration
00037   template<class T, class N> class basic_tree_iterator;
00038   template<class T> class basic_const_tree_iterator;
00039   template<class T> class basic_nonconst_tree_iterator;
00040   template<class T, class X> class basic_preorder_iterator;
00041   template<class T, class X> class basic_sibling_iterator;
00042   template<class T> class tree_preorder_iterator;
00043   template<class T> class const_tree_preorder_iterator;
00044   template<class T> class tree_sibling_iterator;
00045   template<class T> class const_tree_sibling_iterator;
00046    
00050 
00051   template <class T> class tree  {
00053 
00054     friend class basic_nonconst_tree_iterator<T>;
00055     friend class basic_tree_iterator<T, tree<T> >;
00056     friend class basic_tree_iterator<T, const tree<T> >;
00057     friend class basic_sibling_iterator<T,basic_nonconst_tree_iterator<T> >;
00058     friend class basic_sibling_iterator<T,basic_const_tree_iterator<T> >;
00059     friend class basic_preorder_iterator<T,basic_nonconst_tree_iterator<T> >;
00060     friend class basic_preorder_iterator<T,basic_const_tree_iterator<T> >;
00061 
00062     private:
00064       void clone(const tree<T>&);
00065     
00066     protected:
00068       T *pinfo;
00070       tree<T>* parent;        
00072       tree<T>* first, *last;
00074       tree<T>* prev, *next;   
00076       unsigned int nchildren;
00077    
00078     public:
00080       typedef tree_preorder_iterator<T> preorder_iterator;
00081       typedef const_tree_preorder_iterator<T> const_preorder_iterator;
00082       typedef tree_sibling_iterator<T> sibling_iterator;
00083       typedef const_tree_sibling_iterator<T> const_sibling_iterator;
00084 
00086       typedef preorder_iterator iterator;
00087       typedef const_preorder_iterator const_iterator;
00088       
00090       tree();
00091       tree(const T&);
00092       tree(const const_iterator&);
00094       tree(const tree<T>&);
00096       tree<T>& operator=(const tree<T>&);
00098       ~tree();
00099       
00101       void clear();
00104       bool is_root() const;
00106       bool empty() const;
00108       unsigned int num_children() const;
00110       bool has_ancestor(const tree<T> &) const;
00111 
00112       sibling_iterator nth_child(unsigned int);
00113       const_sibling_iterator nth_child(unsigned int) const;
00114       tree<T> & nth_child_ref(unsigned int);
00115       const tree<T> & nth_child_ref(unsigned int) const;
00116 
00117       static const_iterator get_leftmost_leaf(const_iterator);
00118       static const_iterator get_rightmost_leaf(const_iterator);
00119 
00121       void add_child(const tree<T>& t, bool last=true);
00123       void hang_child(tree<T>& t, tree_sibling_iterator<T> where=tree_sibling_iterator<T>(NULL));
00124       void hang_child(preorder_iterator &p, tree_sibling_iterator<T> where=tree_sibling_iterator<T>(NULL));
00125       void hang_child(sibling_iterator &p, tree_sibling_iterator<T> where=tree_sibling_iterator<T>(NULL));
00126 
00128       preorder_iterator get_parent();
00129       const_preorder_iterator get_parent() const;
00130       
00131       preorder_iterator begin();
00132       preorder_iterator end();
00133       const_preorder_iterator begin() const;
00134       const_preorder_iterator end() const;
00135       
00136       sibling_iterator sibling_begin();
00137       sibling_iterator sibling_end();
00138       const_sibling_iterator sibling_begin() const;
00139       const_sibling_iterator sibling_end() const;
00140       sibling_iterator sibling_rbegin();
00141       sibling_iterator sibling_rend();
00142       const_sibling_iterator sibling_rbegin() const;
00143       const_sibling_iterator sibling_rend() const;
00144   };
00145  
00148 
00149   template<class T> tree<T>::tree() {
00150     pinfo = NULL;
00151     parent = first = last = prev = next = NULL;
00152     nchildren = 0;
00153   }
00154 
00157 
00158   template<class T> tree<T>::tree(const T &x) {
00159     pinfo = new T(x); 
00160     parent = first = last = prev = next = NULL;
00161     nchildren = 0;
00162   }
00163  
00166 
00167   template<class T> tree<T>::tree(const const_iterator &p) {
00168     clone(*(p.tr));
00169   }
00170 
00171 
00174 
00175   template<class T> tree<T>::tree(const tree<T>& t) {
00176     clone(t);
00177   }
00178 
00181 
00182   template<class T> tree<T>& tree<T>::operator=(const tree<T>& t) {
00183     if (this!=&t) {
00184       clear();
00185       clone(t);
00186     }
00187     return (*this);
00188   }
00189   
00192 
00193   template<class T> tree<T>::~tree() {
00194     clear();
00195   }
00196 
00199 
00200   template<class T> void tree<T>::clear() {
00201     tree<T> *p = first;
00202     while (p!=NULL) {
00203       tree<T> *q = p->next;
00204       delete p;
00205       p=q;
00206     }
00207     delete pinfo;
00208   }
00209 
00212 
00213   template<class T> void tree<T>::clone(const tree<T>& t) {
00214     pinfo = (not t.empty() ? new T(*t.pinfo) : NULL);
00215     parent = first = last = prev = next = NULL;
00216     nchildren = 0;
00217     for (tree<T>* p = t.first; p!=NULL; p=p->next) 
00218       this->add_child(*p);
00219   }
00220 
00223 
00224   template<class T> bool tree<T>::is_root() const {
00225     return (parent==NULL);
00226   }
00227     
00230 
00231   template<class T> bool tree<T>::empty() const {
00232     return (pinfo==NULL);
00233   }
00234 
00235 
00238 
00239   template<class T> unsigned int tree<T>::num_children() const {
00240     return nchildren;
00241   }
00242 
00243 
00246 
00247   template<class T> bool tree<T>::has_ancestor(const tree<T> &p) const {
00248     const tree<T> *t = this;
00249     while (not t->is_root() and t!=&p) t=t->parent;
00250     return t==&p;
00251   }
00252 
00255   
00256   template<class T> typename tree<T>::sibling_iterator tree<T>::nth_child(unsigned int n) {
00257     sibling_iterator i = this->sibling_begin();    
00258     while (n>0 && i!=this->sibling_end()) {
00259       i++;
00260       n--;
00261     }
00262     return i;
00263   }
00264 
00265 
00268   
00269   template<class T> typename tree<T>::const_sibling_iterator tree<T>::nth_child(unsigned int n) const {
00270     const_sibling_iterator i = this->sibling_begin();    
00271     while (n>0 && i!=this->sibling_end()) {
00272       i++;
00273       n--;
00274     }
00275     return i;
00276   }
00277 
00280   
00281   template<class T> tree<T>& tree<T>::nth_child_ref(unsigned int n) {
00282     sibling_iterator i = this->sibling_begin();    
00283     while (n>0 && i!=this->sibling_end()) {
00284       i++;
00285       n--;
00286     }
00287 
00288     tree<T> *t;
00289     if (i!=this->sibling_end()) 
00290       return *(i.tr);
00291     else {
00292       // no such child, return undefined tree.
00293       t = new tree<T>();
00294       return *t;
00295     }
00296   }
00297 
00298 
00301   
00302   template<class T> const tree<T>& tree<T>::nth_child_ref(unsigned int n) const {
00303     const_sibling_iterator i = this->sibling_begin();
00304     while (n>0 && i!=this->sibling_end()) {
00305       i++;
00306       n--;
00307     }
00308 
00309     tree<T> *t;
00310     if (i!=this->sibling_end()) 
00311       return *(i.tr);
00312     else {
00313       // no such child, return undefined tree.
00314       t = new tree<T>();
00315       return *t;
00316     }
00317   }
00318 
00321 
00322   template<class T> typename tree<T>::const_iterator tree<T>::get_leftmost_leaf(typename tree<T>::const_iterator t) {
00323     if (t.num_children()==0) 
00324       return t;
00325     else 
00326       return get_leftmost_leaf(t.sibling_begin());
00327   }
00328 
00331 
00332   template<class T> typename tree<T>::const_iterator tree<T>::get_rightmost_leaf(typename tree<T>::const_iterator t) {
00333     if (t.num_children()==0) 
00334       return t;
00335     else 
00336       return get_rightmost_leaf(t.sibling_rbegin());
00337   }
00338 
00339 
00342 
00343   template<class T> typename tree<T>::preorder_iterator tree<T>::get_parent() {
00344     return tree<T>::preorder_iterator(parent);
00345   }
00346 
00349 
00350   template<class T> typename tree<T>::const_preorder_iterator tree<T>::get_parent() const {
00351     return tree<T>::const_preorder_iterator(parent);
00352   }
00353  
00354 
00357 
00358   template<class T> void tree<T>::hang_child(tree<T>& t, typename tree<T>::sibling_iterator where) {
00359 
00360     // remove child from its current location, preserving structure
00361     // 1- remove it from siblings chain
00362     if (t.prev!=NULL) t.prev->next = t.next;
00363     if (t.next!=NULL) t.next->prev = t.prev;  
00364     // 2- adujst parent pointers if first or last child
00365     if (t.parent!=NULL) {
00366       if (t.prev==NULL) t.parent->first=t.next;
00367       if (t.next==NULL) t.parent->last=t.prev;
00368       t.parent->nchildren--;
00369     }
00370 
00371     // hang child on new location under 'this'.
00372     t.parent = this;
00373     
00374     // locate 'where' position and insert node 
00375     t.prev = NULL; 
00376     t.next = this->first;
00377     while (t.next != where.tr) {
00378       t.prev = t.next;
00379       t.next = t.next->next;
00380     }
00381 
00382     // fix pointers in surrounding nodes
00383     if (t.next!=NULL) t.next->prev = &t;
00384     else this->last = &t;
00385     if (t.prev!=NULL) t.prev->next = &t;
00386     else this->first = &t;
00387 
00388     // update count
00389     this->nchildren++;
00390   }
00391 
00394 
00395   template<class T> void tree<T>::hang_child(typename tree<T>::preorder_iterator &p, typename tree<T>::sibling_iterator where) {
00396     this->hang_child(*(p.tr),where);
00397   }
00398 
00401 
00402   template<class T> void tree<T>::hang_child(typename tree<T>::sibling_iterator &p, typename tree<T>::sibling_iterator where) {
00403     this->hang_child(*(p.tr),where);
00404   }
00405 
00406 
00409 
00410   template<class T> void tree<T>::add_child(const tree<T>& t, bool last) {
00411     tree<T> *nt = new tree<T>(t);  // make a copy of given tree
00412     // hang the copy under 'this'
00413     if (last) this->hang_child(*nt,this->sibling_end());  
00414     else this->hang_child(*nt,this->sibling_begin()); 
00415   }
00416 
00419 
00420   template<class T> typename tree<T>::preorder_iterator tree<T>::begin() {
00421     return tree<T>::preorder_iterator(this);
00422   }
00423 
00426 
00427   template<class T> typename tree<T>::preorder_iterator tree<T>::end() {
00428     return tree<T>::preorder_iterator((tree<T>*)NULL);
00429   }
00430 
00433 
00434   template<class T> typename tree<T>::const_preorder_iterator tree<T>::begin() const {
00435     return tree<T>::const_preorder_iterator(this);
00436   }
00437 
00440 
00441   template<class T> typename tree<T>::const_preorder_iterator tree<T>::end() const {
00442     return tree<T>::const_preorder_iterator((tree<T>*)NULL);
00443   }
00444 
00447 
00448   template<class T> typename tree<T>::sibling_iterator tree<T>::sibling_begin() {
00449     return tree<T>::sibling_iterator(this->first);
00450   }
00451 
00454 
00455   template<class T> typename tree<T>::sibling_iterator tree<T>::sibling_end() {
00456     return tree<T>::sibling_iterator((tree<T>*)NULL);
00457   }
00458 
00461 
00462   template<class T> typename tree<T>::const_sibling_iterator tree<T>::sibling_begin() const {
00463     return tree<T>::const_sibling_iterator(this->first);
00464   }
00465 
00468 
00469   template<class T> typename tree<T>::const_sibling_iterator tree<T>::sibling_end() const {
00470     return tree<T>::const_sibling_iterator((tree<T>*)NULL);
00471   }
00472 
00475 
00476   template<class T> typename tree<T>::sibling_iterator tree<T>::sibling_rbegin() {
00477     return tree<T>::sibling_iterator(this->last);
00478   }
00479 
00482 
00483   template<class T> typename tree<T>::sibling_iterator tree<T>::sibling_rend() {
00484     return tree<T>::sibling_iterator((tree<T>*)NULL);
00485   }
00486 
00489 
00490   template<class T> typename tree<T>::const_sibling_iterator tree<T>::sibling_rbegin() const {
00491     return tree<T>::const_sibling_iterator(this->last);
00492   }
00493 
00496 
00497   template<class T> typename tree<T>::const_sibling_iterator tree<T>::sibling_rend() const {
00498     return tree<T>::const_sibling_iterator((tree<T>*)NULL);
00499   }
00500 
00501 
00502 
00508 
00513   
00514   template<class T, class N> class basic_tree_iterator {
00515     friend class tree<T>;
00516     
00517     protected:
00518       N *tr;
00519       
00520     public:
00521       basic_tree_iterator();
00522       ~basic_tree_iterator();
00523 
00525       const T& operator*() const;
00526       const T* operator->() const;
00528       const T* get_info() const;
00529       bool operator==(const basic_tree_iterator &t) const;
00530       bool operator!=(const basic_tree_iterator &t) const;      
00531 
00533       bool is_defined() const;
00535       bool is_root() const;
00536       bool empty() const;
00537       bool has_ancestor(const tree<T> &p) const;
00538       unsigned int num_children() const;
00539 
00541       const_tree_preorder_iterator<T> get_parent() const;
00543       const_tree_sibling_iterator<T> nth_child(unsigned int n) const;
00544       const tree<T> & nth_child_ref(unsigned int n) const;
00546       const_tree_preorder_iterator<T> begin() const;
00547       const_tree_preorder_iterator<T> end() const;
00548       const_tree_sibling_iterator<T> sibling_begin() const;
00549       const_tree_sibling_iterator<T> sibling_end() const;
00550       const_tree_sibling_iterator<T> sibling_rbegin() const;
00551       const_tree_sibling_iterator<T> sibling_rend() const;
00552   };
00553 
00556 
00557   template<class T> class basic_const_tree_iterator : public basic_tree_iterator<T, const tree<T> > {
00558     friend class tree_preorder_iterator<T>;
00559     friend class tree_sibling_iterator<T>;
00560     friend class const_tree_preorder_iterator<T>;
00561     friend class const_tree_sibling_iterator<T>;
00562   };
00563 
00568   
00569   template<class T> class basic_nonconst_tree_iterator : public basic_tree_iterator<T, tree<T> > {
00570     friend class tree_preorder_iterator<T>;
00571     friend class tree_sibling_iterator<T>;
00572     friend class const_tree_preorder_iterator<T>;
00573     friend class const_tree_sibling_iterator<T>;
00574 
00575     public:
00576       basic_nonconst_tree_iterator();
00577       ~basic_nonconst_tree_iterator();
00578       T& operator*() const;
00579       T* operator->() const;
00581       T* get_info() const;
00582 
00584       tree_preorder_iterator<T> get_parent();
00585       // get iterator to nth child
00586       tree_sibling_iterator<T> nth_child(unsigned int);
00587       // get reference to nth child (Useful for Java API)
00588       tree<T>& nth_child_ref(unsigned int);
00589 
00591       tree_preorder_iterator<T> begin();
00592       tree_preorder_iterator<T> end();
00593       tree_sibling_iterator<T> sibling_begin();
00594       tree_sibling_iterator<T> sibling_end();
00595       tree_sibling_iterator<T> sibling_rbegin();
00596       tree_sibling_iterator<T> sibling_rend();
00597 
00599       void add_child(const tree<T>& t, bool last=true);
00601       void hang_child(tree<T>& t, tree_sibling_iterator<T> where=tree_sibling_iterator<T>(NULL));
00602       void hang_child(basic_nonconst_tree_iterator &p, tree_sibling_iterator<T> where=tree_sibling_iterator<T>(NULL));
00603   };
00604 
00605 
00606 
00610   
00611   template<class T, class X> class basic_preorder_iterator : public X {
00612     public: 
00613       basic_preorder_iterator();
00614       basic_preorder_iterator(const basic_preorder_iterator &p);
00615       ~basic_preorder_iterator();
00616 
00617       basic_preorder_iterator<T,X> operator++(int);
00618       basic_preorder_iterator<T,X>& operator++();
00619       basic_preorder_iterator<T,X> operator--(int);
00620       basic_preorder_iterator<T,X>& operator--();
00621   };
00622 
00623 
00627   
00628   template<class T, class X> class basic_sibling_iterator : public X {
00629 
00630     public: 
00631       basic_sibling_iterator();
00632       basic_sibling_iterator(const basic_sibling_iterator &p);
00633       ~basic_sibling_iterator();
00634 
00635       basic_sibling_iterator<T,X> operator++(int);
00636       basic_sibling_iterator<T,X>& operator++();
00637       basic_sibling_iterator<T,X> operator--(int);
00638       basic_sibling_iterator<T,X>& operator--();
00639   };
00640 
00641 
00644 
00645   template<class T> class tree_preorder_iterator : public basic_preorder_iterator<T,basic_nonconst_tree_iterator<T> > {
00646     friend class tree_sibling_iterator<T>;
00647     friend class const_tree_preorder_iterator<T>;
00648     friend class const_tree_sibling_iterator<T>;
00649     public: 
00650       tree_preorder_iterator();
00651       tree_preorder_iterator(tree<T> *p);
00652       tree_preorder_iterator<T>& operator=(const tree_preorder_iterator<T> &p);
00653       tree_preorder_iterator(const basic_preorder_iterator<T,basic_nonconst_tree_iterator<T> > &p);
00654       tree_preorder_iterator(const tree_preorder_iterator<T> &p);
00655       tree_preorder_iterator(const tree_sibling_iterator<T> &p);
00656       ~tree_preorder_iterator();
00657 
00658   };
00659 
00662 
00663   template<class T> class const_tree_preorder_iterator : public basic_preorder_iterator<T,basic_const_tree_iterator<T> > {
00664     friend class const_tree_sibling_iterator<T>;
00665     public: 
00666       const_tree_preorder_iterator();
00667       const_tree_preorder_iterator(tree<T> *p);
00668       const_tree_preorder_iterator<T>& operator=(const const_tree_preorder_iterator<T> &p);
00669       const_tree_preorder_iterator(const basic_preorder_iterator<T,basic_const_tree_iterator<T> > &p);
00670       const_tree_preorder_iterator(const basic_preorder_iterator<T,basic_nonconst_tree_iterator<T> > &p);
00671       const_tree_preorder_iterator(const tree<T> *p);
00672       const_tree_preorder_iterator(const tree_preorder_iterator<T> &p);
00673       const_tree_preorder_iterator(const tree_sibling_iterator<T> &p);
00674       const_tree_preorder_iterator(const const_tree_preorder_iterator<T> &p);
00675       const_tree_preorder_iterator(const const_tree_sibling_iterator<T> &p);
00676       ~const_tree_preorder_iterator();
00677   };
00678 
00681 
00682   template<class T> class tree_sibling_iterator : public basic_sibling_iterator<T,basic_nonconst_tree_iterator<T> > {
00683     friend class tree_preorder_iterator<T>;
00684     friend class const_tree_preorder_iterator<T>;
00685     friend class const_tree_sibling_iterator<T>;
00686     public: 
00687       tree_sibling_iterator();
00688       tree_sibling_iterator(tree<T> *p);
00689       tree_sibling_iterator<T>& operator=(const tree_sibling_iterator<T> &p);
00690       tree_sibling_iterator(const basic_sibling_iterator<T,basic_nonconst_tree_iterator<T> > &p);
00691       tree_sibling_iterator(const tree_sibling_iterator<T> &p);
00692       tree_sibling_iterator(const tree_preorder_iterator<T> &p);
00693       ~tree_sibling_iterator();
00694   };
00695 
00698 
00699   template<class T> class const_tree_sibling_iterator : public basic_sibling_iterator<T,basic_const_tree_iterator<T> > {
00700     friend class tree_preorder_iterator<T>;
00701     friend class const_tree_preorder_iterator<T>;
00702     public: 
00703       const_tree_sibling_iterator();
00704       const_tree_sibling_iterator(tree<T> *p);
00705       const_tree_sibling_iterator<T>& operator=(const const_tree_sibling_iterator<T> &p);
00706       const_tree_sibling_iterator(const basic_sibling_iterator<T,basic_const_tree_iterator<T> > &p);
00707       const_tree_sibling_iterator(const basic_sibling_iterator<T,basic_nonconst_tree_iterator<T> > &p);
00708       const_tree_sibling_iterator(const tree<T> *p);
00709       const_tree_sibling_iterator(const tree_sibling_iterator<T> &p);
00710       const_tree_sibling_iterator(const tree_preorder_iterator<T> &p);
00711       const_tree_sibling_iterator(const const_tree_sibling_iterator<T> &p);
00712       const_tree_sibling_iterator(const const_tree_preorder_iterator<T> &p);
00713       ~const_tree_sibling_iterator();
00714   };
00715 
00716 
00717 
00721   
00724   template<class T, class N> basic_tree_iterator<T,N>::basic_tree_iterator() {tr=NULL;}
00725   template<class T, class N> basic_tree_iterator<T,N>::~basic_tree_iterator() {}  
00726   template<class T, class N> const T& basic_tree_iterator<T,N>::operator*() const {return *(tr->pinfo);}
00727   template<class T, class N> const T* basic_tree_iterator<T,N>::operator->() const {return tr->pinfo;}
00728   template<class T, class N> const T* basic_tree_iterator<T,N>::get_info() const {return tr->pinfo;}
00729   template<class T, class N> bool basic_tree_iterator<T,N>::operator==(const basic_tree_iterator<T,N> &t) const {return tr==t.tr;}
00730   template<class T, class N> bool basic_tree_iterator<T,N>::operator!=(const basic_tree_iterator<T,N> &t) const {return tr!=t.tr;}
00731   template<class T, class N> bool basic_tree_iterator<T,N>::is_defined() const {return tr!=NULL;}
00732 
00735   template<class T, class N> bool basic_tree_iterator<T,N>::is_root() const {return tr->is_root();}
00736   template<class T, class N> bool basic_tree_iterator<T,N>::empty() const {return tr->empty();}
00737   template<class T, class N> bool basic_tree_iterator<T,N>::has_ancestor(const tree<T> &p) const {return tr->has_ancestor(p);}
00738   template<class T, class N> unsigned int basic_tree_iterator<T,N>::num_children() const {return tr->num_children();}      
00739   template<class T, class N> const_tree_sibling_iterator<T> basic_tree_iterator<T,N>::nth_child(unsigned int n) const { return tr->nth_child(n);}
00740   template<class T, class N> const tree<T>& basic_tree_iterator<T,N>::nth_child_ref(unsigned int n) const { return tr->nth_child_ref(n);}
00741   template<class T, class N> const_tree_preorder_iterator<T> basic_tree_iterator<T,N>::get_parent() const {return tr->get_parent();}
00742   template<class T, class N> const_tree_preorder_iterator<T> basic_tree_iterator<T,N>::begin() const {return tr->begin();}
00743   template<class T, class N> const_tree_preorder_iterator<T> basic_tree_iterator<T,N>::end() const {return tr->end();}
00744   template<class T, class N> const_tree_sibling_iterator<T> basic_tree_iterator<T,N>::sibling_begin() const {return tr->sibling_begin();}
00745   template<class T, class N> const_tree_sibling_iterator<T> basic_tree_iterator<T,N>::sibling_end() const {return tr->sibling_end();}
00746   template<class T, class N> const_tree_sibling_iterator<T> basic_tree_iterator<T,N>::sibling_rbegin() const {return tr->sibling_rbegin();}
00747   template<class T, class N> const_tree_sibling_iterator<T> basic_tree_iterator<T,N>::sibling_rend() const {return tr->sibling_rend();}
00748   
00751   template<class T> basic_nonconst_tree_iterator<T>::basic_nonconst_tree_iterator() {}
00752   template<class T> basic_nonconst_tree_iterator<T>::~basic_nonconst_tree_iterator() {}
00753   template<class T> T& basic_nonconst_tree_iterator<T>::operator*() const {return *(this->tr->pinfo);}
00754   template<class T> T* basic_nonconst_tree_iterator<T>::operator->() const {return this->tr->pinfo;}
00755   template<class T> T* basic_nonconst_tree_iterator<T>::get_info() const {return this->tr->pinfo;}
00756 
00759   template<class T> tree_sibling_iterator<T> basic_nonconst_tree_iterator<T>::nth_child(unsigned int n) { return this->tr->nth_child(n); }
00760   template<class T> tree<T>& basic_nonconst_tree_iterator<T>::nth_child_ref(unsigned int n) { return this->tr->nth_child_ref(n); }
00761   template<class T> tree_preorder_iterator<T> basic_nonconst_tree_iterator<T>::get_parent() {return this->tr->get_parent();}
00762   template<class T> tree_preorder_iterator<T> basic_nonconst_tree_iterator<T>::begin() {return this->tr->begin();}
00763   template<class T> tree_preorder_iterator<T> basic_nonconst_tree_iterator<T>::end() {return this->tr->end();}
00764   template<class T> tree_sibling_iterator<T> basic_nonconst_tree_iterator<T>::sibling_begin() {return this->tr->sibling_begin();}
00765   template<class T> tree_sibling_iterator<T> basic_nonconst_tree_iterator<T>::sibling_end() {return this->tr->sibling_end();}
00766   template<class T> tree_sibling_iterator<T> basic_nonconst_tree_iterator<T>::sibling_rbegin() {return this->tr->sibling_rbegin();}
00767   template<class T> tree_sibling_iterator<T> basic_nonconst_tree_iterator<T>::sibling_rend() {return this->tr->sibling_rend();}
00768   template<class T> void basic_nonconst_tree_iterator<T>::add_child(const tree<T>& t,bool last) {this->tr->add_child(t,last);}
00769   template<class T> void basic_nonconst_tree_iterator<T>::hang_child(tree<T>& t, tree_sibling_iterator<T> where) {this->tr->hang_child(t,where);}
00770   template<class T> void basic_nonconst_tree_iterator<T>::hang_child(basic_nonconst_tree_iterator<T>& p, tree_sibling_iterator<T> where) {this->tr->hang_child(*p.tr,where);}
00771 
00772 
00775   template<class T, class X> basic_preorder_iterator<T,X>::basic_preorder_iterator() {}
00776   template<class T, class X> basic_preorder_iterator<T,X>::basic_preorder_iterator(const basic_preorder_iterator<T,X> &p) {this->tr=p.tr;}
00777   template<class T, class X> basic_preorder_iterator<T,X>::~basic_preorder_iterator() {}  
00778 
00780   template<class T, class X> basic_preorder_iterator<T,X> basic_preorder_iterator<T,X>::operator++(int) {
00781     basic_preorder_iterator<T,X> b = (*this);
00782     ++(*this);
00783     return b;
00784   }
00786   template<class T, class X> basic_preorder_iterator<T,X>& basic_preorder_iterator<T,X>::operator++() {
00787     if (this->tr->first != NULL) 
00788       this->tr = this->tr->first;
00789     else {
00790       while (this->tr!=NULL && this->tr->next==NULL) 
00791         this->tr = this->tr->parent;
00792       if (this->tr!=NULL) this->tr = this->tr->next;
00793     }
00794     return *this;
00795   }
00797   template<class T, class X> basic_preorder_iterator<T,X> basic_preorder_iterator<T,X>::operator--(int) {
00798     basic_preorder_iterator<T,X> b = (*this);
00799     --(*this);
00800     return b;
00801   }
00803   template<class T, class X> basic_preorder_iterator<T,X>& basic_preorder_iterator<T,X>::operator--() {
00804     if (this->tr->prev == NULL) 
00805       this->tr = this->tr->parent;
00806     else {
00807       this->tr = this->tr->prev;
00808       while (this->tr->nchildren>0)
00809         this->tr = this->tr->last;
00810     }
00811     return *this;
00812   }
00813 
00814 
00817   template<class T, class X> basic_sibling_iterator<T,X>::basic_sibling_iterator() {}
00818   template<class T, class X> basic_sibling_iterator<T,X>::basic_sibling_iterator(const basic_sibling_iterator<T,X> &p) {this->tr=p.tr;}
00819   template<class T, class X> basic_sibling_iterator<T,X>::~basic_sibling_iterator() {}  
00820 
00821   // postincrement
00822   template<class T, class X> basic_sibling_iterator<T,X> basic_sibling_iterator<T,X>::operator++(int) {
00823     basic_sibling_iterator<T,X> b = (*this);
00824     ++(*this);
00825     return b;
00826   }
00827   // preincrement
00828   template<class T, class X> basic_sibling_iterator<T,X>& basic_sibling_iterator<T,X>::operator++() {
00829     if (this->tr!=NULL) this->tr = this->tr->next;
00830     return *this;
00831   }
00832   // postdecrement
00833   template<class T, class X> basic_sibling_iterator<T,X> basic_sibling_iterator<T,X>::operator--(int) {
00834     basic_sibling_iterator<T,X> b = (*this);
00835     --(*this);
00836     return b;
00837   }
00838   // predecrement
00839   template<class T, class X> basic_sibling_iterator<T,X>& basic_sibling_iterator<T,X>::operator--() {
00840     if (this->tr!=NULL) this->tr = this->tr->prev;
00841     return *this;
00842   }
00843 
00844 
00847   template<class T> tree_preorder_iterator<T>::tree_preorder_iterator() {}
00848   template<class T> tree_preorder_iterator<T>::tree_preorder_iterator(tree<T> *p) {this->tr = p;}
00849   template<class T> tree_preorder_iterator<T>& tree_preorder_iterator<T>::operator=(const tree_preorder_iterator<T> &p) {
00850     if (this!=&p) this->tr = p.tr;
00851     return (*this);
00852   }
00853   template<class T> tree_preorder_iterator<T>::tree_preorder_iterator(const basic_preorder_iterator<T,basic_nonconst_tree_iterator<T>> &p) {this->tr = p.tr;}
00854   template<class T> tree_preorder_iterator<T>::tree_preorder_iterator(const tree_preorder_iterator<T> &p) {this->tr = p.tr;}
00855   template<class T> tree_preorder_iterator<T>::tree_preorder_iterator(const tree_sibling_iterator<T> &p) {this->tr = p.tr;}
00856   template<class T> tree_preorder_iterator<T>::~tree_preorder_iterator() {}
00857 
00860   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator() {}
00861   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(tree<T> *p) {this->tr = p;}
00862   template<class T> const_tree_preorder_iterator<T>& const_tree_preorder_iterator<T>::operator=(const const_tree_preorder_iterator<T> &p) {
00863     if (this!=&p) this->tr = p.tr;
00864     return (*this);
00865   }
00866   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const basic_preorder_iterator<T,basic_const_tree_iterator<T>> &p) {this->tr = p.tr;}
00867   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const basic_preorder_iterator<T,basic_nonconst_tree_iterator<T>> &p) {this->tr = p.tr;}
00868   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const tree<T> *p) {this->tr = p;}
00869   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const tree_preorder_iterator<T> &p) {this->tr = p.tr;}
00870   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const tree_sibling_iterator<T> &p) {this->tr = p.tr;}
00871   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const const_tree_preorder_iterator<T> &p) {this->tr = p.tr;}
00872   template<class T> const_tree_preorder_iterator<T>::const_tree_preorder_iterator(const const_tree_sibling_iterator<T> &p) {this->tr = p.tr;}
00873   template<class T> const_tree_preorder_iterator<T>::~const_tree_preorder_iterator() {}
00874 
00875 
00878   template<class T> tree_sibling_iterator<T>::tree_sibling_iterator() {}
00879   template<class T> tree_sibling_iterator<T>::tree_sibling_iterator(tree<T> *p) {this->tr = p;}
00880   template<class T> tree_sibling_iterator<T>& tree_sibling_iterator<T>::operator=(const tree_sibling_iterator<T> &p) {
00881     if (this!=&p) this->tr = p.tr;
00882     return (*this);
00883   }
00884   template<class T> tree_sibling_iterator<T>::tree_sibling_iterator(const basic_sibling_iterator<T,basic_nonconst_tree_iterator<T>> &p) {this->tr = p.tr;}
00885   template<class T> tree_sibling_iterator<T>::tree_sibling_iterator(const tree_sibling_iterator<T> &p) {this->tr = p.tr;}
00886   template<class T> tree_sibling_iterator<T>::tree_sibling_iterator(const tree_preorder_iterator<T> &p) {this->tr = p.tr;}
00887   template<class T> tree_sibling_iterator<T>::~tree_sibling_iterator() {}
00888 
00889 
00892   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator() {}
00893   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(tree<T> *p) {this->tr = p;}
00894   template<class T> const_tree_sibling_iterator<T>& const_tree_sibling_iterator<T>::operator=(const const_tree_sibling_iterator<T> &p) {
00895     if (this!=&p) this->tr = p.tr;
00896     return (*this);
00897   }
00898   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const basic_sibling_iterator<T,basic_const_tree_iterator<T>> &p) {this->tr = p.tr;}
00899   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const basic_sibling_iterator<T,basic_nonconst_tree_iterator<T>> &p) {this->tr = p.tr;}
00900   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const tree<T> *p) {this->tr = p;}
00901   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const tree_sibling_iterator<T> &p) {this->tr = p.tr;}
00902   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const tree_preorder_iterator<T> &p) {this->tr = p.tr;}
00903   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const const_tree_sibling_iterator<T> &p) {this->tr = p.tr;}
00904   template<class T> const_tree_sibling_iterator<T>::const_tree_sibling_iterator(const const_tree_preorder_iterator<T> &p) {this->tr = p.tr;}
00905   template<class T> const_tree_sibling_iterator<T>::~const_tree_sibling_iterator() {}
00906 
00907 
00908 } // namespace
00909 
00910 #endif