Added is_descendant_of method to tree

This commit is contained in:
Joel Holdsworth 2009-01-24 17:19:10 +00:00
parent ce37fa649d
commit 262ee3655b

View file

@ -139,6 +139,9 @@ class tree {
void skip_children(); void skip_children();
/// Number of children of the node pointed to by the iterator. /// Number of children of the node pointed to by the iterator.
unsigned int number_of_children() const; unsigned int number_of_children() const;
/// Determines if the node pointed to by the iterator is a descendant of
/// another node pointed to by another iterator
bool is_descendant_of(iterator_base parent) const;
sibling_iterator begin() const; sibling_iterator begin() const;
sibling_iterator end() const; sibling_iterator end() const;
@ -2001,6 +2004,17 @@ unsigned int tree<T, tree_node_allocator>::iterator_base::number_of_children() c
return ret; return ret;
} }
template <class T, class tree_node_allocator>
bool tree<T, tree_node_allocator>::iterator_base::is_descendant_of(iterator_base parent) const
{
tree_node node = this->node;
while(node != NULL) {
if(node == parent->node) return true;
node = node->parent;
}
return false;
}
// Pre-order iterator // Pre-order iterator