/**
- * 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();
}
/**
* Remove a child node
*/
-SGPropertyNode_ptr
+SGPropertyNode_ptr
SGPropertyNode::removeChild (const char * name, int index, bool keep)
{
SGPropertyNode_ptr ret;
}
}
-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];
}
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]->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;