From: david Date: Sat, 6 Jul 2002 14:58:38 +0000 (+0000) Subject: Added new getDisplayName method that gets the name with its index. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=767b74dd357b3af09f366f907607679bae962916;p=simgear.git Added new getDisplayName method that gets the name with its index. Suggested by Julian Foad. --- diff --git a/simgear/misc/props.cxx b/simgear/misc/props.cxx index 7da884a7..392b456e 100644 --- a/simgear/misc/props.cxx +++ b/simgear/misc/props.cxx @@ -633,6 +633,7 @@ const int SGPropertyNode::LAST_USED_ATTRIBUTE = TRACE_WRITE; */ SGPropertyNode::SGPropertyNode () : _name(copy_string("")), + _display_name(0), _index(0), _parent(0), _path(0), @@ -652,6 +653,7 @@ SGPropertyNode::SGPropertyNode () */ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node) : _index(node._index), + _display_name(0), _parent(0), // don't copy the parent _path(0), _path_cache(0), @@ -735,7 +737,8 @@ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node) SGPropertyNode::SGPropertyNode (const char * name, int index, SGPropertyNode * parent) - : _index(index), + : _display_name(0), + _index(index), _parent(parent), _path(0), _path_cache(0), @@ -931,6 +934,22 @@ SGPropertyNode::removeChild (const char * name, int index, bool keep) } +const char * +SGPropertyNode::getDisplayName (bool simplify) const +{ + if (_display_name == 0) { + string display = _name; + if (_index != 0 || !simplify) { + char buffer[64]; + sprintf(buffer, "[%d]", _index); + display += buffer; + } + _display_name = copy_string(display.c_str()); + } + return _display_name; +} + + const char * SGPropertyNode::getPath (bool simplify) const { @@ -942,12 +961,7 @@ SGPropertyNode::getPath (bool simplify) const } else { path = _parent->getPath(simplify); path += '/'; - path += _name; - if (_index != 0 || !simplify) { - char buffer[64]; - sprintf(buffer, "[%d]", _index); - path += buffer; - } + path += getDisplayName(simplify); } _path = copy_string(path.c_str()); } diff --git a/simgear/misc/props.hxx b/simgear/misc/props.hxx index ca61a2f2..c22d3036 100644 --- a/simgear/misc/props.hxx +++ b/simgear/misc/props.hxx @@ -633,6 +633,12 @@ public: const char * getName () const { return _name; } + /** + * Get the node's pretty display name, with subscript when needed. + */ + const char * getDisplayName (bool simplify = false) const; + + /** * Get the node's integer index. */ @@ -1241,6 +1247,7 @@ private: class hash_table; char * _name; + mutable char * _display_name; int _index; SGPropertyNode * _parent; vector _children;