From: ehofman Date: Wed, 29 Jun 2005 09:41:07 +0000 (+0000) Subject: Melchior FRANZ: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fdd9bb1af626c02e562c63be14fc8da196c867ce;p=simgear.git Melchior FRANZ: - check for isTied() and refcount has to be made *before* we go into recursion, so as to pertain subtrees of refcounted nodes, even if there are no refcounted/tied nodes *in* this tree - return value inverted, because it's more logical to say removeChildren() == true --> everything removed; false --> failed - further cleanup --- diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index 927fdd95..6f8495c7 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -942,44 +942,39 @@ SGPropertyNode::detachChild (const char * name, int index, bool keep) /** * Remove a child node, and all children that aren't referenced. - * Returns "true" if not all nodes could be deleted. + * Returns "true" if the node and all subnodes could be removed. */ bool SGPropertyNode::removeChild (const char * name, int index) { - bool dirty = false; int pos = find_child(name, index, _children); if (pos >= 0) { vector::iterator it = _children.begin(); it += pos; SGPropertyNode *node = _children[pos]; - if (node->nChildren() && node->removeChildren()) - dirty = true; + if (node->_count != 1 || node->isTied() || !node->removeChildren()) + return false; - if (node->isTied() || node->_count != 1 || node->nChildren()) - dirty = true; - else { - if (_path_cache) - _path_cache->erase(name); // EMH - TODO: Take "index" into account! + if (_path_cache) + _path_cache->erase(name); // EMH - TODO: Take "index" into account! - node->setAttribute(REMOVED, true); - node->clearValue(); - fireChildRemoved(node); - _children.erase(it); - } + node->setAttribute(REMOVED, true); + node->clearValue(); + fireChildRemoved(node); + _children.erase(it); } - return dirty; + return true; } /** - * Remove all children nodes, or all with a given name. Returns - * "true" if not all nodes could be deleted. + * Remove all children nodes, or all with a given name. + * Returns "true" if the node and all subnodes could be removed. */ bool SGPropertyNode::removeChildren(const char *name) { - bool dirty = false; + bool success = true; vector::iterator it = _children.end(); vector::iterator begin = _children.begin(); while (it-- != begin) { @@ -987,11 +982,8 @@ SGPropertyNode::removeChildren(const char *name) if (name && !compare_strings(node->getName(), name)) continue; - if (node->nChildren() && node->removeChildren()) - dirty = true; - - if (node->isTied() || node->_count != 1 || node->nChildren()) - dirty = true; + if (node->_count != 1 || node->isTied() || !node->removeChildren()) + success = false; else { if (_path_cache) _path_cache->erase(node->getName()); @@ -1002,7 +994,7 @@ SGPropertyNode::removeChildren(const char *name) _children.erase(it); } } - return dirty; + return success; } diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index 9a3e4a7e..092fc224 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -714,14 +714,16 @@ public: /** - * Remove a child node. Returns "true" if at least one node had to remain, - * because it was tied, aliased, or refcounted through SGPropertyNode_ptr. + * Remove a child node. Returns "true" if the node and all subnodes could + * be removed, and "false" if at least one node had to remain, because it + * was tied, aliased, or refcounted through SGPropertyNode_ptr. */ bool removeChild (const char * name, int index = 0); /** - * Remove all children nodes, or all with a given name. + * Remove all children nodes, or all with a given name. True if all nodes + * were removed. */ bool removeChildren(const char * name = 0);