using std::endl;
using std::find;
using std::sort;
+using std::vector;
#else
#include <simgear/debug/logstream.hxx>
SG_USING_STD(sort);
+SG_USING_STD(find);
+SG_USING_STD(vector);
+
+#ifdef _MSC_VER
+// MSVC is buggy, and needs something strange here
+SG_USING_STD(vector<SGPropertyNode_ptr>);
+SG_USING_STD(vector<SGPropertyChangeListener *>);
+SG_USING_STD(vector<SGPropertyNode *>);
+#endif
#endif
*/
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;
SGPropertyNode_ptr node;
pos = find_child(name, index, _removedChildren);
if (pos >= 0) {
- std::vector<SGPropertyNode_ptr>::iterator it = _removedChildren.begin();
+ vector<SGPropertyNode_ptr>::iterator it = _removedChildren.begin();
it += pos;
node = _removedChildren[pos];
_removedChildren.erase(it);
SGPropertyNode_ptr ret;
int pos = find_child(name, index, _children);
if (pos >= 0) {
- std::vector<SGPropertyNode_ptr>::iterator it = _children.begin();
+ vector<SGPropertyNode_ptr>::iterator it = _children.begin();
it += pos;
SGPropertyNode_ptr node = _children[pos];
_children.erase(it);
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;
}
- return path.c_str();
+ _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());
+ }
+
+ return _path;
}
SGPropertyNode::Type
SGPropertyNode::fireValueChanged (SGPropertyNode * node)
{
if (_listeners != 0) {
- for (int i = 0; i < _listeners->size(); i++) {
+ for (unsigned int i = 0; i < _listeners->size(); i++) {
(*_listeners)[i]->valueChanged(node);
}
}
SGPropertyNode * child)
{
if (_listeners != 0) {
- for (int i = 0; i < _listeners->size(); i++) {
+ for (unsigned int i = 0; i < _listeners->size(); i++) {
(*_listeners)[i]->childAdded(parent, child);
}
}
SGPropertyNode * child)
{
if (_listeners != 0) {
- for (int i = 0; i < _listeners->size(); i++) {
+ for (unsigned int i = 0; i < _listeners->size(); i++) {
(*_listeners)[i]->childRemoved(parent, child);
}
}