tree< T, tree_node_allocator >::fixed_depth_iterator Class Reference

#include <tree.h>

Inheritance diagram for tree< T, tree_node_allocator >::fixed_depth_iterator:

Inheritance graph
[legend]
Collaboration diagram for tree< T, tree_node_allocator >::fixed_depth_iterator:

Collaboration graph
[legend]

Detailed Description

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>
class tree< T, tree_node_allocator >::fixed_depth_iterator

Iterator which traverses only the nodes at a given depth from the root.

Definition at line 221 of file tree.h.


Public Member Functions

 fixed_depth_iterator ()
 fixed_depth_iterator (tree_node *)
 fixed_depth_iterator (const iterator_base &)
 fixed_depth_iterator (const sibling_iterator &)
 fixed_depth_iterator (const fixed_depth_iterator &)
bool operator== (const fixed_depth_iterator &) const
bool operator!= (const fixed_depth_iterator &) const
fixed_depth_iteratoroperator++ ()
fixed_depth_iteratoroperator-- ()
fixed_depth_iterator operator++ (int)
fixed_depth_iterator operator-- (int)
fixed_depth_iteratoroperator+= (unsigned int)
fixed_depth_iteratoroperator-= (unsigned int)

Data Fields

tree_nodefirst_parent_

Private Member Functions

void set_first_parent_ ()
void find_leftmost_parent_ ()

Constructor & Destructor Documentation

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator (  )  [inline]

Definition at line 2222 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::set_first_parent_().

