tree< T, tree_node_allocator > Class Template Reference

#include <tree.h>

Inheritance diagram for tree< T, tree_node_allocator >:

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

Collaboration graph
[legend]

Detailed Description

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

Definition at line 107 of file tree.h.


Public Types

typedef T value_type
 Value of the data stored at a node.
typedef
pre_order_iterator 
iterator
 The default iterator types throughout the tree class.
typedef
breadth_first_queued_iterator 
breadth_first_iterator

Public Member Functions

 tree ()
 tree (const T &)
 tree (const iterator_base &)
 tree (const tree< T, tree_node_allocator > &)
 ~tree ()
void operator= (const tree< T, tree_node_allocator > &)
pre_order_iterator begin () const
 Return iterator to the beginning of the tree.
pre_order_iterator end () const
 Return iterator to the end of the tree.
post_order_iterator begin_post () const
 Return post-order iterator to the beginning of the tree.
post_order_iterator end_post () const
 Return post-order iterator to the end of the tree.
fixed_depth_iterator begin_fixed (const iterator_base &, unsigned int) const
 Return fixed-depth iterator to the first node at a given depth.
fixed_depth_iterator end_fixed (const iterator_base &, unsigned int) const
 Return fixed-depth iterator to end of the nodes at given depth.
breadth_first_queued_iterator begin_breadth_first () const
 Return breadth-first iterator to the first node at a given depth.
breadth_first_queued_iterator end_breadth_first () const
 Return breadth-first iterator to end of the nodes at given depth.
sibling_iterator begin (const iterator_base &) const
 Return sibling iterator to the first child of given node.
sibling_iterator end (const iterator_base &) const
 Return sibling iterator to the end of the children of a given node.
leaf_iterator begin_leaf () const
 Return leaf iterator to the first leaf of the tree.
leaf_iterator end_leaf () const
 Return leaf iterator to the last leaf of the tree.
template<typename iter>
iter previous_sibling (iter) const
 Return iterator to the previous sibling of a node.
template<typename iter>
iter next_sibling (iter) const
 Return iterator to the next sibling of a node.
template<typename iter>
iter next_at_same_depth (iter) const
 Return iterator to the next node at a given depth.
void clear ()
 Erase all nodes of the tree.
template<typename iter>
iter erase (iter)
 Erase element at position pointed to by iterator, return incremented iterator.
void erase_children (const iterator_base &)
 Erase all children of the node pointed to by iterator.
template<typename iter>
iter append_child (iter position)
 Insert empty node as last/first child of node pointed to by position.
template<typename iter>
iter prepend_child (iter position)
template<typename iter>
iter append_child (iter position, const T &x)
 Insert node as last/first child of node pointed to by position.
template<typename iter>
iter prepend_child (iter position, const T &x)
template<typename iter>
iter append_child (iter position, iter other_position)
 Append the node (plus its children) at other_position as last/first child of position.
template<typename iter>
iter prepend_child (iter position, iter other_position)
template<typename iter>
iter append_children (iter position, sibling_iterator from, sibling_iterator to)
 Append the nodes in the from-to range (plus their children) as last/first children of position.
template<typename iter>
iter prepend_children (iter position, sibling_iterator from, sibling_iterator to)
pre_order_iterator set_head (const T &x)
 Short-hand to insert topmost node in otherwise empty tree.
template<typename iter>
iter insert (iter position, const T &x)
 Insert node as previous sibling of node pointed to by position.
sibling_iterator insert (sibling_iterator position, const T &x)
 Specialisation of previous member.
template<typename iter>
iter insert_subtree (iter position, const iterator_base &subtree)
 Insert node (with children) pointed to by subtree as previous sibling of node pointed to by position.
template<typename iter>
iter insert_after (iter position, const T &x)
 Insert node as next sibling of node pointed to by position.
template<typename iter>
iter insert_subtree_after (iter position, const iterator_base &subtree)
 Insert node (with children) pointed to by subtree as next sibling of node pointed to by position.
template<typename iter>
iter replace (iter position, const T &x)
 Replace node at 'position' with other node (keeping same children); 'position' becomes invalid.
template<typename iter>
iter replace (iter position, const iterator_base &from)
 Replace node at 'position' with subtree starting at 'from' (do not erase subtree at 'from'); see above.
sibling_iterator replace (sibling_iterator orig_begin, sibling_iterator orig_end, sibling_iterator new_begin, sibling_iterator new_end)
 Replace string of siblings (plus their children) with copy of a new string (with children); see above.
template<typename iter>
iter flatten (iter position)
 Move all children of node at 'position' to be siblings, returns position.
template<typename iter>
iter reparent (iter position, sibling_iterator begin, sibling_iterator end)
 Move nodes in range to be children of 'position'.
template<typename iter>
iter reparent (iter position, iter from)
 Move all child nodes of 'from' to be children of 'position'.
template<typename iter>
iter wrap (iter position, const T &x)
 Replace node with a new node, making the old node a child of the new node.
template<typename iter>
iter move_after (iter target, iter source)
 Move 'source' node (plus its children) to become the next sibling of 'target'.
template<typename iter>
iter move_before (iter target, iter source)
 Move 'source' node (plus its children) to become the previous sibling of 'target'.
sibling_iterator move_before (sibling_iterator target, sibling_iterator source)
template<typename iter>
iter move_ontop (iter target, iter source)
 Move 'source' node (plus its children) to become the node at 'target' (erasing the node at 'target').
void merge (sibling_iterator, sibling_iterator, sibling_iterator, sibling_iterator, bool duplicate_leaves=false)
 Merge with other tree, creating new branches and leaves only if they are not already present.
void sort (sibling_iterator from, sibling_iterator to, bool deep=false)
 Sort (std::sort only moves values of nodes, this one moves children as well).
template<class StrictWeakOrdering>
void sort (sibling_iterator from, sibling_iterator to, StrictWeakOrdering comp, bool deep=false)
template<typename iter>
bool equal (const iter &one, const iter &two, const iter &three) const
 Compare two ranges of nodes (compares nodes as well as tree structure).
template<typename iter, class BinaryPredicate>
bool equal (const iter &one, const iter &two, const iter &three, BinaryPredicate) const
template<typename iter>
bool equal_subtree (const iter &one, const iter &two) const
template<typename iter, class BinaryPredicate>
bool equal_subtree (const iter &one, const iter &two, BinaryPredicate) const
tree subtree (sibling_iterator from, sibling_iterator to) const
 Extract a new tree formed by the range of siblings plus all their children.
void subtree (tree &, sibling_iterator from, sibling_iterator to) const
void swap (sibling_iterator it)
 Exchange the node (plus subtree) with its sibling node (do nothing if no sibling present).
void swap (iterator, iterator)
 Exchange two nodes (plus subtrees).
int size () const
 Count the total number of nodes.
int size (const iterator_base &) const
 Count the total number of nodes below the indicated node (plus one).
bool empty () const
 Check if tree is empty.
int depth (const iterator_base &) const
 Compute the depth to the root.
unsigned int number_of_siblings (const iterator_base &) const
 Count the number of 'next' siblings of node at iterator.
bool is_in_subtree (const iterator_base &position, const iterator_base &begin, const iterator_base &end) const
 Determine whether node at position is in the subtrees with root in the range.
bool is_valid (const iterator_base &) const
 Determine whether the iterator is an 'end' iterator and thus not actually pointing to a node.
unsigned int index (sibling_iterator it) const
 Determine the index of a node in the range of siblings to which it belongs.
sibling_iterator child (const iterator_base &position, unsigned int) const
 Inverse of 'index': return the n-th child of the node at position.

Static Public Member Functions

template<typename iter>
static iter parent (iter)
 Return iterator to the parent of a node.
static unsigned int number_of_children (const iterator_base &)
 Count the number of children of node at position.

Data Fields

tree_nodehead
tree_nodefeet

Protected Types

typedef tree_node_< T > tree_node

Private Member Functions

void head_initialise_ ()
void copy_ (const tree< T, tree_node_allocator > &other)

Private Attributes

tree_node_allocator alloc_

Data Structures

class  breadth_first_queued_iterator
 Breadth-first iterator, using a queue. More...
class  compare_nodes
 Comparator class for two nodes of a tree (used for sorting and searching). More...
class  fixed_depth_iterator
 Iterator which traverses only the nodes at a given depth from the root. More...
class  iterator_base
 Base class for iterators, only pointers stored, no traversal logic. More...
