*/
SGPropertyNode::SGPropertyNode ()
: _name(copy_string("")),
+ _display_name(0),
_index(0),
_parent(0),
_path(0),
*/
SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
: _index(node._index),
+ _display_name(0),
_parent(0), // don't copy the parent
_path(0),
_path_cache(0),
SGPropertyNode::SGPropertyNode (const char * name,
int index,
SGPropertyNode * parent)
- : _index(index),
+ : _display_name(0),
+ _index(index),
_parent(parent),
_path(0),
_path_cache(0),
}
+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
{
} 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());
}
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.
*/
class hash_table;
char * _name;
+ mutable char * _display_name;
int _index;
SGPropertyNode * _parent;
vector<SGPropertyNode_ptr> _children;