Melchior FRANZ:

The attached patch makes remove_child() available as removeChild(pos, keep).
That's consistent with getChild. Only renamed remove_child to removeChild and
added a check for validity of the pos argument.

removeChildren() will be used in input.cxx, and a lot in the upcoming
dynamic new_gui dialogs, which are aiming at replacing the hard-coded
dialogs. I'll discuss them on the list once the infrastructure is
in place. (The <hide> gui property was one part of it.)
This commit is contained in:
ehofman
2005-10-23 11:55:48 +00:00
parent f58d81b1e9
commit debd066edd
2 changed files with 57 additions and 15 deletions

View File

@@ -911,6 +911,32 @@ SGPropertyNode::getChildren (const char * name) const
}
/**
* Revove child by position.
*/
SGPropertyNode_ptr
SGPropertyNode::removeChild (int pos, bool keep)
{
SGPropertyNode_ptr node;
if (pos < 0 || pos > _children.size() - 1)
return node;
vector<SGPropertyNode_ptr>::iterator it = _children.begin();
it += pos;
node = _children[pos];
_children.erase(it);
if (keep) {
_removedChildren.push_back(node);
}
if (_path_cache)
_path_cache->erase(node->getName()); // EMH - TODO: Take "index" into account!
node->setAttribute(REMOVED, true);
node->clearValue();
fireChildRemoved(node);
return node;
}
/**
* Remove a child node
*/
@@ -919,25 +945,29 @@ SGPropertyNode::removeChild (const char * name, int index, bool keep)
{
SGPropertyNode_ptr ret;
int pos = find_child(name, index, _children);
if (pos >= 0) {
vector<SGPropertyNode_ptr>::iterator it = _children.begin();
it += pos;
SGPropertyNode_ptr node = _children[pos];
_children.erase(it);
if (keep) {
_removedChildren.push_back(node);
}
if (_path_cache)
_path_cache->erase(name); // EMH - TODO: Take "index" into account!
node->setAttribute(REMOVED, true);
node->clearValue();
ret = node;
fireChildRemoved(node);
}
if (pos >= 0)
ret = removeChild(pos, keep);
return ret;
}
/**
* Remove all children with the specified name.
*/
vector<SGPropertyNode_ptr>
SGPropertyNode::removeChildren (const char * name, bool keep)
{
vector<SGPropertyNode_ptr> children;
for (int pos = _children.size() - 1; pos >= 0; pos--)
if (compare_strings(_children[pos]->getName(), name))
children.push_back(removeChild(pos, keep));
sort(children.begin(), children.end(), CompareIndices());
return children;
}
const char *
SGPropertyNode::getDisplayName (bool simplify) const
{

View File

@@ -706,12 +706,24 @@ public:
vector<SGPropertyNode_ptr> getChildren (const char * name) const;
/**
* Remove child by position.
*/
SGPropertyNode_ptr removeChild (int pos, bool keep = true);
/**
* Remove a child node
*/
SGPropertyNode_ptr removeChild (const char * name, int index = 0,
bool keep = true);
/**
* Remove all children with the specified name.
*/
vector<SGPropertyNode_ptr> removeChildren (const char * name,
bool keep = true);
//
// Alias support.