Add method to copy entire properry subtree

This commit is contained in:
Richard Harrison
2017-10-15 16:54:36 +02:00
parent b57dca66be
commit 7be1fcc32e
2 changed files with 71 additions and 41 deletions
+25
View File
@@ -2443,6 +2443,7 @@ SGPropertyNode::fireValueChanged (SGPropertyNode * node)
{ {
if (_listeners != 0) { if (_listeners != 0) {
for (unsigned int i = 0; i < _listeners->size(); i++) { for (unsigned int i = 0; i < _listeners->size(); i++) {
if ((*_listeners)[i])
(*_listeners)[i]->valueChanged(node); (*_listeners)[i]->valueChanged(node);
} }
} }
@@ -2630,6 +2631,30 @@ bool compareNodeValue(const SGPropertyNode& lhs, const SGPropertyNode& rhs)
} }
} }
void SGPropertyNode::copy(SGPropertyNode *to)
{
if (nChildren())
{
for (int i = 0; i < nChildren(); i++) {
SGPropertyNode *child = getChild(i);
SGPropertyNode *to_child = to->getChild(child->getName());
if (!to_child)
to_child = to->addChild(child->getName());
if (child->nChildren())
{
child->copy(to_child);
}
else
{
to_child->setValue(child->getStringValue());
}
}
}
else
to->setValue(getStringValue());
}
bool SGPropertyNode::compare(const SGPropertyNode& lhs, bool SGPropertyNode::compare(const SGPropertyNode& lhs,
const SGPropertyNode& rhs) const SGPropertyNode& rhs)
{ {
+5
View File
@@ -1105,6 +1105,11 @@ public:
*/ */
SGPropertyNode * getNode (const char * relative_path, bool create = false); SGPropertyNode * getNode (const char * relative_path, bool create = false);
/**
* deep copy one node to another.
*/
void copy(SGPropertyNode *to);
/** /**
* Get a pointer to another node by relative path. * Get a pointer to another node by relative path.
*/ */