]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props.cxx
Modified Files:
[simgear.git] / simgear / props / props.cxx
index fe3001129f475e27b1f708933e1023ae06ec5bc4..aa37f1db2083605edab681d550a728bbace844d3 100644 (file)
@@ -116,7 +116,7 @@ parse_name (const string &path, int &i)
       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] == '_') {
@@ -295,7 +295,7 @@ find_node (SGPropertyNode * current,
   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);
   }
@@ -595,11 +595,11 @@ void
 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
 }
 
@@ -613,7 +613,7 @@ SGPropertyNode::trace_read () const
   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
 }
@@ -739,7 +739,11 @@ SGPropertyNode::SGPropertyNode (const char * name,
     _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;
 }
 
@@ -911,17 +915,18 @@ SGPropertyNode::getChildren (const char * name) const
 
 
 /**
- * Remove this node from all nodes that link to it in their path cache.
+ * Remove this node and all children from nodes that link to them
+ * in their path cache.
  */
 void
 SGPropertyNode::remove_from_path_caches ()
 {
+  for (unsigned int i = 0; i < _children.size(); ++i)
+    _children[i]->remove_from_path_caches();
+
   for (unsigned int i = 0; i < _linkedNodes.size(); i++)
     _linkedNodes[i]->erase(this);
-
   _linkedNodes.clear();
-  for (unsigned int i = 0; i < _children.size(); ++i)
-    _children[i]->remove_from_path_caches();
 }
 
 
@@ -954,7 +959,7 @@ SGPropertyNode::removeChild (int pos, bool keep)
 /**
  * Remove a child node
  */
-SGPropertyNode_ptr 
+SGPropertyNode_ptr
 SGPropertyNode::removeChild (const char * name, int index, bool keep)
 {
   SGPropertyNode_ptr ret;
@@ -2226,28 +2231,12 @@ SGPropertyNode::hash_table::bucket::get_entry (const char * key, bool create)
   }
 }
 
-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) {
-    for (++i; i < _length; i++) {
-      _entries[i-1] = _entries[i];
-    }
-     _length--;
-  }
-}
-
 bool
 SGPropertyNode::hash_table::bucket::erase (SGPropertyNode * node)
 {
   for (int i = 0; i < _length; i++) {
     if (_entries[i]->get_value() == node) {
+      delete _entries[i];
       for (++i; i < _length; i++) {
         _entries[i-1] = _entries[i];
       }
@@ -2258,6 +2247,16 @@ 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)
@@ -2266,8 +2265,12 @@ SGPropertyNode::hash_table::hash_table ()
 
 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;
 }
 
@@ -2304,24 +2307,11 @@ SGPropertyNode::hash_table::put (const char * key, SGPropertyNode * value)
   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]->get_entry(key, true)->get_value()->remove_linked_node(this);
-  _data[index]->erase(key);
-  _data[index] = 0;
-}
-
 bool
 SGPropertyNode::hash_table::erase (SGPropertyNode * node)
 {
-  for (unsigned int d = 0; d < _data_length; d++)
-    if (_data[d] && _data[d]->erase(node))
+  for (unsigned int i = 0; i < _data_length; i++)
+    if (_data[i] && _data[i]->erase(node))
       return true;
 
   return false;