simgear/props/props.*: added method to add exising SGPropertyNode_ptr as child.

Avoids the need to create a new child and copy recursively.
This commit is contained in:
Julian Smith 2020-09-14 00:05:07 +01:00
parent 42c89ba6d3
commit d1aa5a0b82
2 changed files with 24 additions and 0 deletions

View File

@ -1098,6 +1098,20 @@ SGPropertyNode::addChild(const char * name, int min_index, bool append)
return node;
}
SGPropertyNode_ptr SGPropertyNode::addChild(SGPropertyNode_ptr node, const std::string& name,
int min_index, bool append)
{
int pos = append
? std::max(find_last_child(name.c_str(), _children) + 1, min_index)
: first_unused_index(name.c_str(), _children, min_index);
node->_name = name;
node->_parent = this;
node->_index = pos;
_children.push_back(node);
fireChildAdded(node);
return node;
}
/**
* Create multiple children with unused indices
*/

View File

@ -926,6 +926,16 @@ public:
bool append = true )
{ return addChild(name.c_str(), min_index, append); }
/**
* Add existing node as child.
*
* @param min_index Minimal index for new node (skips lower indices)
* @param append Whether to simply use the index after the last used index
* or use a lower, unused index if it exists
*/
SGPropertyNode_ptr addChild(SGPropertyNode_ptr node, const std::string& name,
int min_index=0, bool append=true);
/**
* Create multiple child nodes with the given name an unused indices
*