class  iterator_base_less
 Comparator class for iterators (compares pointer values; why doesn't this work automatically?). More...
class  leaf_iterator
 Iterator which traverses only the leaves. More...
class  post_order_iterator
 Depth-first iterator, first accessing the children, then the node itself. More...
class  pre_order_iterator
 Depth-first iterator, first accessing the node, then its children. More...
class  sibling_iterator
 Iterator which traverses only the nodes which are siblings of each other. More...

Member Typedef Documentation

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>
typedef tree_node_<T> tree< T, tree_node_allocator >::tree_node [protected]

Definition at line 109 of file tree.h.

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

Value of the data stored at a node.

Definition at line 112 of file tree.h.

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>
typedef pre_order_iterator tree< T, tree_node_allocator >::iterator

The default iterator types throughout the tree class.

Definition at line 217 of file tree.h.

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>
typedef breadth_first_queued_iterator tree< T, tree_node_allocator >::breadth_first_iterator

Definition at line 218 of file tree.h.


Constructor & Destructor Documentation

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

Definition at line 500 of file tree.h.

References tree< T, tree_node_allocator >::head_initialise_().

00501    {
00502    head_initialise_();
00503    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::tree ( const T &  x  )  [inline]

Definition at line 506 of file tree.h.

References tree< T, tree_node_allocator >::head_initialise_(), and tree< T, tree_node_allocator >::set_head().

00507    {
00508    head_initialise_();
00509    set_head(x);
00510    }

Here is the call graph for this function:

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

Definition at line 513 of file tree.h.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::head_initialise_(), tree< T, tree_node_allocator >::replace(), and tree< T, tree_node_allocator >::set_head().

00514    {
00515    head_initialise_();
00516    set_head((*other));
00517    replace(begin(), other);
00518    }

Here is the call graph for this function:

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

Definition at line 554 of file tree.h.

References tree< T, tree_node_allocator >::copy_(), and tree< T, tree_node_allocator >::head_initialise_().

00555    {
00556    head_initialise_();
00557    copy_(other);
00558    }

Here is the call graph for this function:

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

Definition at line 521 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, tree< T, tree_node_allocator >::clear(), tree< T, tree_node_allocator >::feet, and tree< T, tree_node_allocator >::head.

00522    {
00523    clear();
00524    alloc_.deallocate(head,1);
00525    alloc_.deallocate(feet,1);
00526    }

Here is the call graph for this function:


Member Function Documentation

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

Definition at line 548 of file tree.h.

References tree< T, tree_node_allocator >::copy_().

00549    {
00550    copy_(other);
00551    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::pre_order_iterator tree< T, tree_node_allocator >::begin (  )  const [inline]

Return iterator to the beginning of the tree.

Definition at line 639 of file tree.h.

References tree< T, tree_node_allocator >::head, and tree_node_< T >::next_sibling.

Referenced by addClassCpp(), addFunctionCpp(), applyModification(), classAssignement(), className(), clean_pattern(), tree< T, tree_node_allocator >::copy_(), copy_branch(), tree< T, tree_node_allocator >::empty(), tree< T, tree_node_allocator >::equal_subtree(), exportXML(), Ast::fillAstInformation(), Ast::functionBoxing(), Ast::functionMapping(), functionReturnValue(), getNodeIter(), getNodeValue(), Ast::getSubVariables(), insert_branch(), Ast::nbNestedVariables(), Ast2Php::operator()(), Ast2Cpp::operator()(), ControlFlow::operator()(), RenameVariable::operator()(), RenameFunction::operator()(), RenameClass::operator()(), NumberSunkDiffuseInputs::operator()(), NumberDiffuseInputs::operator()(), NumberInput::operator()(), NumberResources::operator()(), NumberSinks::operator()(), kptree::print_subtree_bracketed(), kptree::print_tree_bracketed(), tree< T, tree_node_allocator >::size(), Ast::skeleton(), tree< T, tree_node_allocator >::sort(), Ast::sourceBoxing(), tree< T, tree_node_allocator >::subtree(), Ast::trace(), tree< T, tree_node_allocator >::tree(), writeCPP(), writeSiblingsCPP(), and writeSiblingsXML().

00640    {
00641    return pre_order_iterator(head->next_sibling);
00642    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::pre_order_iterator tree< T, tree_node_allocator >::end (  )  const [inline]

Return iterator to the end of the tree.

Definition at line 645 of file tree.h.

References tree< T, tree_node_allocator >::feet.

Referenced by addClassCpp(), addFunctionCpp(), applyModification(), tree< T, tree_node_allocator >::begin(), classAssignement(), className(), clean_pattern(), tree< T, tree_node_allocator >::copy_(), copy_branch(), tree< T, tree_node_allocator >::empty(), tree< T, tree_node_allocator >::equal_subtree(), exportXML(), Ast::fillAstInformation(), Ast::functionBoxing(), Ast::functionMapping(), functionReturnValue(), Ast::getLeftVariable(), getNodeIter(), getNodeValue(), Ast::getRightVariables(), Ast::getSimpleVariable(), Ast::getSubVariables(), insert_branch(), Ast::nbNestedVariables(), Ast2Php::operator()(), Ast2Cpp::operator()(), ControlFlow::operator()(), RenameVariable::operator()(), RenameFunction::operator()(), RenameClass::operator()(), NumberSunkDiffuseInputs::operator()(), NumberResources::operator()(), NumberSinks::operator()(), kptree::print_subtree_bracketed(), kptree::print_tree_bracketed(), tree< T, tree_node_allocator >::reparent(), tree< T, tree_node_allocator >::size(), Ast::skeleton(), tree< T, tree_node_allocator >::sort(), Ast::sourceBoxing(), tree< T, tree_node_allocator >::subtree(), subVarName(), writeCPP(), writeSiblingsCPP(), and writeSiblingsXML().

00646    {
00647    return pre_order_iterator(feet);
00648    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::post_order_iterator tree< T, tree_node_allocator >::begin_post (  )  const [inline]

Return post-order iterator to the beginning of the tree.

Definition at line 663 of file tree.h.

References tree< T, tree_node_allocator >::feet, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, and tree_node_< T >::next_sibling.

00664    {
00665    tree_node *tmp=head->next_sibling;
00666    if(tmp!=feet) {
00667       while(tmp->first_child)
00668          tmp=tmp->first_child;
00669       }
00670    return post_order_iterator(tmp);
00671    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::post_order_iterator tree< T, tree_node_allocator >::end_post (  )  const [inline]

Return post-order iterator to the end of the tree.

Definition at line 674 of file tree.h.

References tree< T, tree_node_allocator >::feet.

00675    {
00676    return post_order_iterator(feet);
00677    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator tree< T, tree_node_allocator >::begin_fixed ( const iterator_base pos,
unsigned int  dp 
) const [inline]

Return fixed-depth iterator to the first node at a given depth.

Definition at line 680 of file tree.h.

References tree_node_< T >::first_child, and tree_node_< T >::next_sibling.

00681    {
00682    tree_node *tmp=pos.node;
00683    unsigned int curdepth=0;
00684    while(curdepth<dp) { // go down one level
00685       while(tmp->first_child==0) {
00686          tmp=tmp->next_sibling;
00687          if(tmp==0)
00688             throw std::range_error("tree: begin_fixed out of range");
00689          }
00690       tmp=tmp->first_child;
00691       ++curdepth;
00692       }
00693    return tmp;
00694    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::fixed_depth_iterator tree< T, tree_node_allocator >::end_fixed ( const iterator_base pos,
unsigned int  dp 
) const [inline]

Return fixed-depth iterator to end of the nodes at given depth.

Definition at line 697 of file tree.h.

References tree_node_< T >::first_child, and tree_node_< T >::next_sibling.

00698    {
00699    assert(1==0); // FIXME: not correct yet
00700    tree_node *tmp=pos.node;
00701    unsigned int curdepth=1;
00702    while(curdepth<dp) { // go down one level
00703       while(tmp->first_child==0) {
00704          tmp=tmp->next_sibling;
00705          if(tmp==0)
00706             throw std::range_error("tree: end_fixed out of range");
00707          }
00708       tmp=tmp->first_child;
00709       ++curdepth;
00710       }
00711    return tmp;
00712    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::breadth_first_queued_iterator tree< T, tree_node_allocator >::begin_breadth_first (  )  const [inline]

Return breadth-first iterator to the first node at a given depth.

Definition at line 651 of file tree.h.

References tree< T, tree_node_allocator >::head, and tree_node_< T >::next_sibling.

00652    {
00653    return breadth_first_queued_iterator(head->next_sibling);
00654    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::breadth_first_queued_iterator tree< T, tree_node_allocator >::end_breadth_first (  )  const [inline]

Return breadth-first iterator to end of the nodes at given depth.

Definition at line 657 of file tree.h.

00658    {
00659    return breadth_first_queued_iterator();
00660    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::begin ( const iterator_base pos  )  const [inline]

Return sibling iterator to the first child of given node.

Definition at line 715 of file tree.h.

References tree< T, tree_node_allocator >::end().

00716    {
00717    assert(pos.node!=0);
00718    if(pos.node->first_child==0) {
00719       return end(pos);
00720       }
00721    return pos.node->first_child;
00722    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::end ( const iterator_base pos  )  const [inline]

Return sibling iterator to the end of the children of a given node.

Definition at line 725 of file tree.h.

References tree< T, tree_node_allocator >::sibling_iterator::parent_.

00726    {
00727    sibling_iterator ret(0);
00728    ret.parent_=pos.node;
00729    return ret;
00730    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::leaf_iterator tree< T, tree_node_allocator >::begin_leaf (  )  const [inline]

Return leaf iterator to the first leaf of the tree.

Definition at line 733 of file tree.h.

References tree< T, tree_node_allocator >::feet, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, and tree_node_< T >::next_sibling.

Referenced by NumberSunkDiffuseInputs::operator()(), NumberDiffuseInputs::operator()(), and NumberInput::operator()().

00734    {
00735    tree_node *tmp=head->next_sibling;
00736    if(tmp!=feet) {
00737       while(tmp->first_child)
00738          tmp=tmp->first_child;
00739       }
00740    return leaf_iterator(tmp);
00741    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::leaf_iterator tree< T, tree_node_allocator >::end_leaf (  )  const [inline]

Return leaf iterator to the last leaf of the tree.

Definition at line 744 of file tree.h.

References tree< T, tree_node_allocator >::feet.

Referenced by NumberSunkDiffuseInputs::operator()(), NumberDiffuseInputs::operator()(), and NumberInput::operator()().

00745    {
00746    return leaf_iterator(feet);
00747    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::parent ( iter  position  )  [inline, static]

Return iterator to the parent of a node.

Definition at line 751 of file tree.h.

Referenced by functionReturnValue(), insert_statement(), Ast::is_skeleton_node(), tree< T, tree_node_allocator >::merge(), ControlFlow::operator()(), RenameFunction::operator()(), RenameClass::operator()(), NumberSunkDiffuseInputs::operator()(), NumberDiffuseInputs::operator()(), NumberInput::operator()(), tree< T, tree_node_allocator >::replace(), rewind(), Ast::skeleton(), Ast::trace(), and writeSiblingsCPP().

00752    {
00753    assert(position.node!=0);
00754    return iter(position.node->parent);
00755    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::previous_sibling ( iter  position  )  const [inline]

Return iterator to the previous sibling of a node.

Definition at line 759 of file tree.h.

00760    {
00761    assert(position.node!=0);
00762    iter ret(position);
00763    ret.node=position.node->prev_sibling;
00764    return ret;
00765    }

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::next_sibling ( iter  position  )  const [inline]

Return iterator to the next sibling of a node.

Definition at line 769 of file tree.h.

00770    {
00771    assert(position.node!=0);
00772    iter ret(position);
00773    ret.node=position.node->next_sibling;
00774    return ret;
00775    }

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::next_at_same_depth ( iter  position  )  const [inline]

Return iterator to the next node at a given depth.

Definition at line 779 of file tree.h.

00780    {
00781    assert(position.node!=0);
00782    iter ret(position);
00783 
00784    if(position.node->next_sibling) {
00785       ret.node=position.node->next_sibling;
00786       }
00787    else { 
00788       int relative_depth=0;
00789       upper:
00790       do {
00791          ret.node=ret.node->parent;
00792          if(ret.node==0) return ret;
00793          --relative_depth;
00794          } while(ret.node->next_sibling==0);
00795       lower:
00796       ret.node=ret.node->next_sibling;
00797       while(ret.node->first_child==0) {
00798          if(ret.node->next_sibling==0)
00799             goto upper;
00800          ret.node=ret.node->next_sibling;
00801          if(ret.node==0) return ret;
00802          }
00803       while(relative_depth<0 && ret.node->first_child!=0) {
00804          ret.node=ret.node->first_child;
00805          ++relative_depth;
00806          }
00807       if(relative_depth<0) {
00808          if(ret.node->next_sibling==0) goto upper;
00809          else                          goto lower;
00810          }
00811       }
00812    return ret;
00813    }

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

Erase all nodes of the tree.

Definition at line 582 of file tree.h.

References tree< T, tree_node_allocator >::erase(), tree< T, tree_node_allocator >::feet, tree< T, tree_node_allocator >::head, and tree_node_< T >::next_sibling.

Referenced by tree< T, tree_node_allocator >::copy_(), and tree< T, tree_node_allocator >::~tree().

00583    {
00584    if(head)
00585       while(head->next_sibling!=feet)
00586          erase(pre_order_iterator(head->next_sibling));
00587    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::erase ( iter  it  )  [inline]

Erase element at position pointed to by iterator, return incremented iterator.

Definition at line 612 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, tree_node_< T >::data, kp::destructor(), tree< T, tree_node_allocator >::erase_children(), tree< T, tree_node_allocator >::head, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

Referenced by clean_pattern(), tree< T, tree_node_allocator >::clear(), move_branch(), tree< T, tree_node_allocator >::move_ontop(), and tree< T, tree_node_allocator >::replace().

00613    {
00614    tree_node *cur=it.node;
00615    assert(cur!=head);
00616    iter ret=it;
00617    ret.skip_children();
00618    ++ret;
00619    erase_children(it);
00620    if(cur->prev_sibling==0) {
00621       cur->parent->first_child=cur->next_sibling;
00622       }
00623    else {
00624       cur->prev_sibling->next_sibling=cur->next_sibling;
00625       }
00626    if(cur->next_sibling==0) {
00627       cur->parent->last_child=cur->prev_sibling;
00628       }
00629    else {
00630       cur->next_sibling->prev_sibling=cur->prev_sibling;
00631       }
00632 
00633    kp::destructor(&cur->data);
00634    alloc_.deallocate(cur,1);
00635    return ret;
00636    }

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 >::erase_children ( const iterator_base it  )  [inline]

Erase all children of the node pointed to by iterator.

Definition at line 590 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, tree_node_< T >::data, kp::destructor(), and tree_node_< T >::next_sibling.

Referenced by tree< T, tree_node_allocator >::erase(), and tree< T, tree_node_allocator >::replace().

00591    {
00592 // std::cout << "erase_children " << it.node << std::endl;
00593    if(it.node==0) return;
00594 
00595    tree_node *cur=it.node->first_child;
00596    tree_node *prev=0;
00597 
00598    while(cur!=0) {
00599       prev=cur;
00600       cur=cur->next_sibling;
00601       erase_children(pre_order_iterator(prev));
00602       kp::destructor(&prev->data);
00603       alloc_.deallocate(prev,1);
00604       }
00605    it.node->first_child=0;
00606    it.node->last_child=0;
00607 // std::cout << "exit" << std::endl;
00608    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::append_child ( iter  position  )  [inline]

Insert empty node as last/first child of node pointed to by position.

Definition at line 817 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

Referenced by tree< T, tree_node_allocator >::append_child(), copy_branch(), insert_branch(), insert_statement(), tree< T, tree_node_allocator >::merge(), tree< T, tree_node_allocator >::replace(), and Ast::walk().

00818    {
00819    assert(position.node!=head);
00820    assert(position.node);
00821 
00822    tree_node *tmp=alloc_.allocate(1,0);
00823    kp::constructor(&tmp->data);
00824    tmp->first_child=0;
00825    tmp->last_child=0;
00826 
00827    tmp->parent=position.node;
00828    if(position.node->last_child!=0) {
00829       position.node->last_child->next_sibling=tmp;
00830       }
00831    else {
00832       position.node->first_child=tmp;
00833       }
00834    tmp->prev_sibling=position.node->last_child;
00835    position.node->last_child=tmp;
00836    tmp->next_sibling=0;
00837    return tmp;
00838    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::prepend_child ( iter  position  )  [inline]

Definition at line 842 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

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

00843    {
00844    assert(position.node!=head);
00845    assert(position.node);
00846 
00847    tree_node *tmp=alloc_.allocate(1,0);
00848    kp::constructor(&tmp->data);
00849    tmp->first_child=0;
00850    tmp->last_child=0;
00851 
00852    tmp->parent=position.node;
00853    if(position.node->first_child!=0) {
00854       position.node->first_child->prev_sibling=tmp;
00855       }
00856    else {
00857       position.node->last_child=tmp;
00858       }
00859    tmp->next_sibling=position.node->first_child;
00860    position.node->prev_child=tmp;
00861    tmp->prev_sibling=0;
00862    return tmp;
00863    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::append_child ( iter  position,
const T &  x 
) [inline]

Insert node as last/first child of node pointed to by position.

Definition at line 867 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

00868    {
00869    // If your program fails here you probably used 'append_child' to add the top
00870    // node to an empty tree. From version 1.45 the top element should be added
00871    // using 'insert'. See the documentation for further information, and sorry about
00872    // the API change.
00873    assert(position.node!=head);
00874    assert(position.node);
00875 
00876    tree_node* tmp = alloc_.allocate(1,0);
00877    kp::constructor(&tmp->data, x);
00878    tmp->first_child=0;
00879    tmp->last_child=0;
00880 
00881    tmp->parent=position.node;
00882    if(position.node->last_child!=0) {
00883       position.node->last_child->next_sibling=tmp;
00884       }
00885    else {
00886       position.node->first_child=tmp;
00887       }
00888    tmp->prev_sibling=position.node->last_child;
00889    position.node->last_child=tmp;
00890    tmp->next_sibling=0;
00891    return tmp;
00892    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::prepend_child ( iter  position,
const T &  x 
) [inline]

Definition at line 896 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

00897    {
00898    assert(position.node!=head);
00899    assert(position.node);
00900 
00901    tree_node* tmp = alloc_.allocate(1,0);
00902    kp::constructor(&tmp->data, x);
00903    tmp->first_child=0;
00904    tmp->last_child=0;
00905 
00906    tmp->parent=position.node;
00907    if(position.node->first_child!=0) {
00908       position.node->first_child->prev_sibling=tmp;
00909       }
00910    else {
00911       position.node->last_child=tmp;
00912       }
00913    tmp->next_sibling=position.node->first_child;
00914    position.node->first_child=tmp;
00915    tmp->prev_sibling=0;
00916    return tmp;
00917    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::append_child ( iter  position,
iter  other_position 
) [inline]

Append the node (plus its children) at other_position as last/first child of position.

Definition at line 921 of file tree.h.

References tree< T, tree_node_allocator >::append_child(), tree< T, tree_node_allocator >::head, and tree< T, tree_node_allocator >::replace().

00922    {
00923    assert(position.node!=head);
00924    assert(position.node);
00925 
00926    sibling_iterator aargh=append_child(position, value_type());
00927    return replace(aargh, other);
00928    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::prepend_child ( iter  position,
iter  other_position 
) [inline]

Definition at line 932 of file tree.h.

References tree< T, tree_node_allocator >::head, tree< T, tree_node_allocator >::prepend_child(), and tree< T, tree_node_allocator >::replace().

00933    {
00934    assert(position.node!=head);
00935    assert(position.node);
00936 
00937    sibling_iterator aargh=prepend_child(position, value_type());
00938    return replace(aargh, other);
00939    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::append_children ( iter  position,
sibling_iterator  from,
sibling_iterator  to 
) [inline]

Append the nodes in the from-to range (plus their children) as last/first children of position.

Definition at line 943 of file tree.h.

References tree< T, tree_node_allocator >::head, and tree< T, tree_node_allocator >::insert_subtree().

00944    {
00945    assert(position.node!=head);
00946    assert(position.node);
00947 
00948    iter ret=from;
00949 
00950    while(from!=to) {
00951       insert_subtree(position.end(), from);
00952       ++from;
00953       }
00954    return ret;
00955    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::prepend_children ( iter  position,
sibling_iterator  from,
sibling_iterator  to 
) [inline]

Definition at line 959 of file tree.h.

References tree< T, tree_node_allocator >::head, and tree< T, tree_node_allocator >::insert_subtree().

00960    {
00961    assert(position.node!=head);
00962    assert(position.node);
00963 
00964    iter ret=from;
00965 
00966    while(from!=to) {
00967       insert_subtree(position.begin(), from);
00968       ++from;
00969       }
00970    return ret;
00971    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::pre_order_iterator tree< T, tree_node_allocator >::set_head ( const T &  x  )  [inline]

Short-hand to insert topmost node in otherwise empty tree.

Definition at line 974 of file tree.h.

References tree< T, tree_node_allocator >::feet, tree< T, tree_node_allocator >::head, tree< T, tree_node_allocator >::insert(), and tree_node_< T >::next_sibling.

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

00975    {
00976    assert(head->next_sibling==feet);
00977    return insert(iterator(feet), x);
00978    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::insert ( iter  position,
const T &  x 
) [inline]

Insert node as previous sibling of node pointed to by position.

Definition at line 982 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree< T, tree_node_allocator >::feet, tree_node_< T >::first_child, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

Referenced by tree< T, tree_node_allocator >::copy_(), tree< T, tree_node_allocator >::insert_subtree(), tree< T, tree_node_allocator >::set_head(), and tree< T, tree_node_allocator >::wrap().

00983    {
00984    if(position.node==0) {
00985       position.node=feet; // Backward compatibility: when calling insert on a null node,
00986                           // insert before the feet.
00987       }
00988    tree_node* tmp = alloc_.allocate(1,0);
00989    kp::constructor(&tmp->data, x);
00990    tmp->first_child=0;
00991    tmp->last_child=0;
00992 
00993    tmp->parent=position.node->parent;
00994    tmp->next_sibling=position.node;
00995    tmp->prev_sibling=position.node->prev_sibling;
00996    position.node->prev_sibling=tmp;
00997 
00998    if(tmp->prev_sibling==0) {
00999       if(tmp->parent) // when inserting nodes at the head, there is no parent
01000          tmp->parent->first_child=tmp;
01001       }
01002    else
01003       tmp->prev_sibling->next_sibling=tmp;
01004    return tmp;
01005    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::insert ( sibling_iterator  position,
const T &  x 
) [inline]

Specialisation of previous member.

Definition at line 1008 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree_node_< T >::first_child, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree< T, tree_node_allocator >::iterator_base::node, tree_node_< T >::parent, tree< T, tree_node_allocator >::sibling_iterator::parent_, tree_node_< T >::prev_sibling, and tree< T, tree_node_allocator >::sibling_iterator::range_last().

01009    {
01010    tree_node* tmp = alloc_.allocate(1,0);
01011    kp::constructor(&tmp->data, x);
01012    tmp->first_child=0;
01013    tmp->last_child=0;
01014 
01015    tmp->next_sibling=position.node;
01016    if(position.node==0) { // iterator points to end of a subtree
01017       tmp->parent=position.parent_;
01018       tmp->prev_sibling=position.range_last();
01019       tmp->parent->last_child=tmp;
01020       }
01021    else {
01022       tmp->parent=position.node->parent;
01023       tmp->prev_sibling=position.node->prev_sibling;
01024       position.node->prev_sibling=tmp;
01025       }
01026 
01027    if(tmp->prev_sibling==0) {
01028       if(tmp->parent) // when inserting nodes at the head, there is no parent
01029          tmp->parent->first_child=tmp;
01030       }
01031    else
01032       tmp->prev_sibling->next_sibling=tmp;
01033    return tmp;
01034    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::insert_subtree ( iter  position,
const iterator_base subtree 
) [inline]

Insert node (with children) pointed to by subtree as previous sibling of node pointed to by position.

Definition at line 1062 of file tree.h.

References tree< T, tree_node_allocator >::insert(), and tree< T, tree_node_allocator >::replace().

Referenced by tree< T, tree_node_allocator >::append_children(), tree< T, tree_node_allocator >::merge(), tree< T, tree_node_allocator >::prepend_children(), and tree< T, tree_node_allocator >::replace().

01063    {
01064    // insert dummy
01065    iter it=insert(position, value_type());
01066    // replace dummy with subtree
01067    return replace(it, subtree);
01068    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::insert_after ( iter  position,
const T &  x 
) [inline]

Insert node as next sibling of node pointed to by position.

Definition at line 1038 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, kp::constructor(), tree_node_< T >::data, tree_node_< T >::first_child, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

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

01039    {
01040    tree_node* tmp = alloc_.allocate(1,0);
01041    kp::constructor(&tmp->data, x);
01042    tmp->first_child=0;
01043    tmp->last_child=0;
01044 
01045    tmp->parent=position.node->parent;
01046    tmp->prev_sibling=position.node;
01047    tmp->next_sibling=position.node->next_sibling;
01048    position.node->next_sibling=tmp;
01049 
01050    if(tmp->next_sibling==0) {
01051       if(tmp->parent) // when inserting nodes at the head, there is no parent
01052          tmp->parent->last_child=tmp;
01053       }
01054    else {
01055       tmp->next_sibling->prev_sibling=tmp;
01056       }
01057    return tmp;
01058    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::insert_subtree_after ( iter  position,
const iterator_base subtree 
) [inline]

Insert node (with children) pointed to by subtree as next sibling of node pointed to by position.

Definition at line 1072 of file tree.h.

References tree< T, tree_node_allocator >::insert_after(), and tree< T, tree_node_allocator >::replace().

01073    {
01074    // insert dummy
01075    iter it=insert_after(position, value_type());
01076    // replace dummy with subtree
01077    return replace(it, subtree);
01078    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::replace ( iter  position,
const T &  x 
) [inline]

Replace node at 'position' with other node (keeping same children); 'position' becomes invalid.

Definition at line 1092 of file tree.h.

References kp::constructor(), and kp::destructor().

Referenced by tree< T, tree_node_allocator >::append_child(), tree< T, tree_node_allocator >::copy_(), tree< T, tree_node_allocator >::insert_subtree(), tree< T, tree_node_allocator >::insert_subtree_after(), tree< T, tree_node_allocator >::prepend_child(), tree< T, tree_node_allocator >::subtree(), and tree< T, tree_node_allocator >::tree().

01093    {
01094    kp::destructor(&position.node->data);
01095    kp::constructor(&position.node->data, x);
01096    return position;
01097    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class iter>
iter tree< T, tree_node_allocator >::replace ( iter  position,
const iterator_base from 
) [inline]

Replace node at 'position' with subtree starting at 'from' (do not erase subtree at 'from'); see above.

Definition at line 1101 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, tree< T, tree_node_allocator >::append_child(), kp::constructor(), tree_node_< T >::data, kp::destructor(), tree< T, tree_node_allocator >::erase_children(), tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree< T, tree_node_allocator >::parent(), tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

01102    {
01103    assert(position.node!=head);
01104    tree_node *current_from=from.node;
01105    tree_node *start_from=from.node;
01106    tree_node *current_to  =position.node;
01107 
01108    // replace the node at position with head of the replacement tree at from
01109 // std::cout << "warning!" << position.node << std::endl;
01110    erase_children(position);  
01111 // std::cout << "no warning!" << std::endl;
01112    tree_node* tmp = alloc_.allocate(1,0);
01113    kp::constructor(&tmp->data, (*from));
01114    tmp->first_child=0;
01115    tmp->last_child=0;
01116    if(current_to->prev_sibling==0) {
01117       if(current_to->parent!=0)
01118          current_to->parent->first_child=tmp;
01119       }
01120    else {
01121       current_to->prev_sibling->next_sibling=tmp;
01122       }
01123    tmp->prev_sibling=current_to->prev_sibling;
01124    if(current_to->next_sibling==0) {
01125       if(current_to->parent!=0)
01126          current_to->parent->last_child=tmp;
01127       }
01128    else {
01129       current_to->next_sibling->prev_sibling=tmp;
01130       }
01131    tmp->next_sibling=current_to->next_sibling;
01132    tmp->parent=current_to->parent;
01133    kp::destructor(&current_to->data);
01134    alloc_.deallocate(current_to,1);
01135    current_to=tmp;
01136    
01137    // only at this stage can we fix 'last'
01138    tree_node *last=from.node->next_sibling;
01139 
01140    pre_order_iterator toit=tmp;
01141    // copy all children
01142    do {
01143       assert(current_from!=0);
01144       if(current_from->first_child != 0) {
01145          current_from=current_from->first_child;
01146          toit=append_child(toit, current_from->data);
01147          }
01148       else {
01149          while(current_from->next_sibling==0 && current_from!=start_from) {
01150             current_from=current_from->parent;
01151             toit=parent(toit);
01152             assert(current_from!=0);
01153             }
01154          current_from=current_from->next_sibling;
01155          if(current_from!=last) {
01156             toit=append_child(parent(toit), current_from->data);
01157             }
01158          }
01159       } while(current_from!=last);
01160 
01161    return current_to;
01162    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::replace ( sibling_iterator  orig_begin,
sibling_iterator  orig_end,
sibling_iterator  new_begin,
sibling_iterator  new_end 
) [inline]

Replace string of siblings (plus their children) with copy of a new string (with children); see above.

Definition at line 1165 of file tree.h.

References tree< T, tree_node_allocator >::erase(), tree< T, tree_node_allocator >::insert_subtree(), tree_node_< T >::next_sibling, and tree< T, tree_node_allocator >::iterator_base::node.

01170    {
01171    tree_node *orig_first=orig_begin.node;
01172    tree_node *new_first=new_begin.node;
01173    tree_node *orig_last=orig_first;
01174    while((++orig_begin)!=orig_end)
01175       orig_last=orig_last->next_sibling;
01176    tree_node *new_last=new_first;
01177    while((++new_begin)!=new_end)
01178       new_last=new_last->next_sibling;
01179 
01180    // insert all siblings in new_first..new_last before orig_first
01181    bool first=true;
01182    pre_order_iterator ret;
01183    while(1==1) {
01184       pre_order_iterator tt=insert_subtree(pre_order_iterator(orig_first), pre_order_iterator(new_first));
01185       if(first) {
01186          ret=tt;
01187          first=false;
01188          }
01189       if(new_first==new_last)
01190          break;
01191       new_first=new_first->next_sibling;
01192       }
01193 
01194    // erase old range of siblings
01195    bool last=false;
01196    tree_node *next=orig_first;
01197    while(1==1) {
01198       if(next==orig_last) 
01199          last=true;
01200       next=next->next_sibling;
01201       erase((pre_order_iterator)orig_first);
01202       if(last) 
01203          break;
01204       orig_first=next;
01205       }
01206    return ret;
01207    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::flatten ( iter  position  )  [inline]

Move all children of node at 'position' to be siblings, returns position.

Definition at line 1211 of file tree.h.

References tree_node_< T >::next_sibling, and tree_node_< T >::parent.

01212    {
01213    if(position.node->first_child==0)
01214       return position;
01215 
01216    tree_node *tmp=position.node->first_child;
01217    while(tmp) {
01218       tmp->parent=position.node->parent;
01219       tmp=tmp->next_sibling;
01220       } 
01221    if(position.node->next_sibling) {
01222       position.node->last_child->next_sibling=position.node->next_sibling;
01223       position.node->next_sibling->prev_sibling=position.node->last_child;
01224       }
01225    else {
01226       position.node->parent->last_child=position.node->last_child;
01227       }
01228    position.node->next_sibling=position.node->first_child;
01229    position.node->next_sibling->prev_sibling=position.node;
01230    position.node->first_child=0;
01231    position.node->last_child=0;
01232 
01233    return position;
01234    }

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::reparent ( iter  position,
sibling_iterator  begin,
sibling_iterator  end 
) [inline]

Move nodes in range to be children of 'position'.

Definition at line 1239 of file tree.h.

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

Referenced by tree< T, tree_node_allocator >::reparent(), Ast::skeleton(), and tree< T, tree_node_allocator >::wrap().

01240    {
01241    tree_node *first=begin.node;
01242    tree_node *last=first;
01243 
01244    assert(first!=position.node);
01245    
01246    if(begin==end) return begin;
01247    // determine last node
01248    while((++begin)!=end) {
01249       last=last->next_sibling;
01250       }
01251    // move subtree
01252    if(first->prev_sibling==0) {
01253       first->parent->first_child=last->next_sibling;
01254       }
01255    else {
01256       first->prev_sibling->next_sibling=last->next_sibling;
01257       }
01258    if(last->next_sibling==0) {
01259       last->parent->last_child=first->prev_sibling;
01260       }
01261    else {
01262       last->next_sibling->prev_sibling=first->prev_sibling;
01263       }
01264    if(position.node->first_child==0) {
01265       position.node->first_child=first;
01266       position.node->last_child=last;
01267       first->prev_sibling=0;
01268       }
01269    else {
01270       position.node->last_child->next_sibling=first;
01271       first->prev_sibling=position.node->last_child;
01272       position.node->last_child=last;
01273       }
01274    last->next_sibling=0;
01275 
01276    tree_node *pos=first;
01277    while(1==1) {
01278       pos->parent=position.node;
01279       if(pos==last) break;
01280       pos=pos->next_sibling;
01281       }
01282 
01283    return first;
01284    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::reparent ( iter  position,
iter  from 
) [inline]

Move all child nodes of 'from' to be children of 'position'.

Definition at line 1287 of file tree.h.

References tree< T, tree_node_allocator >::end(), and tree< T, tree_node_allocator >::reparent().

01288    {
01289    if(from.node->first_child==0) return position;
01290    return reparent(position, from.node->first_child, end(from));
01291    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::wrap ( iter  position,
const T &  x 
) [inline]

Replace node with a new node, making the old node a child of the new node.

Definition at line 1294 of file tree.h.

References tree< T, tree_node_allocator >::insert(), and tree< T, tree_node_allocator >::reparent().

01295    {
01296    assert(position.node!=0);
01297    sibling_iterator fr=position, to=position;
01298    ++to;
01299    iter ret = insert(position, x);
01300    reparent(ret, fr, to);
01301    return ret;
01302    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::move_after ( iter  target,
iter  source 
) [inline]

Move 'source' node (plus its children) to become the next sibling of 'target'.

Definition at line 1305 of file tree.h.

References tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

01306    {
01307    tree_node *dst=target.node;
01308    tree_node *src=source.node;
01309    assert(dst);
01310    assert(src);
01311 
01312    if(dst==src) return source;
01313    if(dst->next_sibling)
01314       if(dst->next_sibling==src) // already in the right spot
01315          return source;
01316 
01317    // take src out of the tree
01318    if(src->prev_sibling!=0) src->prev_sibling->next_sibling=src->next_sibling;
01319    else                     src->parent->first_child=src->next_sibling;
01320    if(src->next_sibling!=0) src->next_sibling->prev_sibling=src->prev_sibling;
01321    else                     src->parent->last_child=src->prev_sibling;
01322 
01323    // connect it to the new point
01324    if(dst->next_sibling!=0) dst->next_sibling->prev_sibling=src;
01325    else                     dst->parent->last_child=src;
01326    src->next_sibling=dst->next_sibling;
01327    dst->next_sibling=src;
01328    src->prev_sibling=dst;
01329    src->parent=dst->parent;
01330    return src;
01331    }

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::move_before ( iter  target,
iter  source 
) [inline]

Move 'source' node (plus its children) to become the previous sibling of 'target'.

Definition at line 1334 of file tree.h.

References tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

01335    {
01336    tree_node *dst=target.node;
01337    tree_node *src=source.node;
01338    assert(dst);
01339    assert(src);
01340 
01341    if(dst==src) return source;
01342    if(dst->prev_sibling)
01343       if(dst->prev_sibling==src) // already in the right spot
01344          return source;
01345 
01346    // take src out of the tree
01347    if(src->prev_sibling!=0) src->prev_sibling->next_sibling=src->next_sibling;
01348    else                     src->parent->first_child=src->next_sibling;
01349    if(src->next_sibling!=0) src->next_sibling->prev_sibling=src->prev_sibling;
01350    else                     src->parent->last_child=src->prev_sibling;
01351 
01352    // connect it to the new point
01353    if(dst->prev_sibling!=0) dst->prev_sibling->next_sibling=src;
01354    else                     dst->parent->first_child=src;
01355    src->prev_sibling=dst->prev_sibling;
01356    dst->prev_sibling=src;
01357    src->next_sibling=dst;
01358    src->parent=dst->parent;
01359    return src;
01360    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::move_before ( sibling_iterator  target,
sibling_iterator  source 
) [inline]

Definition at line 1364 of file tree.h.

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

01366    {
01367    tree_node *dst=target.node;
01368    tree_node *src=source.node;
01369    tree_node *dst_prev_sibling;
01370    if(dst==0) { // must then be an end iterator
01371       dst_prev_sibling=target.parent_->last_child;
01372       assert(dst_prev_sibling);
01373       }
01374    else dst_prev_sibling=dst->prev_sibling;
01375    assert(src);
01376 
01377    if(dst==src) return source;
01378    if(dst_prev_sibling)
01379       if(dst_prev_sibling==src) // already in the right spot
01380          return source;
01381 
01382    // take src out of the tree
01383    if(src->prev_sibling!=0) src->prev_sibling->next_sibling=src->next_sibling;
01384    else                     src->parent->first_child=src->next_sibling;
01385    if(src->next_sibling!=0) src->next_sibling->prev_sibling=src->prev_sibling;
01386    else                     src->parent->last_child=src->prev_sibling;
01387 
01388    // connect it to the new point
01389    if(dst_prev_sibling!=0) dst_prev_sibling->next_sibling=src;
01390    else                    target.parent_->first_child=src;
01391    src->prev_sibling=dst_prev_sibling;
01392    if(dst) {
01393       dst->prev_sibling=src;
01394       src->parent=dst->parent;
01395       }
01396    src->next_sibling=dst;
01397    return src;
01398    }

template<class T, class tree_node_allocator>
template<typename iter>
iter tree< T, tree_node_allocator >::move_ontop ( iter  target,
iter  source 
) [inline]

Move 'source' node (plus its children) to become the node at 'target' (erasing the node at 'target').

Definition at line 1401 of file tree.h.

References tree< T, tree_node_allocator >::erase(), tree_node_< T >::first_child, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

01402    {
01403    tree_node *dst=target.node;
01404    tree_node *src=source.node;
01405    assert(dst);
01406    assert(src);
01407 
01408    if(dst==src) return source;
01409 
01410    // remember connection points
01411    tree_node *b_prev_sibling=dst->prev_sibling;
01412    tree_node *b_next_sibling=dst->next_sibling;
01413    tree_node *b_parent=dst->parent;
01414 
01415    // remove target
01416    erase(target);
01417 
01418    // take src out of the tree
01419    if(src->prev_sibling!=0) src->prev_sibling->next_sibling=src->next_sibling;
01420    else                     src->parent->first_child=src->next_sibling;
01421    if(src->next_sibling!=0) src->next_sibling->prev_sibling=src->prev_sibling;
01422    else                     src->parent->last_child=src->prev_sibling;
01423 
01424    // connect it to the new point
01425    if(b_prev_sibling!=0) b_prev_sibling->next_sibling=src;
01426    else                  b_parent->first_child=src;
01427    if(b_next_sibling!=0) b_next_sibling->prev_sibling=src;
01428    else                  b_parent->last_child=src;
01429    src->prev_sibling=b_prev_sibling;
01430    src->next_sibling=b_next_sibling;
01431    src->parent=b_parent;
01432    return src;
01433    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::merge ( sibling_iterator  to1,
sibling_iterator  to2,
sibling_iterator  from1,
sibling_iterator  from2,
bool  duplicate_leaves = false 
) [inline]

Merge with other tree, creating new branches and leaves only if they are not already present.

Definition at line 1436 of file tree.h.

References tree< T, tree_node_allocator >::append_child(), tree< T, tree_node_allocator >::iterator_base::begin(), tree< T, tree_node_allocator >::iterator_base::end(), tree< T, tree_node_allocator >::insert_subtree(), and tree< T, tree_node_allocator >::parent().

01439    {
01440    sibling_iterator fnd;
01441    while(from1!=from2) {
01442       if((fnd=std::find(to1, to2, (*from1))) != to2) { // element found
01443          if(from1.begin()==from1.end()) { // full depth reached
01444             if(duplicate_leaves)
01445                append_child(parent(to1), (*from1));
01446             }
01447          else { // descend further
01448             merge(fnd.begin(), fnd.end(), from1.begin(), from1.end(), duplicate_leaves);
01449             }
01450          }
01451       else { // element missing
01452          insert_subtree(to2, from1);
01453          }
01454       ++from1;
01455       }
01456    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::sort ( sibling_iterator  from,
sibling_iterator  to,
bool  deep = false 
) [inline]

Sort (std::sort only moves values of nodes, this one moves children as well).

Definition at line 1460 of file tree.h.

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

01461    {
01462    std::less<T> comp;
01463    sort(from, to, comp, deep);
01464    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<class StrictWeakOrdering>
void tree< T, tree_node_allocator >::sort ( sibling_iterator  from,
sibling_iterator  to,
StrictWeakOrdering  comp,
bool  deep = false 
) [inline]

Definition at line 1468 of file tree.h.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::end(), tree_node_< T >::next_sibling, tree< T, tree_node_allocator >::iterator_base::node, tree_node_< T >::parent, tree_node_< T >::prev_sibling, and tree< T, tree_node_allocator >::sort().

01470    {
01471    if(from==to) return;
01472    // make list of sorted nodes
01473    // CHECK: if multiset stores equivalent nodes in the order in which they
01474    // are inserted, then this routine should be called 'stable_sort'.
01475    std::multiset<tree_node *, compare_nodes<StrictWeakOrdering> > nodes(comp);
01476    sibling_iterator it=from, it2=to;
01477    while(it != to) {
01478       nodes.insert(it.node);
01479       ++it;
01480       }
01481    // reassemble
01482    --it2;
01483 
01484    // prev and next are the nodes before and after the sorted range
01485    tree_node *prev=from.node->prev_sibling;
01486    tree_node *next=it2.node->next_sibling;
01487    typename std::multiset<tree_node *, compare_nodes<StrictWeakOrdering> >::iterator nit=nodes.begin(), eit=nodes.end();
01488    if(prev==0) {
01489       if((*nit)->parent!=0) // to catch "sorting the head" situations, when there is no parent
01490          (*nit)->parent->first_child=(*nit);
01491       }
01492    else prev->next_sibling=(*nit);
01493 
01494    --eit;
01495    while(nit!=eit) {
01496       (*nit)->prev_sibling=prev;
01497       if(prev)
01498          prev->next_sibling=(*nit);
01499       prev=(*nit);
01500       ++nit;
01501       }
01502    // prev now points to the last-but-one node in the sorted range
01503    if(prev)
01504       prev->next_sibling=(*eit);
01505 
01506    // eit points to the last node in the sorted range.
01507    (*eit)->next_sibling=next;
01508    (*eit)->prev_sibling=prev; // missed in the loop above
01509    if(next==0) {
01510       if((*eit)->parent!=0) // to catch "sorting the head" situations, when there is no parent
01511          (*eit)->parent->last_child=(*eit);
01512       }
01513    else next->prev_sibling=(*eit);
01514 
01515    if(deep) {  // sort the children of each node too
01516       sibling_iterator bcs(*nodes.begin());
01517       sibling_iterator ecs(*eit);
01518       ++ecs;
01519       while(bcs!=ecs) {
01520          sort(begin(bcs), end(bcs), comp, deep);
01521          ++bcs;
01522          }
01523       }
01524    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
bool tree< T, tree_node_allocator >::equal ( const iter &  one,
const iter &  two,
const iter &  three 
) const [inline]

Compare two ranges of nodes (compares nodes as well as tree structure).

Definition at line 1528 of file tree.h.

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

01529    {
01530    std::equal_to<T> comp;
01531    return equal(one_, two, three_, comp);
01532    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
template<typename iter, class BinaryPredicate>
bool tree< T, tree_node_allocator >::equal ( const iter &  one,
const iter &  two,
const iter &  three,
BinaryPredicate  fun 
) const [inline]

Definition at line 1544 of file tree.h.

References tree< T, tree_node_allocator >::is_valid(), and tree< T, tree_node_allocator >::iterator_base::number_of_children().

01545    {
01546    pre_order_iterator one(one_), three(three_);
01547 
01548 // if(one==two && is_valid(three) && three.number_of_children()!=0)
01549 //    return false;
01550    while(one!=two && is_valid(three)) {
01551       if(!fun(*one,*three))
01552          return false;
01553       if(one.number_of_children()!=three.number_of_children()) 
01554          return false;
01555       ++one;
01556       ++three;
01557       }
01558    return true;
01559    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
template<typename iter>
bool tree< T, tree_node_allocator >::equal_subtree ( const iter &  one,
const iter &  two 
) const [inline]

Definition at line 1536 of file tree.h.

01537    {
01538    std::equal_to<T> comp;
01539    return equal_subtree(one_, two_, comp);
01540    }

template<class T, class tree_node_allocator>
template<typename iter, class BinaryPredicate>
bool tree< T, tree_node_allocator >::equal_subtree ( const iter &  one,
const iter &  two,
BinaryPredicate  fun 
) const [inline]

Definition at line 1563 of file tree.h.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::end(), tree< T, tree_node_allocator >::equal(), and tree< T, tree_node_allocator >::number_of_children().

01564    {
01565    pre_order_iterator one(one_), two(two_);
01566 
01567    if(!fun(*one,*two)) return false;
01568    if(number_of_children(one)!=number_of_children(two)) return false;
01569    return equal(begin(one),end(one),begin(two),fun);
01570    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator > tree< T, tree_node_allocator >::subtree ( sibling_iterator  from,
sibling_iterator  to 
) const [inline]

Extract a new tree formed by the range of siblings plus all their children.

Definition at line 1573 of file tree.h.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::end(), tree< T, tree_node_allocator >::replace(), and tree< T, tree_node_allocator >::set_head().

01574    {
01575    tree tmp;
01576    tmp.set_head(value_type());
01577    tmp.replace(tmp.begin(), tmp.end(), from, to);
01578    return tmp;
01579    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::subtree ( tree< T, tree_node_allocator > &  tmp,
sibling_iterator  from,
sibling_iterator  to 
) const [inline]

Definition at line 1582 of file tree.h.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::end(), tree< T, tree_node_allocator >::replace(), and tree< T, tree_node_allocator >::set_head().

01583    {
01584    tmp.set_head(value_type());
01585    tmp.replace(tmp.begin(), tmp.end(), from, to);
01586    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::swap ( sibling_iterator  it  )  [inline]

Exchange the node (plus subtree) with its sibling node (do nothing if no sibling present).

Definition at line 1675 of file tree.h.

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

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

01676    {
01677    tree_node *nxt=it.node->next_sibling;
01678    if(nxt) {
01679       if(it.node->prev_sibling)
01680          it.node->prev_sibling->next_sibling=nxt;
01681       else
01682          it.node->parent->first_child=nxt;
01683       nxt->prev_sibling=it.node->prev_sibling;
01684       tree_node *nxtnxt=nxt->next_sibling;
01685       if(nxtnxt)
01686          nxtnxt->prev_sibling=it.node;
01687       else
01688          it.node->parent->last_child=it.node;
01689       nxt->next_sibling=it.node;
01690       it.node->prev_sibling=nxt;
01691       it.node->next_sibling=nxtnxt;
01692       }
01693    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::swap ( iterator  one,
iterator  two 
) [inline]

Exchange two nodes (plus subtrees).

Definition at line 1696 of file tree.h.

References tree_node_< T >::first_child, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree< T, tree_node_allocator >::iterator_base::node, tree_node_< T >::parent, tree_node_< T >::prev_sibling, and tree< T, tree_node_allocator >::swap().

01697    {
01698    // if one and two are adjacent siblings, use the sibling swap
01699    if(one.node->next_sibling==two.node) swap(one);
01700    else if(two.node->next_sibling==one.node) swap(two);
01701    else {
01702       tree_node *nxt1=one.node->next_sibling;
01703       tree_node *nxt2=two.node->next_sibling;
01704       tree_node *pre1=one.node->prev_sibling;
01705       tree_node *pre2=two.node->prev_sibling;
01706       tree_node *par1=one.node->parent;
01707       tree_node *par2=two.node->parent;
01708 
01709       // reconnect
01710       one.node->parent=par2;
01711       one.node->next_sibling=nxt2;
01712       if(nxt2) nxt2->prev_sibling=one.node;
01713       else     par2->last_child=one.node;
01714       one.node->prev_sibling=pre2;
01715       if(pre2) pre2->next_sibling=one.node;
01716       else     par2->first_child=one.node;    
01717 
01718       two.node->parent=par1;
01719       two.node->next_sibling=nxt1;
01720       if(nxt1) nxt1->prev_sibling=two.node;
01721       else     par1->last_child=two.node;
01722       two.node->prev_sibling=pre1;
01723       if(pre1) pre1->next_sibling=two.node;
01724       else     par1->first_child=two.node;
01725       }
01726    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
int tree< T, tree_node_allocator >::size (  )  const [inline]

Count the total number of nodes.

Definition at line 1589 of file tree.h.

References tree< T, tree_node_allocator >::begin(), and tree< T, tree_node_allocator >::end().

01590    {
01591    int i=0;
01592    pre_order_iterator it=begin(), eit=end();
01593    while(it!=eit) {
01594       ++i;
01595       ++it;
01596       }
01597    return i;
01598    }

Here is the call graph for this function:

template<class T, class tree_node_allocator>
int tree< T, tree_node_allocator >::size ( const iterator_base top  )  const [inline]

Count the total number of nodes below the indicated node (plus one).

Definition at line 1601 of file tree.h.

01602    {
01603    int i=0;
01604    pre_order_iterator it=top, eit=top;
01605    eit.skip_children();
01606    ++eit;
01607    while(it!=eit) {
01608       ++i;
01609       ++it;
01610       }
01611    return i;
01612    }

template<class T, class tree_node_allocator>
bool tree< T, tree_node_allocator >::empty (  )  const [inline]

Check if tree is empty.

Definition at line 1615 of file tree.h.

References tree< T, tree_node_allocator >::begin(), and tree< T, tree_node_allocator >::end().

Referenced by exportXML(), kptree::print_subtree_bracketed(), writeCPP(), writeSiblingsCPP(), and writeSiblingsXML().

01616    {
01617    pre_order_iterator it=begin(), eit=end();
01618    return (it==eit);
01619    }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
int tree< T, tree_node_allocator >::depth ( const iterator_base it  )  const [inline]

Compute the depth to the root.

Definition at line 1622 of file tree.h.

References tree_node_< T >::parent.

01623    {
01624    tree_node* pos=it.node;
01625    assert(pos!=0);
01626    int ret=0;
01627    while(pos->parent!=0) {
01628       pos=pos->parent;
01629       ++ret;
01630       }
01631    return ret;
01632    }

template<class T, class tree_node_allocator>
unsigned int tree< T, tree_node_allocator >::number_of_children ( const iterator_base it  )  [inline, static]

Count the number of children of node at position.

Definition at line 1635 of file tree.h.

References tree_node_< T >::next_sibling.

Referenced by addClassCpp(), addFunctionCpp(), copy_branch(), Ast::detectAssignment(), tree< T, tree_node_allocator >::equal_subtree(), Ast::fillAstInformation(), functionReturnValue(), Ast::getLeftVariable(), Ast::getRightVariables(), Ast::getSimpleVariable(), Ast::getSubVariables(), insert_branch(), isAChildrenOf(), NumberSunkDiffuseInputs::operator()(), NumberDiffuseInputs::operator()(), NumberInput::operator()(), kptree::print_subtree_bracketed(), subVarName(), writeSiblingsCPP(), and writeSiblingsXML().

01636    {
01637    tree_node *pos=it.node->first_child;
01638    if(pos==0) return 0;
01639    
01640    unsigned int ret=1;
01641 //   while(pos!=it.node->last_child) {
01642 //      ++ret;
01643 //      pos=pos->next_sibling;
01644 //      }
01645    while((pos=pos->next_sibling))
01646       ++ret;
01647    return ret;
01648    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
unsigned int tree< T, tree_node_allocator >::number_of_siblings ( const iterator_base it  )  const [inline]

Count the number of 'next' siblings of node at iterator.

Definition at line 1651 of file tree.h.

References tree< T, tree_node_allocator >::feet, tree< T, tree_node_allocator >::head, tree_node_< T >::next_sibling, and tree_node_< T >::prev_sibling.

Referenced by kptree::print_tree_bracketed().

01652    {
01653    tree_node *pos=it.node;
01654    unsigned int ret=0;
01655    // count forward
01656    while(pos->next_sibling && 
01657          pos->next_sibling!=head &&
01658          pos->next_sibling!=feet) {
01659       ++ret;
01660       pos=pos->next_sibling;
01661       }
01662    // count backward
01663    pos=it.node;
01664    while(pos->prev_sibling && 
01665          pos->prev_sibling!=head &&
01666          pos->prev_sibling!=feet) {
01667       ++ret;
01668       pos=pos->prev_sibling;
01669       }
01670    
01671    return ret;
01672    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
bool tree< T, tree_node_allocator >::is_in_subtree ( const iterator_base position,
const iterator_base begin,
const iterator_base end 
) const [inline]

Determine whether node at position is in the subtrees with root in the range.

Definition at line 1743 of file tree.h.

01745    {
01746    // FIXME: this should be optimised.
01747    pre_order_iterator tmp=begin;
01748    while(tmp!=end) {
01749       if(tmp==it) return true;
01750       ++tmp;
01751       }
01752    return false;
01753    }

template<class T, class tree_node_allocator>
bool tree< T, tree_node_allocator >::is_valid ( const iterator_base it  )  const [inline]

Determine whether the iterator is an 'end' iterator and thus not actually pointing to a node.

Definition at line 1756 of file tree.h.

References tree< T, tree_node_allocator >::feet, and tree< T, tree_node_allocator >::head.

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

01757    {
01758    if(it.node==0 || it.node==feet || it.node==head) return false;
01759    else return true;
01760    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
unsigned int tree< T, tree_node_allocator >::index ( sibling_iterator  it  )  const [inline]

Determine the index of a node in the range of siblings to which it belongs.

Definition at line 1763 of file tree.h.

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

01764    {
01765    unsigned int ind=0;
01766    if(it.node->parent==0) {
01767       while(it.node->prev_sibling!=head) {
01768          it.node=it.node->prev_sibling;
01769          ++ind;
01770          }
01771       }
01772    else {
01773       while(it.node->prev_sibling!=0) {
01774          it.node=it.node->prev_sibling;
01775          ++ind;
01776          }
01777       }
01778    return ind;
01779    }

template<class T, class tree_node_allocator>
tree< T, tree_node_allocator >::sibling_iterator tree< T, tree_node_allocator >::child ( const iterator_base position,
unsigned int  num 
) const [inline]

Inverse of 'index': return the n-th child of the node at position.

Definition at line 1783 of file tree.h.

References tree_node_< T >::next_sibling.

Referenced by addClassCpp(), addFunctionCpp(), Ast::detectAssignment(), Ast::fillAstInformation(), forward(), Ast::getLeftVariable(), Ast::getRightVariables(), Ast::getSimpleVariable(), Ast::getSubVariables(), insert_statement(), isAChildrenOf(), ControlFlow::operator()(), NumberSunkDiffuseInputs::operator()(), subVarName(), and writeSiblingsCPP().

01784    {
01785    tree_node *tmp=it.node->first_child;
01786    while(num--) {
01787       assert(tmp!=0);
01788       tmp=tmp->next_sibling;
01789       }
01790    return tmp;
01791    }

Here is the caller graph for this function:

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

Definition at line 529 of file tree.h.

References tree< T, tree_node_allocator >::alloc_, tree< T, tree_node_allocator >::feet, tree_node_< T >::first_child, tree< T, tree_node_allocator >::head, tree_node_< T >::last_child, tree_node_< T >::next_sibling, tree_node_< T >::parent, and tree_node_< T >::prev_sibling.

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

00530    { 
00531    head = alloc_.allocate(1,0); // MSVC does not have default second argument 
00532    feet = alloc_.allocate(1,0);
00533 
00534    head->parent=0;
00535    head->first_child=0;
00536    head->last_child=0;
00537    head->prev_sibling=0; //head;
00538    head->next_sibling=feet; //head;
00539 
00540    feet->parent=0;
00541    feet->first_child=0;
00542    feet->last_child=0;
00543    feet->prev_sibling=head;
00544    feet->next_sibling=0;
00545    }

Here is the caller graph for this function:

template<class T, class tree_node_allocator>
void tree< T, tree_node_allocator >::copy_ ( const tree< T, tree_node_allocator > &  other  )  [inline, private]

Definition at line 561 of file tree.h.

References tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::clear(), tree< T, tree_node_allocator >::end(), tree< T, tree_node_allocator >::insert(), tree< T, tree_node_allocator >::replace(), and tree< T, tree_node_allocator >::iterator_base::skip_children().

Referenced by tree< T, tree_node_allocator >::operator=(), and tree< T, tree_node_allocator >::tree().

00562    {
00563    clear();
00564    pre_order_iterator it=other.begin(), to=begin();
00565    while(it!=other.end()) {
00566       to=insert(to, (*it));
00567       it.skip_children();
00568       ++it;
00569       }
00570    to=begin();
00571    it=other.begin();
00572    while(it!=other.end()) {
00573       to=replace(to, it);
00574       to.skip_children();
00575       it.skip_children();
00576       ++to;
00577       ++it;
00578       }
00579    }

Here is the call graph for this function:

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 >::head

Definition at line 435 of file tree.h.

Referenced by tree< T, tree_node_allocator >::append_child(), tree< T, tree_node_allocator >::append_children(), tree< T, tree_node_allocator >::begin(), tree< T, tree_node_allocator >::begin_breadth_first(), tree< T, tree_node_allocator >::begin_leaf(), tree< T, tree_node_allocator >::begin_post(), tree< T, tree_node_allocator >::clear(), tree< T, tree_node_allocator >::erase(), tree< T, tree_node_allocator >::head_initialise_(), tree< T, tree_node_allocator >::index(), tree< T, tree_node_allocator >::is_valid(), tree< T, tree_node_allocator >::number_of_siblings(), tree< T, tree_node_allocator >::prepend_child(), tree< T, tree_node_allocator >::prepend_children(), tree< T, tree_node_allocator >::replace(), tree< T, tree_node_allocator >::set_head(), and tree< T, tree_node_allocator >::~tree().

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

Definition at line 435 of file tree.h.

Referenced by tree< T, tree_node_allocator >::begin_leaf(), tree< T, tree_node_allocator >::begin_post(), tree< T, tree_node_allocator >::clear(), tree< T, tree_node_allocator >::end(), tree< T, tree_node_allocator >::end_leaf(), tree< T, tree_node_allocator >::end_post(), tree< T, tree_node_allocator >::head_initialise_(), tree< T, tree_node_allocator >::insert(), tree< T, tree_node_allocator >::is_valid(), tree< T, tree_node_allocator >::number_of_siblings(), tree< T, tree_node_allocator >::set_head(), and tree< T, tree_node_allocator >::~tree().

template<class T, class tree_node_allocator = std::allocator<tree_node_<T> >>
tree_node_allocator tree< T, tree_node_allocator >::alloc_ [private]

Definition at line 437 of file tree.h.

Referenced by tree< T, tree_node_allocator >::append_child(), tree< T, tree_node_allocator >::erase(), tree< T, tree_node_allocator >::erase_children(), tree< T, tree_node_allocator >::head_initialise_(), tree< T, tree_node_allocator >::insert(), tree< T, tree_node_allocator >::insert_after(), tree< T, tree_node_allocator >::prepend_child(), tree< T, tree_node_allocator >::replace(), and tree< T, tree_node_allocator >::~tree().


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