*/
SGPropertyNode::SGPropertyNode ()
: _name(copy_string("")),
+ _display_name(0),
_index(0),
_parent(0),
+ _path(0),
_path_cache(0),
_type(NONE),
_tied(false),
* Copy constructor.
*/
SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
- : _index(node._index),
+ : _display_name(0),
+ _index(node._index),
_parent(0), // don't copy the parent
+ _path(0),
_path_cache(0),
_type(node._type),
_tied(node._tied),
SGPropertyNode::SGPropertyNode (const char * name,
int index,
SGPropertyNode * parent)
- : _index(index),
+ : _display_name(0),
+ _index(index),
_parent(parent),
+ _path(0),
_path_cache(0),
_type(NONE),
_tied(false),
SGPropertyNode::~SGPropertyNode ()
{
delete [] _name;
+ delete [] _display_name;
+ delete [] _path;
delete _path_cache;
clear_value();
delete _listeners;
const char *
-SGPropertyNode::getPath (bool simplify) const
+SGPropertyNode::getDisplayName (bool simplify) const
{
- if (_parent == 0)
- return "";
-
- string path = _parent->getPath(simplify);
- path += '/';
- path += _name;
+ string display = _name;
if (_index != 0 || !simplify) {
- char buffer[128];
+ char buffer[64];
sprintf(buffer, "[%d]", _index);
- path += buffer;
+ display += buffer;
+ }
+ _display_name = copy_string(display.c_str());
+ return _display_name;
+}
+
+
+const char *
+SGPropertyNode::getPath (bool simplify) const
+{
+ // Calculate the complete path only once.
+ if (_path == 0) {
+ string path;
+ if (_parent == 0) {
+ path = "";
+ } else {
+ path = _parent->getPath(simplify);
+ path += '/';
+ path += getDisplayName(simplify);
+ }
+ _path = copy_string(path.c_str());
}
- strncpy(_buffer, path.c_str(), MAX_STRING_LEN);
- return _buffer;
+
+ return _path;
}
SGPropertyNode::Type