]> git.mxchange.org Git - simgear.git/commitdiff
Melchior FRANZ:
authorehofman <ehofman>
Sun, 23 Oct 2005 11:55:48 +0000 (11:55 +0000)
committerehofman <ehofman>
Sun, 23 Oct 2005 11:55:48 +0000 (11:55 +0000)
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.)

simgear/props/props.cxx
simgear/props/props.hxx

index e7dac3f4bf7dac0e3e13bf2b82a0a7dba5f0929b..dc7ccd6b31e1bf2c8e1acd501bbe8b7e69de201a 100644 (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
 {
index deb4f14d3d9394b2b5cd56e48889be229759d176..cea6d639379eb4fcd69716b7d1ad8032ee71019e 100644 (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.