02223    : iterator_base()
02224    {
02225    set_first_parent_();
02226    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator ( tree_node tn  )  [inline]

Definition at line 2229 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::set_first_parent_().

02230    : iterator_base(tn)
02231    {
02232    set_first_parent_();
02233    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator ( const iterator_base other  )  [inline]

Definition at line 2236 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::set_first_parent_().

02237    : iterator_base(other.node)
02238    {
02239    set_first_parent_();
02240    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator ( const sibling_iterator other  )  [inline]

Definition at line 2243 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::find_leftmost_parent_().

02244    : iterator_base(other.node), first_parent_(other.parent_)
02245    {
02246    find_leftmost_parent_();
02247    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator ( const fixed_depth_iterator other  )  [inline]

Definition at line 2250 of file tree.h.

02251    : iterator_base(other.node), first_parent_(other.first_parent_)
02252    {
02253    }


Member Function Documentation

template<class T, class tree_node_allocator>
bool tree< T, tree_node_allocator >::fixed_depth_iterator::operator== ( const fixed_depth_iterator other  )  const [inline]

Definition at line 2256 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::first_parent_, and tree< T, tree_node_allocator >::iterator_base::node.

02257    {
02258    if(other.node==this->node && other.first_parent_==first_parent_) return true;
02259    else return false;
02260    }

template<class T, class tree_node_allocator>
bool tree< T, tree_node_allocator >::fixed_depth_iterator::operator!= ( const fixed_depth_iterator other  )  const [inline]

Definition at line 2263 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::first_parent_, and tree< T, tree_node_allocator >::iterator_base::node.

02264    {
02265    if(other.node!=this->node || other.first_parent_!=first_parent_) return true;
02266    else return false;
02267    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator & tree< T, tree_node_allocator >::fixed_depth_iterator::operator++ (  )  [inline]

Definition at line 2295 of file tree.h.

References tree_node_< T >::first_child, tree_node_< T >::next_sibling, tree< T, tree_node_allocator >::iterator_base::node, and tree_node_< T >::parent.

02296    {
02297    assert(this->node!=0);
02298 
02299    if(this->node->next_sibling) {
02300       this->node=this->node->next_sibling;
02301       }
02302    else { 
02303       int relative_depth=0;
02304       upper:
02305       do {
02306          this->node=this->node->parent;
02307          if(this->node==0) return *this;
02308          --relative_depth;
02309          } while(this->node->next_sibling==0);
02310       lower:
02311       this->node=this->node->next_sibling;
02312       while(this->node->first_child==0) {
02313          if(this->node->next_sibling==0)
02314             goto upper;
02315          this->node=this->node->next_sibling;
02316          if(this->node==0) return *this;
02317          }
02318       while(relative_depth<0 && this->node->first_child!=0) {
02319          this->node=this->node->first_child;
02320          ++relative_depth;
02321          }
02322       if(relative_depth<0) {
02323          if(this->node->next_sibling==0) goto upper;
02324          else                          goto lower;
02325          }
02326       }
02327    return *this;
02328 
02329 // if(this->node->next_sibling!=0) {
02330 //    this->node=this->node->next_sibling;
02331 //    assert(this->node!=0);
02332 //    if(this->node->parent==0 && this->node->next_sibling==0) // feet element
02333 //       this->node=0;
02334 //    }
02335 // else {
02336 //    tree_node *par=this->node->parent;
02337 //    do {
02338 //       par=par->next_sibling;
02339 //       if(par==0) { // FIXME: need to keep track of this!
02340 //          this->node=0;
02341 //          return *this;
02342 //          }
02343 //       } while(par->first_child==0);
02344 //    this->node=par->first_child;
02345 //    }
02346    return *this;
02347    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator & tree< T, tree_node_allocator >::fixed_depth_iterator::operator-- (  )  [inline]

Definition at line 2350 of file tree.h.

References tree_node_< T >::last_child, tree< T, tree_node_allocator >::iterator_base::node, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

02351    {
02352    assert(this->node!=0);
02353    if(this->node->prev_sibling!=0) {
02354       this->node=this->node->prev_sibling;
02355       assert(this->node!=0);
02356       if(this->node->parent==0 && this->node->prev_sibling==0) // head element
02357          this->node=0;
02358       }
02359    else {
02360       tree_node *par=this->node->parent;
02361       do {
02362          par=par->prev_sibling;
02363          if(par==0) { // FIXME: need to keep track of this!
02364             this->node=0;
02365             return *this;
02366             }
02367          } while(par->last_child==0);
02368       this->node=par->last_child;
02369       }
02370    return *this;
02371 }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator tree< T, tree_node_allocator >::fixed_depth_iterator::operator++ ( int   )  [inline]

Definition at line 2374 of file tree.h.

02375    {
02376    fixed_depth_iterator copy = *this;
02377    ++(*this);
02378    return copy;
02379    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator tree< T, tree_node_allocator >::fixed_depth_iterator::operator-- ( int   )  [inline]

Definition at line 2382 of file tree.h.

02383 {
02384   fixed_depth_iterator copy = *this;
02385   --(*this);
02386   return copy;
02387 }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator & tree< T, tree_node_allocator >::fixed_depth_iterator::operator+= ( unsigned int  num  )  [inline]

Definition at line 2400 of file tree.h.

02401    {
02402    while(num>0) {
02403       ++(*this);
02404       --(num);
02405       }
02406    return *this;
02407    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator & tree< T, tree_node_allocator >::fixed_depth_iterator::operator-= ( unsigned int  num  )  [inline]

Definition at line 2390 of file tree.h.

02391    {
02392    while(num>0) {
02393       --(*this);
02394       --(num);
02395       }
02396    return (*this);
02397    }

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::fixed_depth_iterator::set_first_parent_ (  )  [inline, private]

Definition at line 2270 of file tree.h.

References tree< T, tree_node_allocator >::fixed_depth_iterator::find_leftmost_parent_(), tree< T, tree_node_allocator >::fixed_depth_iterator::first_parent_, tree< T, tree_node_allocator >::iterator_base::node, and tree_node_< T >::parent.

Referenced by tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator().

02271    {
02272    return; // FIXME: we do not use first_parent_ yet, and it actually needs some serious reworking if
02273            // it is ever to work at the 'head' level.
02274    first_parent_=0;
02275    if(this->node==0) return;
02276    if(this->node->parent!=0)
02277       first_parent_=this->node->parent;
02278    if(first_parent_)
02279       find_leftmost_parent_();
02280    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::fixed_depth_iterator::find_leftmost_parent_ (  )  [inline, private]

Definition at line 2283 of file tree.h.

References tree_node_< T >::first_child, tree< T, tree_node_allocator >::fixed_depth_iterator::first_parent_, and tree_node_< T >::prev_sibling.

Referenced by tree< T, tree_node_allocator >::fixed_depth_iterator::fixed_depth_iterator(), and tree< T, tree_node_allocator >::fixed_depth_iterator::set_first_parent_().

02284    {
02285    return; // FIXME: see 'set_first_parent()'
02286    tree_node *tmppar=first_parent_;
02287    while(tmppar->prev_sibling) {
02288       tmppar=tmppar->prev_sibling;
02289       if(tmppar->first_child)
02290          first_parent_=tmppar;
02291       }
02292    }

Here is the caller graph for this function:


Field Documentation

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>
tree_node* tree< T, tree_node_allocator >::fixed_depth_iterator::first_parent_

Definition at line 238 of file tree.h.

Referenced by tree< T, tree_node_allocator >::fixed_depth_iterator::find_leftmost_parent_(), tree< T, tree_node_allocator >::fixed_depth_iterator::operator!=(), tree< T, tree_node_allocator >::fixed_depth_iterator::operator==(), and tree< T, tree_node_allocator >::fixed_depth_iterator::set_first_parent_().


The documentation for this class was generated from the following file:
Generated on Wed Feb 27 20:32:37 2008 for php.ast.svn.src. by  doxygen 1.5.3