]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props.cxx
Revert to c++98
[simgear.git] / simgear / props / props.cxx
index c662eb7f95f808ab54af4f33b4453c08c015063e..da3c482a41dca349dc1756b1b23b89dad11ab5ab 100644 (file)
 #include "props.hxx"
 
 #include <algorithm>
+#include <limits>
 
+#include <set>
 #include <sstream>
 #include <iomanip>
 #include <iterator>
 #include <stdio.h>
 #include <string.h>
 
-#include <boost/algorithm/string/find_iterator.hpp>
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/bind.hpp>
-#include <boost/functional/hash.hpp>
-#include <boost/range.hpp>
-
-#include <simgear/math/SGMath.hxx>
-
 #if PROPS_STANDALONE
-#include <iostream>
+# include <iostream>
+using std::cerr;
 #else
-
-#include <simgear/compiler.h>
-#include <simgear/debug/logstream.hxx>
-
-#if ( _MSC_VER == 1200 )
+# include <boost/algorithm/string/find_iterator.hpp>
+# include <boost/algorithm/string/predicate.hpp>
+# include <boost/algorithm/string/classification.hpp>
+# include <boost/bind.hpp>
+# include <boost/functional/hash.hpp>
+# include <boost/range.hpp>
+# include <simgear/compiler.h>
+# include <simgear/debug/logstream.hxx>
+
+# include "PropertyInterpolationMgr.hxx"
+# include "vectorPropTemplates.hxx"
+
+# if ( _MSC_VER == 1200 )
 // MSVC 6 is buggy, and needs something strange here
 using std::vector<SGPropertyNode_ptr>;
 using std::vector<SGPropertyChangeListener *>;
 using std::vector<SGPropertyNode *>;
-#endif
+# 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;
 
 using namespace simgear;
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Local classes.
 ////////////////////////////////////////////////////////////////////////
@@ -73,19 +70,25 @@ public:
 };
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Convenience macros for value access.
 ////////////////////////////////////////////////////////////////////////
 
 #define TEST_READ(dflt) if (!getAttribute(READ)) return dflt
 #define TEST_WRITE if (!getAttribute(WRITE)) return false
-\f
 
 ////////////////////////////////////////////////////////////////////////
 // Local path normalization code.
 ////////////////////////////////////////////////////////////////////////
 
+#if PROPS_STANDALONE
+struct PathComponent
+{
+  string name;
+  int index;
+};
+#endif
+
 /**
  * Parse the name for a path component.
  *
@@ -94,7 +97,7 @@ public:
 
 template<typename Range>
 inline Range
-parse_name (const Range &path)
+parse_name (const SGPropertyNode *node, const Range &path)
 {
   typename Range::iterator i = path.begin();
   typename Range::iterator max = path.end();
@@ -105,7 +108,7 @@ parse_name (const Range &path)
       i++;
     }
     if (i != max && *i != '/')
-      throw string("illegal character after . or ..");
+      throw std::string("illegal character after . or ..");
   } else if (isalpha(*i) || *i == '_') {
     i++;
 
@@ -118,32 +121,179 @@ parse_name (const Range &path)
       } else if (*i == '[' || *i == '/') {
        break;
       } else {
-       throw string("name may contain only ._- and alphanumeric characters");
+        std::string err = "'";
+        err.push_back(*i);
+        err.append("' found in propertyname after '"+node->getNameString()+"'");
+        err.append("\nname may contain only ._- and alphanumeric characters");
+       throw err;
       }
       i++;
     }
   }
 
   else {
-    if (path.begin() == i)
-      throw string("name must begin with alpha or '_'");
+    if (path.begin() == i) {
+      std::string err = "'";
+      err.push_back(*i);
+      err.append("' found in propertyname after '"+node->getNameString()+"'");
+      err.append("\nname must begin with alpha or '_'");
+      throw err;
+    }
   }
   return Range(path.begin(), i);
 }
 
 // Validate the name of a single node
-inline bool validateName(const string& name)
+inline bool validateName(const std::string& name)
 {
   using namespace boost;
   if (name.empty())
     return false;
   if (!isalpha(name[0]) && name[0] != '_')
     return false;
+#if PROPS_STANDALONE
+  std::string is_any_of("_-.");
+  bool rv = true;
+  for(unsigned i=1; i<name.length(); ++i) {
+    if (!isalnum(name[i]) && is_any_of.find(name[i]) == std::string::npos)  {
+      rv = false;
+      break;
+    }
+  }
+  return rv;
+#else
   return all(make_iterator_range(name.begin(), name.end()),
              is_alnum() || is_any_of("_-."));
+#endif
+}
+
+#if PROPS_STANDALONE
+/**
+ * Parse the name for a path component.
+ *
+ * Name: [_a-zA-Z][-._a-zA-Z0-9]*
+ */
+static inline const string
+parse_name (const string &path, int &i)
+{
+  string name = "";
+  int max = (int)path.size();
+
+  if (path[i] == '.') {
+    i++;
+    if (i < max && path[i] == '.') {
+      i++;
+      name = "..";
+    } else {
+      name = ".";
+    }
+    if (i < max && path[i] != '/')
+      throw string("Illegal character after " + name);
+  }
+
+  else if (isalpha(path[i]) || path[i] == '_') {
+    name += path[i];
+    i++;
+
+             // The rules inside a name are a little
+             // less restrictive.
+    while (i < max) {
+      if (isalpha(path[i]) || isdigit(path[i]) || path[i] == '_' ||
+      path[i] == '-' || path[i] == '.') {
+        name += path[i];
+      } else if (path[i] == '[' || path[i] == '/') {
+        break;
+      } else {
+        throw string("name may contain only ._- and alphanumeric characters");
+      }
+      i++;
+    }
+  }
+
+  else {
+    if (name.size() == 0)
+      throw string("name must begin with alpha or '_'");
+  }
+
+  return name;
+}
+
+
+/**
+ * Parse the optional integer index for a path component.
+ *
+ * Index: "[" [0-9]+ "]"
+ */
+static inline int
+parse_index (const string &path, int &i)
+{
+  int index = 0;
+
+  if (path[i] != '[')
+    return 0;
+  else
+    i++;
+
+  for (int max = (int)path.size(); i < max; i++) {
+    if (isdigit(path[i])) {
+      index = (index * 10) + (path[i] - '0');
+    } else if (path[i] == ']') {
+      i++;
+      return index;
+    } else {
+      break;
+    }
+  }
+
+  throw string("unterminated index (looking for ']')");
 }
 
