From fc4009aa505702241a1b79c710c4358e686245b9 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Fri, 18 Dec 2009 07:14:16 +0100 Subject: [PATCH] change return value of SGPropertyNode::getPath to std::string Also get rid of the cached value. --- simgear/props/props.cxx | 21 +++++++++++++-------- simgear/props/props.hxx | 3 +-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index c662eb7f..acbcc92d 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -1027,17 +1027,22 @@ SGPropertyNode::getDisplayName (bool simplify) const } -const char * +string SGPropertyNode::getPath (bool simplify) const { - // Calculate the complete path only once. - if (_parent != 0 && _path.empty()) { - _path = _parent->getPath(simplify); - _path += '/'; - _path += getDisplayName(simplify); + typedef std::vector PList; + PList pathList; + for (const SGPropertyNode* node = this; node->_parent; node = node->_parent) + pathList.push_back(node); + string result; + for (PList::reverse_iterator itr = pathList.rbegin(), + rend = pathList.rend(); + itr != rend; + ++itr) { + result += '/'; + result += (*itr)->getDisplayName(simplify); } - - return _path.c_str(); + return result; } props::Type diff --git a/simgear/props/props.hxx b/simgear/props/props.hxx index 984bb1b5..b9ba6495 100644 --- a/simgear/props/props.hxx +++ b/simgear/props/props.hxx @@ -994,7 +994,7 @@ public: /** * Get the path to this node from the root. */ - const char * getPath (bool simplify = false) const; + std::string getPath (bool simplify = false) const; /** @@ -1675,7 +1675,6 @@ private: simgear::PropertyList _children; simgear::PropertyList _removedChildren; std::vector _linkedNodes; - mutable std::string _path; mutable std::string _buffer; hash_table * _path_cache; simgear::props::Type _type; -- 2.39.5