From 262ee3655bf59b2a05aed1ac03180be3cee76f51 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 24 Jan 2009 17:19:10 +0000 Subject: [PATCH] Added is_descendant_of method to tree --- src/lib/tree.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/tree.hpp b/src/lib/tree.hpp index d856e9430..f70cf30e7 100644 --- a/src/lib/tree.hpp +++ b/src/lib/tree.hpp @@ -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::iterator_base::number_of_children() c } return ret; } + +template +bool tree::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; + }