-\f
+/**
+ * Parse a single path component.
+ *
+ * Component: Name Index?
+ */
+static inline PathComponent
+parse_component (const string &path, int &i)
+{
+  PathComponent component;
+  component.name = parse_name(path, i);
+  if (component.name[0] != '.')
+    component.index = parse_index(path, i);
+  else
+    component.index = -1;
+  return component;
+}
+
+/**
+ * Parse a path into its components.
+ */
+static void
+parse_path (const string &path, vector<PathComponent> &components)
+{
+  int pos = 0;
+  int max = (int)path.size();
+
+  // Check for initial '/'
+  if (path[pos] == '/') {
+    PathComponent root;
+    root.name = "";
+    root.index = -1;
+    components.push_back(root);
+    pos++;
+    while (pos < max && path[pos] == '/')
+      pos++;
+  }
+
+  while (pos < max) {
+    components.push_back(parse_component(path, pos));
+    while (pos < max && path[pos] == '/')
+      pos++;
+  }
+}
+#endif
+
+
 ////////////////////////////////////////////////////////////////////////
 // Other static utility functions.
 ////////////////////////////////////////////////////////////////////////
@@ -152,7 +302,7 @@ inline bool validateName(const string& name)
 static char *
 copy_string (const char * s)
 {
-  unsigned long int slen = strlen(s);
+  size_t slen = strlen(s);
   char * copy = new char[slen + 1];
 
   // the source string length is known so no need to check for '\0'
@@ -175,16 +325,24 @@ template<typename Itr>
 static int
 find_child (Itr begin, Itr end, int index, const PropertyList& nodes)
 {
-  int nNodes = nodes.size();
-  boost::iterator_range<Itr> name(begin, end);
+  size_t nNodes = nodes.size();
+#if PROPS_STANDALONE
   for (int i = 0; i < nNodes; i++) {
     SGPropertyNode * node = nodes[i];
+    if (node->getIndex() == index && compare_strings(node->getName(), begin))
+      return i;
+  }
+#else
+  boost::iterator_range<Itr> name(begin, end);
+  for (size_t i = 0; i < nNodes; i++) {
+    SGPropertyNode * node = nodes[i];
 
-    // searching for a mathing index is a lot less time consuming than
+    // searching for a matching index is a lot less time consuming than
     // comparing two strings so do that first.
     if (node->getIndex() == index && boost::equals(node->getName(), name))
-      return i;
+      return static_cast<int>(i);
   }
+#endif
   return -1;
 }
 
@@ -194,10 +352,10 @@ find_child (Itr begin, Itr end, int index, const PropertyList& nodes)
 static int
 find_last_child (const char * name, const PropertyList& nodes)
 {
-  int nNodes = nodes.size();
-  int index = 0;
+  size_t nNodes = nodes.size();
+  int index = -1;
 
-  for (int i = 0; i < nNodes; i++) {
+  for (size_t i = 0; i < nNodes; i++) {
     SGPropertyNode * node = nodes[i];
     if (compare_strings(node->getName(), name))
     {
@@ -208,35 +366,41 @@ find_last_child (const char * name, const PropertyList& nodes)
   return index;
 }
 
+/**
+ * Get first unused index for child nodes with the given name
+ */
+static int
+first_unused_index( const char * name,
+                    const PropertyList& nodes,
+                    int min_index )
+{
+  const char* nameEnd = name + strlen(name);
+
+  for( int index = min_index; index < std::numeric_limits<int>::max(); ++index )
+  {
+    if( find_child(name, nameEnd, index, nodes) < 0 )
+      return index;
+  }
+
+  SG_LOG(SG_GENERAL, SG_ALERT, "Too many nodes: " << name);
+  return -1;
+}
+
 template<typename Itr>
 inline SGPropertyNode*
-SGPropertyNode::getExistingChild (Itr begin, Itr end, int index, bool create)
+SGPropertyNode::getExistingChild (Itr begin, Itr end, int index)
 {
   int pos = find_child(begin, end, index, _children);
-  if (pos >= 0) {
+  if (pos >= 0)
     return _children[pos];
-  } else if (create) {
-    SGPropertyNode_ptr node;
-    pos = find_child(begin, end, index, _removedChildren);
-    if (pos >= 0) {
-      PropertyList::iterator it = _removedChildren.begin();
-      it += pos;
-      node = _removedChildren[pos];
-      _removedChildren.erase(it);
-      node->setAttribute(REMOVED, false);
-      _children.push_back(node);
-      fireChildAdded(node);
-      return node;      
-    }
-  }
   return 0;
 }
-    
+
 template<typename Itr>
 SGPropertyNode *
 SGPropertyNode::getChildImpl (Itr begin, Itr end, int index, bool create)
 {
-    SGPropertyNode* node = getExistingChild(begin, end, index, create);
+    SGPropertyNode* node = getExistingChild(begin, end, index);
 
     if (node) {
       return node;
@@ -268,13 +432,13 @@ find_node_aux(SGPropertyNode * current, SplitItr& itr, bool create,
   // Empty name at this point is empty, not root.
   if (token.empty())
     return find_node_aux(current, ++itr, create, last_index);
-  Range name = parse_name(token);
+  Range name = parse_name(current, token);
   if (equals(name, "."))
     return find_node_aux(current, ++itr, create, last_index);
   if (equals(name, "..")) {
     SGPropertyNode * parent = current->getParent();
     if (parent == 0)
-      throw string("attempt to move past root with '..'");
+      throw std::string("attempt to move past root with '..'");
     return find_node_aux(parent, ++itr, create, last_index);
   }
   int index = -1;
@@ -307,10 +471,10 @@ find_node_aux(SGPropertyNode * current, SplitItr& itr, bool create,
           }
         }
         if (i == token.end() || *i != ']')
-          throw string("unterminated index (looking for ']')");
+          throw std::string("unterminated index (looking for ']')");
       } else {
-        throw string("illegal characters in token: ")
-          + string(name.begin(), name.end());
+        throw std::string("illegal characters in token: ")
+          + std::string(name.begin(), name.end());
       }
     }
   }
@@ -321,11 +485,57 @@ find_node_aux(SGPropertyNode * current, SplitItr& itr, bool create,
 
 // Internal function for parsing property paths. last_index provides
 // and index value for the last node name token, if supplied.
+#if PROPS_STANDALONE
+static SGPropertyNode *
+find_node (SGPropertyNode * current,
+     const vector<PathComponent> &components,
+     int position,
+     bool create)
+{
+  // Run off the end of the list
+  if (current == 0) {
+    return 0;
+  }
+
+  // Success! This is the one we want.
+  else if (position >= (int)components.size()) {
+    return (current->getAttribute(SGPropertyNode::REMOVED) ? 0 : current);
+  }
+
+  // Empty component means root.
+  else if (components[position].name == "") {
+    return find_node(current->getRootNode(), components, position + 1, create);
+  }
+
+  // . means current directory
+  else if (components[position].name == ".") {
+    return find_node(current, components, position + 1, create);
+  }
+
+  // .. means parent directory
+  else if (components[position].name == "..") {
+    SGPropertyNode * parent = current->getParent();
+    if (parent == 0)
+      throw string("Attempt to move past root with '..'");
+    else
+      return find_node(parent, components, position + 1, create);
+  }
+
+  // Otherwise, a child name
+  else {
+    SGPropertyNode * child =
+      current->getChild(components[position].name.c_str(),
+      components[position].index,
+      create);
+    return find_node(child, components, position + 1, create);
+  }
+}
+#else
 template<typename Range>
 SGPropertyNode*
 find_node (SGPropertyNode * current,
            const Range& path,
-          bool create,
+           bool create,
            int last_index = -1)
 {
   using namespace boost;
@@ -339,8 +549,8 @@ find_node (SGPropertyNode * current,
    else
      return find_node_aux(current, itr, create, last_index);
 }
+#endif
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Private methods from SGPropertyNode (may be inlined for speed).
 ////////////////////////////////////////////////////////////////////////
@@ -600,13 +810,8 @@ SGPropertyNode::make_string () const
 void
 SGPropertyNode::trace_write () const
 {
-#if PROPS_STANDALONE
-  cerr << "TRACE: Write node " << getPath () << ", value \""
-       << make_string() << '"' << endl;
-#else
   SG_LOG(SG_GENERAL, SG_ALERT, "TRACE: Write node " << getPath()
         << ", value \"" << make_string() << '"');
-#endif
 }
 
 /**
@@ -615,16 +820,10 @@ SGPropertyNode::trace_write () const
 void
 SGPropertyNode::trace_read () const
 {
-#if PROPS_STANDALONE
-  cerr << "TRACE: Write node " << getPath () << ", value \""
-       << make_string() << '"' << endl;
-#else
   SG_LOG(SG_GENERAL, SG_ALERT, "TRACE: Read node " << getPath()
         << ", value \"" << make_string() << '"');
-#endif
 }
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Public methods from SGPropertyNode.
 ////////////////////////////////////////////////////////////////////////
@@ -633,7 +832,7 @@ SGPropertyNode::trace_read () const
  * Last used attribute
  * Update as needed when enum Attribute is changed
  */
-const int SGPropertyNode::LAST_USED_ATTRIBUTE = USERARCHIVE;
+const int SGPropertyNode::LAST_USED_ATTRIBUTE = PRESERVE;
 
 /**
  * Default constructor: always creates a root node.
@@ -641,7 +840,6 @@ const int SGPropertyNode::LAST_USED_ATTRIBUTE = USERARCHIVE;
 SGPropertyNode::SGPropertyNode ()
   : _index(0),
     _parent(0),
-    _path_cache(0),
     _type(props::NONE),
     _tied(false),
     _attr(READ|WRITE),
@@ -656,10 +854,10 @@ SGPropertyNode::SGPropertyNode ()
  * Copy constructor.
  */
 SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
-  : _index(node._index),
+  : SGReferenced(node),
+    _index(node._index),
     _name(node._name),
     _parent(0),                        // don't copy the parent
-    _path_cache(0),
     _type(node._type),
     _tied(node._tied),
     _attr(node._attr),
@@ -715,7 +913,6 @@ SGPropertyNode::SGPropertyNode (Itr begin, Itr end,
   : _index(index),
     _name(begin, end),
     _parent(parent),
-    _path_cache(0),
     _type(props::NONE),
     _tied(false),
     _attr(READ|WRITE),
@@ -724,16 +921,15 @@ SGPropertyNode::SGPropertyNode (Itr begin, Itr end,
   _local_val.string_val = 0;
   _value.val = 0;
   if (!validateName(_name))
-    throw string("plain name expected instead of '") + _name + '\'';
+    throw std::string("plain name expected instead of '") + _name + '\'';
 }
 
-SGPropertyNode::SGPropertyNode (const string& name,
-                               int index,
-                               SGPropertyNode * parent)
+SGPropertyNode::SGPropertyNode( const std::string& name,
+                                int index,
+                                SGPropertyNode * parent)
   : _index(index),
     _name(name),
     _parent(parent),
-    _path_cache(0),
     _type(props::NONE),
     _tied(false),
     _attr(READ|WRITE),
@@ -742,7 +938,7 @@ SGPropertyNode::SGPropertyNode (const string& name,
   _local_val.string_val = 0;
   _value.val = 0;
   if (!validateName(name))
-    throw string("plain name expected instead of '") + _name + '\'';
+    throw std::string("plain name expected instead of '") + _name + '\'';
 }
 
 /**
@@ -753,9 +949,6 @@ SGPropertyNode::~SGPropertyNode ()
   // zero out all parent pointers, else they might be dangling
   for (unsigned i = 0; i < _children.size(); ++i)
     _children[i]->_parent = 0;
-  for (unsigned i = 0; i < _removedChildren.size(); ++i)
-    _removedChildren[i]->_parent = 0;
-  delete _path_cache;
   clearValue();
 
   if (_listeners) {
@@ -773,13 +966,38 @@ SGPropertyNode::~SGPropertyNode ()
 bool
 SGPropertyNode::alias (SGPropertyNode * target)
 {
-  if (target == 0 || _type == props::ALIAS || _tied)
-    return false;
-  clearValue();
-  get(target);
-  _value.alias = target;
-  _type = props::ALIAS;
-  return true;
+  if (target && (_type != props::ALIAS) && (!_tied))
+  {
+    clearValue();
+    get(target);
+    _value.alias = target;
+    _type = props::ALIAS;
+    return true;
+  }
+
+  if (!target)
+  {
+    SG_LOG(SG_GENERAL, SG_ALERT,
+           "Failed to create alias for " << getPath() << ". "
+           "The target property does not exist.");
+  }
+  else
+  if (_type == props::ALIAS)
+  {
+    if (_value.alias == target)
+        return true; // ok, identical alias requested
+    SG_LOG(SG_GENERAL, SG_ALERT,
+           "Failed to create alias at " << target->getPath() << ". "
+           "Source "<< getPath() << " is already aliasing another property.");
+  }
+  else
+  if (_tied)
+  {
+    SG_LOG(SG_GENERAL, SG_ALERT, "Failed to create alias at " << target->getPath() << ". "
+           "Source " << getPath() << " is a tied property.");
+  }
+
+  return false;
 }
 
 
@@ -826,9 +1044,11 @@ SGPropertyNode::getAliasTarget () const
  * create a non-const child by name after the last node with the same name.
  */
 SGPropertyNode *
-SGPropertyNode::addChild (const char * name)
+SGPropertyNode::addChild(const char * name, int min_index, bool append)
 {
-  int pos = find_last_child(name, _children)+1;
+  int pos = append
+          ? std::max(find_last_child(name, _children) + 1, min_index)
+          : first_unused_index(name, _children, min_index);
 
   SGPropertyNode_ptr node;
   node = new SGPropertyNode(name, name + strlen(name), pos, this);
@@ -837,6 +1057,52 @@ SGPropertyNode::addChild (const char * name)
   return node;
 }
 
+/**
+ * Create multiple children with unused indices
+ */
+simgear::PropertyList
+SGPropertyNode::addChildren( const std::string& name,
+                             size_t count,
+                             int min_index,
+                             bool append )
+{
+  simgear::PropertyList nodes;
+  std::set<int> used_indices;
+
+  if( !append )
+  {
+    // First grab all used indices. This saves us of testing every index if it
+    // is used for every element to be created
+    for( size_t i = 0; i < nodes.size(); i++ )
+    {
+      const SGPropertyNode* node = nodes[i];
+
+      if( node->getNameString() == name && node->getIndex() >= min_index )
+        used_indices.insert(node->getIndex());
+    }
+  }
+  else
+  {
+    // If we don't want to fill the holes just find last node
+    min_index = std::max(find_last_child(name.c_str(), _children) + 1, min_index);
+  }
+
+  for( int index = min_index;
+            index < std::numeric_limits<int>::max() && nodes.size() < count;
+          ++index )
+  {
+    if( used_indices.find(index) == used_indices.end() )
+    {
+      SGPropertyNode_ptr node;
+      node = new SGPropertyNode(name, index, this);
+      _children.push_back(node);
+      fireChildAdded(node);
+      nodes.push_back(node);
+    }
+  }
+
+  return nodes;
+}
 
 /**
  * Get a non-const child by index.
@@ -875,14 +1141,20 @@ SGPropertyNode::getChild (const char * name, int index, bool create)
 }
 
 SGPropertyNode *
-SGPropertyNode::getChild (const string& name, int index, bool create)
+SGPropertyNode::getChild (const std::string& name, int index, bool create)
 {
-  SGPropertyNode* node = getExistingChild(name.begin(), name.end(), index,
-                                          create);
+#if PROPS_STANDALONE
+  const char *n = name.c_str();
+  int pos = find_child(n, n + strlen(n), index, _children);
+  if (pos >= 0) {
+    return _children[pos];
+#else
+  SGPropertyNode* node = getExistingChild(name.begin(), name.end(), index);
   if (node) {
       return node;
+#endif
     } else if (create) {
-      node = new SGPropertyNode(name, index, this);
+      SGPropertyNode* node = new SGPropertyNode(name, index, this);
       _children.push_back(node);
       fireChildAdded(node);
       return node;
@@ -912,9 +1184,9 @@ PropertyList
 SGPropertyNode::getChildren (const char * name) const
 {
   PropertyList children;
-  int max = _children.size();
+  size_t max = _children.size();
 
-  for (int i = 0; i < max; i++)
+  for (size_t i = 0; i < max; i++)
     if (compare_strings(_children[i]->getName(), name))
       children.push_back(_children[i]);
 
@@ -922,46 +1194,28 @@ SGPropertyNode::getChildren (const char * name) const
   return children;
 }
 
-
-/**
- * Remove this node and all children from nodes that link to them
- * in their path cache.
- */
-void
-SGPropertyNode::remove_from_path_caches ()
+//------------------------------------------------------------------------------
+bool SGPropertyNode::removeChild(SGPropertyNode* node)
 {
-  for (unsigned int i = 0; i < _children.size(); ++i)
-    _children[i]->remove_from_path_caches();
+  if( node->_parent != this )
+    return false;
 
-  for (unsigned int i = 0; i < _linkedNodes.size(); i++)
-    _linkedNodes[i]->erase(this);
-  _linkedNodes.clear();
-}
+  PropertyList::iterator it =
+    std::find(_children.begin(), _children.end(), node);
+  if( it == _children.end() )
+    return false;
 
+  eraseChild(it);
+  return true;
+}
 
-/**
- * Remove child by position.
- */
-SGPropertyNode_ptr
-SGPropertyNode::removeChild (int pos, bool keep)
+//------------------------------------------------------------------------------
+SGPropertyNode_ptr SGPropertyNode::removeChild(int pos)
 {
-  SGPropertyNode_ptr node;
   if (pos < 0 || pos >= (int)_children.size())
-    return node;
+    return SGPropertyNode_ptr();
 
-  PropertyList::iterator it = _children.begin();
-  it += pos;
-  node = _children[pos];
-  _children.erase(it);
-  if (keep) {
-    _removedChildren.push_back(node);
-  }
-
-  node->remove_from_path_caches();
-  node->setAttribute(REMOVED, true);
-  node->clearValue();
-  fireChildRemoved(node);
-  return node;
+  return eraseChild(_children.begin() + pos);
 }
 
 
@@ -969,12 +1223,12 @@ SGPropertyNode::removeChild (int pos, bool keep)
  * Remove a child node
  */
 SGPropertyNode_ptr
-SGPropertyNode::removeChild (const char * name, int index, bool keep)
+SGPropertyNode::removeChild(const char * name, int index)
 {
   SGPropertyNode_ptr ret;
   int pos = find_child(name, name + strlen(name), index, _children);
   if (pos >= 0)
-    ret = removeChild(pos, keep);
+    ret = removeChild(pos);
   return ret;
 }
 
@@ -983,41 +1237,37 @@ SGPropertyNode::removeChild (const char * name, int index, bool keep)
   * Remove all children with the specified name.
   */
 PropertyList
-SGPropertyNode::removeChildren (const char * name, bool keep)
+SGPropertyNode::removeChildren(const char * name)
 {
   PropertyList children;
 
-  for (int pos = _children.size() - 1; pos >= 0; pos--)
+  for (int pos = static_cast<int>(_children.size() - 1); pos >= 0; pos--)
     if (compare_strings(_children[pos]->getName(), name))
-      children.push_back(removeChild(pos, keep));
+      children.push_back(removeChild(pos));
 
   sort(children.begin(), children.end(), CompareIndices());
   return children;
 }
 
-
-/**
-  * Remove a linked node.
-  */
-bool
-SGPropertyNode::remove_linked_node (hash_table * node)
+void
+SGPropertyNode::removeAllChildren()
 {
-  for (unsigned int i = 0; i < _linkedNodes.size(); i++) {
-    if (_linkedNodes[i] == node) {
-      vector<hash_table *>::iterator it = _linkedNodes.begin();
-      it += i;
-      _linkedNodes.erase(it);
-      return true;
-    }
+  for(unsigned i = 0; i < _children.size(); ++i)
+  {
+    SGPropertyNode_ptr& node = _children[i];
+    node->_parent = 0;
+    node->setAttribute(REMOVED, true);
+    node->clearValue();
+    fireChildRemoved(node);
   }
-  return false;
-}
 
+  _children.clear();
+}
 
-string
+std::string
 SGPropertyNode::getDisplayName (bool simplify) const
 {
-  string display_name = _name;
+  std::string display_name = _name;
   if (_index != 0 || !simplify) {
     stringstream sstr;
     sstr << '[' << _index << ']';
@@ -1026,18 +1276,22 @@ SGPropertyNode::getDisplayName (bool simplify) const
   return display_name;
 }
 
-
-const char *
+std::string
 SGPropertyNode::getPath (bool simplify) const
 {
-  // Calculate the complete path only once.
-  if (_parent != 0 && _path.empty()) {
-    _path = _parent->getPath(simplify);
-    _path += '/';
-    _path += getDisplayName(simplify);
+  typedef std::vector<SGConstPropertyNode_ptr> PList;
+  PList pathList;
+  for (const SGPropertyNode* node = this; node->_parent; node = node->_parent)
+    pathList.push_back(node);
+  std::string result;
+  for (PList::reverse_iterator itr = pathList.rbegin(),
+         rend = pathList.rend();
+       itr != rend;
+       ++itr) {
+    result += '/';
+    result += (*itr)->getDisplayName(simplify);
   }
-
-  return _path.c_str();
+  return result;
 }
 
 props::Type
@@ -1574,12 +1828,14 @@ SGPropertyNode::setUnspecifiedValue (const char * value)
   case props::UNSPECIFIED:
     result = set_string(value);
     break;
+#if !PROPS_STANDALONE
   case props::VEC3D:
       result = static_cast<SGRawValue<SGVec3d>*>(_value.val)->setValue(parseString<SGVec3d>(value));
       break;
   case props::VEC4D:
       result = static_cast<SGRawValue<SGVec4d>*>(_value.val)->setValue(parseString<SGVec4d>(value));
       break;
+#endif
   case props::NONE:
   default:
     break;
@@ -1590,6 +1846,60 @@ SGPropertyNode::setUnspecifiedValue (const char * value)
   return result;
 }
 
+//------------------------------------------------------------------------------
+#if !PROPS_STANDALONE
+bool SGPropertyNode::interpolate( const std::string& type,
+                                  const SGPropertyNode& target,
+                                  double duration,
+                                  const std::string& easing )
+{
+  if( !_interpolation_mgr )
+  {
+    SG_LOG(SG_GENERAL, SG_WARN, "No property interpolator available");
+
+    // no interpolation possible -> set to target immediately
+    setUnspecifiedValue( target.getStringValue() );
+    return false;
+  }
+
+  return _interpolation_mgr->interpolate(this, type, target, duration, easing);
+}
+
+//------------------------------------------------------------------------------
+bool SGPropertyNode::interpolate( const std::string& type,
+                                  const simgear::PropertyList& values,
+                                  const double_list& deltas,
+                                  const std::string& easing )
+{
+  if( !_interpolation_mgr )
+  {
+    SG_LOG(SG_GENERAL, SG_WARN, "No property interpolator available");
+
+    // no interpolation possible -> set to last value immediately
+    if( !values.empty() )
+      setUnspecifiedValue(values.back()->getStringValue());
+    return false;
+  }
+
+  return _interpolation_mgr->interpolate(this, type, values, deltas, easing);
+}
+
+//------------------------------------------------------------------------------
+void SGPropertyNode::setInterpolationMgr(simgear::PropertyInterpolationMgr* mgr)
+{
+  _interpolation_mgr = mgr;
+}
+
+//------------------------------------------------------------------------------
+simgear::PropertyInterpolationMgr* SGPropertyNode::getInterpolationMgr()
+{
+  return _interpolation_mgr;
+}
+
+simgear::PropertyInterpolationMgr* SGPropertyNode::_interpolation_mgr = 0;
+#endif
+
+//------------------------------------------------------------------------------
 std::ostream& SGPropertyNode::printOn(std::ostream& stream) const
 {
     if (!getAttribute(READ))
@@ -1643,8 +1953,12 @@ bool SGPropertyNode::tie (const SGRawValue<const char *> &rawValue,
     _tied = true;
     _value.val = rawValue.clone();
 
-    if (useDefault)
+    if (useDefault) {
+        int save_attributes = getAttributes();
+        setAttribute( WRITE, true );
         setStringValue(old_val.c_str());
+        setAttributes( save_attributes );
+    }
 
     return true;
 }
@@ -1692,7 +2006,7 @@ SGPropertyNode::untie ()
   }
   case props::STRING:
   case props::UNSPECIFIED: {
-    string val = getStringValue();
+    std::string val = getStringValue();
     clearValue();
     _type = props::STRING;
     _local_val.string_val = copy_string(val.c_str());
@@ -1737,30 +2051,37 @@ SGPropertyNode::getRootNode () const
 SGPropertyNode *
 SGPropertyNode::getNode (const char * relative_path, bool create)
 {
-  using namespace boost;
-  if (_path_cache == 0)
-    _path_cache = new hash_table;
+#if PROPS_STANDALONE
+  vector<PathComponent> components;
+  parse_path(relative_path, components);
+  return find_node(this, components, 0, create);
 
-  SGPropertyNode * result = _path_cache->get(relative_path);
-  if (result == 0) {
-    result = find_node(this,
-                       make_iterator_range(relative_path, relative_path
-                                           + strlen(relative_path)),
-                       create);
-    if (result != 0)
-      _path_cache->put(relative_path, result);
-  }
+#else
+  using namespace boost;
 
-  return result;
+  return find_node(this, make_iterator_range(relative_path, relative_path
+                                             + strlen(relative_path)),
+                   create);
+#endif
 }
 
 SGPropertyNode *
 SGPropertyNode::getNode (const char * relative_path, int index, bool create)
 {
+#if PROPS_STANDALONE
+  vector<PathComponent> components;
+  parse_path(relative_path, components);
+  if (components.size() > 0)
+    components.back().index = index;
+  return find_node(this, components, 0, create);
+
+#else
   using namespace boost;
+
   return find_node(this, make_iterator_range(relative_path, relative_path
                                              + strlen(relative_path)),
                    create, index);
+#endif
 }
 
 const SGPropertyNode *
@@ -1775,7 +2096,6 @@ SGPropertyNode::getNode (const char * relative_path, int index) const
   return ((SGPropertyNode *)this)->getNode(relative_path, index, false);
 }
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Convenience methods using relative paths.
 ////////////////////////////////////////////////////////////////////////
@@ -2054,6 +2374,8 @@ SGPropertyNode::addChangeListener (SGPropertyChangeListener * listener,
 void
 SGPropertyNode::removeChangeListener (SGPropertyChangeListener * listener)
 {
+  if (_listeners == 0)
+    return;
   vector<SGPropertyChangeListener*>::iterator it =
     find(_listeners->begin(), _listeners->end(), listener);
   if (it != _listeners->end()) {
@@ -2079,12 +2401,38 @@ SGPropertyNode::fireChildAdded (SGPropertyNode * child)
   fireChildAdded(this, child);
 }
 
+void
+SGPropertyNode::fireCreatedRecursive(bool fire_self)
+{
+  if( fire_self )
+  {
+    _parent->fireChildAdded(this);
+
+    if( _children.empty() && getType() != simgear::props::NONE )
+      return fireValueChanged();
+  }
+
+  for(size_t i = 0; i < _children.size(); ++i)
+    _children[i]->fireCreatedRecursive(true);
+}
+
 void
 SGPropertyNode::fireChildRemoved (SGPropertyNode * child)
 {
   fireChildRemoved(this, child);
 }
 
+void
+SGPropertyNode::fireChildrenRemovedRecursive()
+{
+  for(size_t i = 0; i < _children.size(); ++i)
+  {
+    SGPropertyNode* child = _children[i];
+    fireChildRemoved(this, child);
+    child->fireChildrenRemovedRecursive();
+  }
+}
+
 void
 SGPropertyNode::fireValueChanged (SGPropertyNode * node)
 {
@@ -2123,180 +2471,26 @@ SGPropertyNode::fireChildRemoved (SGPropertyNode * parent,
     _parent->fireChildRemoved(parent, child);
 }
 
-
-\f
-////////////////////////////////////////////////////////////////////////
-// Simplified hash table for caching paths.
-////////////////////////////////////////////////////////////////////////
-
-#define HASH_TABLE_SIZE 199
-
-SGPropertyNode::hash_table::entry::entry ()
-  : _value(0)
-{
-}
-
-SGPropertyNode::hash_table::entry::~entry ()
-{
-                               // Don't delete the value; we don't own
-                               // the pointer.
-}
-
-void
-SGPropertyNode::hash_table::entry::set_key (const char * key)
-{
-  _key = key;
-}
-
-void
-SGPropertyNode::hash_table::entry::set_value (SGPropertyNode * value)
-{
-  _value = value;
-}
-
-SGPropertyNode::hash_table::bucket::bucket ()
-  : _length(0),
-    _entries(0)
-{
-}
-
-SGPropertyNode::hash_table::bucket::~bucket ()
-{
-  for (int i = 0; i < _length; i++)
-    delete _entries[i];
-  delete [] _entries;
-}
-
-SGPropertyNode::hash_table::entry *
-SGPropertyNode::hash_table::bucket::get_entry (const char * key, bool create)
-{
-  int i;
-  for (i = 0; i < _length; i++) {
-    if (!strcmp(_entries[i]->get_key(), key))
-      return _entries[i];
-  }
-  if (create) {
-    entry ** new_entries = new entry*[_length+1];
-    for (i = 0; i < _length; i++) {
-      new_entries[i] = _entries[i];
-    }
-    delete [] _entries;
-    _entries = new_entries;
-    _entries[_length] = new entry;
-    _entries[_length]->set_key(key);
-    _length++;
-    return _entries[_length - 1];
-  } else {
-    return 0;
-  }
-}
-
-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];
-      }
-      _length--;
-      return true;
-    }
-  }
-  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++) {
-    if (_data[i]) {
-      _data[i]->clear(this);
-      delete _data[i];
-    }
-  }
-  delete [] _data;
-}
-
-SGPropertyNode *
-SGPropertyNode::hash_table::get (const char * key)
-{
-  if (_data_length == 0)
-    return 0;
-  unsigned int index = hashcode(key) % _data_length;
-  if (_data[index] == 0)
-    return 0;
-  entry * e = _data[index]->get_entry(key);
-  if (e == 0)
-    return 0;
-  else
-    return e->get_value();
-}
-
-void
-SGPropertyNode::hash_table::put (const char * key, SGPropertyNode * value)
-{
-  if (_data_length == 0) {
-    _data = new bucket*[HASH_TABLE_SIZE];
-    _data_length = HASH_TABLE_SIZE;
-    for (unsigned int i = 0; i < HASH_TABLE_SIZE; i++)
-      _data[i] = 0;
-  }
-  unsigned int index = hashcode(key) % _data_length;
-  if (_data[index] == 0) {
-    _data[index] = new bucket;
-  }
-  entry * e = _data[index]->get_entry(key, true);
-  e->set_value(value);
-  value->add_linked_node(this);
-}
-
-bool
-SGPropertyNode::hash_table::erase (SGPropertyNode * node)
+//------------------------------------------------------------------------------
+SGPropertyNode_ptr
+SGPropertyNode::eraseChild(simgear::PropertyList::iterator child)
 {
-  for (unsigned int i = 0; i < _data_length; i++)
-    if (_data[i] && _data[i]->erase(node))
-      return true;
-
-  return false;
-}
+  SGPropertyNode_ptr node = *child;
+  node->setAttribute(REMOVED, true);
+  node->clearValue();
+  fireChildRemoved(node);
 
-unsigned int
-SGPropertyNode::hash_table::hashcode (const char * key)
-{
-  unsigned int hash = 0;
-  while (*key != 0) {
-    hash = 31 * hash + *key;
-    key++;
-  }
-  return hash;
+  _children.erase(child);
+  return node;
 }
 
-
-\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGPropertyChangeListener.
 ////////////////////////////////////////////////////////////////////////
 
 SGPropertyChangeListener::~SGPropertyChangeListener ()
 {
-  for (int i = _properties.size() - 1; i >= 0; i--)
+  for (int i = static_cast<int>(_properties.size() - 1); i >= 0; i--)
     _properties[i]->removeChangeListener(this);
 }
 
@@ -2335,6 +2529,7 @@ SGPropertyChangeListener::unregister_property (SGPropertyNode * node)
     _properties.erase(it);
 }
 
+#if !PROPS_STANDALONE
 template<>
 std::ostream& SGRawBase<SGVec3d>::printOn(std::ostream& stream) const
 {
@@ -2371,9 +2566,11 @@ std::ostream& SGRawBase<SGVec4d>::printOn(std::ostream& stream) const
     }
     return stream;
 }
+#endif
 
 namespace simgear
 {
+#if !PROPS_STANDALONE
 template<>
 std::istream& readFrom<SGVec4d>(std::istream& stream, SGVec4d& result)
 {
@@ -2382,6 +2579,7 @@ std::istream& readFrom<SGVec4d>(std::istream& stream, SGVec4d& result)
     }
     return stream;
 }
+#endif
 
 namespace
 {
@@ -2409,10 +2607,12 @@ bool compareNodeValue(const SGPropertyNode& lhs, const SGPropertyNode& rhs)
     case props::STRING:
     case props::UNSPECIFIED:
         return !strcmp(lhs.getStringValue(), rhs.getStringValue());
+#if !PROPS_STANDALONE
     case props::VEC3D:
         return lhs.getValue<SGVec3d>() == rhs.getValue<SGVec3d>();
     case props::VEC4D:
         return lhs.getValue<SGVec4d>() == rhs.getValue<SGVec4d>();
+#endif
     default:
         return false;
     }
@@ -2469,10 +2669,10 @@ struct PropertyPlaceLess {
     }
 };
 
+#if !PROPS_STANDALONE
 size_t hash_value(const SGPropertyNode& node)
 {
     using namespace boost;
-
     if (node.nChildren() == 0) {
         switch (node.getType()) {
         case props::NONE:
@@ -2523,5 +2723,6 @@ size_t hash_value(const SGPropertyNode& node)
         return seed;
     }
 }
+#endif
 
 // end of props.cxx