Added new getDisplayName method that gets the name with its index.
Suggested by Julian Foad.
This commit is contained in:
+21
-7
@@ -633,6 +633,7 @@ const int SGPropertyNode::LAST_USED_ATTRIBUTE = TRACE_WRITE;
|
|||||||
*/
|
*/
|
||||||
SGPropertyNode::SGPropertyNode ()
|
SGPropertyNode::SGPropertyNode ()
|
||||||
: _name(copy_string("")),
|
: _name(copy_string("")),
|
||||||
|
_display_name(0),
|
||||||
_index(0),
|
_index(0),
|
||||||
_parent(0),
|
_parent(0),
|
||||||
_path(0),
|
_path(0),
|
||||||
@@ -652,6 +653,7 @@ SGPropertyNode::SGPropertyNode ()
|
|||||||
*/
|
*/
|
||||||
SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
|
SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
|
||||||
: _index(node._index),
|
: _index(node._index),
|
||||||
|
_display_name(0),
|
||||||
_parent(0), // don't copy the parent
|
_parent(0), // don't copy the parent
|
||||||
_path(0),
|
_path(0),
|
||||||
_path_cache(0),
|
_path_cache(0),
|
||||||
@@ -735,7 +737,8 @@ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
|
|||||||
SGPropertyNode::SGPropertyNode (const char * name,
|
SGPropertyNode::SGPropertyNode (const char * name,
|
||||||
int index,
|
int index,
|
||||||
SGPropertyNode * parent)
|
SGPropertyNode * parent)
|
||||||
: _index(index),
|
: _display_name(0),
|
||||||
|
_index(index),
|
||||||
_parent(parent),
|
_parent(parent),
|
||||||
_path(0),
|
_path(0),
|
||||||
_path_cache(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 *
|
const char *
|
||||||
SGPropertyNode::getPath (bool simplify) const
|
SGPropertyNode::getPath (bool simplify) const
|
||||||
{
|
{
|
||||||
@@ -942,12 +961,7 @@ SGPropertyNode::getPath (bool simplify) const
|
|||||||
} else {
|
} else {
|
||||||
path = _parent->getPath(simplify);
|
path = _parent->getPath(simplify);
|
||||||
path += '/';
|
path += '/';
|
||||||
path += _name;
|
path += getDisplayName(simplify);
|
||||||
if (_index != 0 || !simplify) {
|
|
||||||
char buffer[64];
|
|
||||||
sprintf(buffer, "[%d]", _index);
|
|
||||||
path += buffer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_path = copy_string(path.c_str());
|
_path = copy_string(path.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -633,6 +633,12 @@ public:
|
|||||||
const char * getName () const { return _name; }
|
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.
|
* Get the node's integer index.
|
||||||
*/
|
*/
|
||||||
@@ -1241,6 +1247,7 @@ private:
|
|||||||
class hash_table;
|
class hash_table;
|
||||||
|
|
||||||
char * _name;
|
char * _name;
|
||||||
|
mutable char * _display_name;
|
||||||
int _index;
|
int _index;
|
||||||
SGPropertyNode * _parent;
|
SGPropertyNode * _parent;
|
||||||
vector<SGPropertyNode_ptr> _children;
|
vector<SGPropertyNode_ptr> _children;
|
||||||
|
|||||||
Reference in New Issue
Block a user