Added is_descendant_of method to tree
This commit is contained in:
parent
ce37fa649d
commit
262ee3655b
1 changed files with 14 additions and 0 deletions
|
|
@ -139,6 +139,9 @@ class tree {
|
|||
void skip_children();
|
||||
/// Number of children of the node pointed to by the iterator.
|
||||
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 end() const;
|
||||
|
|
@ -2000,6 +2003,17 @@ unsigned int tree<T, tree_node_allocator>::iterator_base::number_of_children() c
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue