From c522e499b252da2e7e9c82eff02d9da31690d3f7 Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 25 May 2009 11:12:24 +0000 Subject: [PATCH] find the last index instead of the last pos for addChild --- simgear/props/props.cxx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index 83b586c0..cd239ca3 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -264,20 +264,23 @@ find_child (const char * name, int index, const vector& node } /** - * Locate the last child node with a given name. -*/ + * Locate the child node with the highest index of the same name + */ static int find_last_child (const char * name, const vector& nodes) { int nNodes = nodes.size(); - int pos = -1; + int index = 0; for (int i = 0; i < nNodes; i++) { SGPropertyNode * node = nodes[i]; if (compare_strings(node->getName(), name)) - pos++; + { + int idx = node->getIndex(); + if (idx > index) index = idx; + } } - return pos; + return index; } @@ -852,10 +855,10 @@ SGPropertyNode::getAliasTarget () const SGPropertyNode * SGPropertyNode::addChild (const char * name) { - int pos = find_last_child(name, _children); + int pos = find_last_child(name, _children)+1; SGPropertyNode_ptr node; - node = new SGPropertyNode(name, ++pos, this); + node = new SGPropertyNode(name, pos, this); _children.push_back(node); fireChildAdded(node); return node; -- 2.39.5