From d1aa5a0b8241682fc3281335ea79f09576fe10cb Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Mon, 14 Sep 2020 00:05:07 +0100 Subject: [PATCH] simgear/props/props.*: added method to add exising SGPropertyNode_ptr as child. Avoids the need to create a new child and copy recursively. --- simgear/props/props.cxx | 14 ++++++++++++++ simgear/props/props.hxx | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index ec77d895..3bf7ace8 100755 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -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 */ diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index 08216a23..f3a9db96 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -925,6 +925,16 @@ public: int min_index = 0, 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