From: Mukund Sivaraman Date: Mon, 26 Aug 2013 01:25:58 +0000 (+0530) Subject: [2750] Add non-const variant of getSubTreeRoot() X-Git-Tag: bind10-1.2.0beta1-release~193^2~4^2~76 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ee0490dae879424b7e20fe1994ae4f2b294e3ef;p=thirdparty%2Fkea.git [2750] Add non-const variant of getSubTreeRoot() --- diff --git a/src/lib/datasrc/memory/domaintree.h b/src/lib/datasrc/memory/domaintree.h index 5f41371903..547d261d0d 100644 --- a/src/lib/datasrc/memory/domaintree.h +++ b/src/lib/datasrc/memory/domaintree.h @@ -393,11 +393,20 @@ private: return ((flags_ & FLAG_SUBTREE_ROOT) != 0); } + /// \brief Static helper function used by const and non-const + /// variants of getSubTreeRoot() + template + static TT* + getSubTreeRootImpl(TT* node); + /// \brief returns the root of its subtree /// /// This method takes a node and returns the root of its subtree. /// /// This method never throws an exception. + DomainTreeNode* getSubTreeRoot(); + + /// \brief returns the root of its subtree (const variant) const DomainTreeNode* getSubTreeRoot() const; public: @@ -610,17 +619,30 @@ DomainTreeNode::~DomainTreeNode() { } template -const DomainTreeNode* -DomainTreeNode::getSubTreeRoot() const { - const DomainTreeNode* current = this; - - // current would never be equal to NULL here (in a correct tree +template +TT* +DomainTreeNode::getSubTreeRootImpl(TT* node) { + // node would never be equal to NULL here (in a correct tree // implementation) - while (!current->isSubTreeRoot()) { - current = current->getParent(); + assert(node != NULL); + + while (!node->isSubTreeRoot()) { + node = node->getParent(); } - return (current); + return (node); +} + +template +DomainTreeNode* +DomainTreeNode::getSubTreeRoot() { + return (getSubTreeRootImpl >(this)); +} + +template +const DomainTreeNode* +DomainTreeNode::getSubTreeRoot() const { + return (getSubTreeRootImpl >(this)); } template