#include "props.hxx"
#include <algorithm>
+
#include <sstream>
#include <stdio.h>
#include <string.h>
#if PROPS_STANDALONE
-
#include <iostream>
-using std::cerr;
-using std::endl;
-using std::find;
-using std::sort;
-using std::vector;
-using std::stringstream;
-
#else
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
-SG_USING_STD(sort);
-SG_USING_STD(find);
-SG_USING_STD(vector);
-SG_USING_STD(stringstream);
-
#if ( _MSC_VER == 1200 )
// MSVC 6 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
+#if PROPS_STANDALONE
+using std::cerr;
#endif
+using std::endl;
+using std::find;
+using std::sort;
+using std::string;
+using std::vector;
+using std::stringstream;
\f
name = ".";
}
if (i < max && path[i] != '/')
- throw string("Illegal character after " + name);
+ throw string("illegal character after " + name);
}
else if (isalpha(path[i]) || path[i] == '_') {
else if (components[position].name == "..") {
SGPropertyNode * parent = current->getParent();
if (parent == 0)
- throw string("Attempt to move past root with '..'");
+ throw string("attempt to move past root with '..'");
else
return find_node(parent, components, position + 1, create);
}
SGPropertyNode::trace_write () const
{
#if PROPS_STANDALONE
- cerr << "TRACE: Write node " << getPath () << ", value\""
+ cerr << "TRACE: Write node " << getPath () << ", value \""
<< make_string() << '"' << endl;
#else
- SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Write node " << getPath()
- << ", value\"" << make_string() << '"');
+ SG_LOG(SG_GENERAL, SG_ALERT, "TRACE: Write node " << getPath()
+ << ", value \"" << make_string() << '"');
#endif
}
cerr << "TRACE: Write node " << getPath () << ", value \""
<< make_string() << '"' << endl;
#else
- SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Read node " << getPath()
+ SG_LOG(SG_GENERAL, SG_ALERT, "TRACE: Read node " << getPath()
<< ", value \"" << make_string() << '"');
#endif
}
* Last used attribute
* Update as needed when enum Attribute is changed
*/
-const int SGPropertyNode::LAST_USED_ATTRIBUTE = TRACE_WRITE;
+const int SGPropertyNode::LAST_USED_ATTRIBUTE = USERARCHIVE;
/**
* Default constructor: always creates a root node.
_attr(READ|WRITE),
_listeners(0)
{
- _name = name;
+ int i = 0;
+ _name = parse_name(name, i);
+ if (i != int(strlen(name)) || name[0] == '.')
+ throw string("plain name expected instead of '") + name + '\'';
+
_local_val.string_val = 0;
}
}
}
-void
-SGPropertyNode::hash_table::bucket::erase (const char * key)
-{
- int i;
- for (i = 0; i < _length; i++) {
- if (!strcmp(_entries[i]->get_key(), key))
- break;
- }
-
- if (i < _length) {
- delete _entries[i];
- for (++i; i < _length; i++) {
- _entries[i-1] = _entries[i];
- }
- _length--;
- }
-}
-
bool
SGPropertyNode::hash_table::bucket::erase (SGPropertyNode * node)
{
return false;
}
+void
+SGPropertyNode::hash_table::bucket::clear (SGPropertyNode::hash_table * owner)
+{
+ for (int i = 0; i < _length; i++) {
+ SGPropertyNode * node = _entries[i]->get_value();
+ if (node)
+ node->remove_linked_node(owner);
+ }
+}
+
SGPropertyNode::hash_table::hash_table ()
: _data_length(0),
_data(0)
SGPropertyNode::hash_table::~hash_table ()
{
- for (unsigned int i = 0; i < _data_length; i++)
- delete _data[i];
+ for (unsigned int i = 0; i < _data_length; i++) {
+ if (_data[i]) {
+ _data[i]->clear(this);
+ delete _data[i];
+ }
+ }
delete [] _data;
}
value->add_linked_node(this);
}
-void
-SGPropertyNode::hash_table::erase (const char * key)
-{
- if (_data_length == 0)
- return;
- unsigned int index = hashcode(key) % _data_length;
- if (_data[index] == 0)
- return;
- _data[index]->erase(key);
-}
-
bool
SGPropertyNode::hash_table::erase (SGPropertyNode * node)
{