]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props.cxx
Patch from Cameron Moore:
[simgear.git] / simgear / misc / props.cxx
index 2889e29a2b393d1d9a3f6f23a88d8d4fce9826eb..0af19b435799e79f54772a974c9ae617276d069c 100644 (file)
@@ -6,16 +6,38 @@
 //
 // $Id$
 
-#include <simgear/compiler.h>
-#include <simgear/debug/logstream.hxx>
+#include "props.hxx"
 
-#include <stdio.h>
-#include <stdlib.h>
-#include STL_IOSTREAM
 #include <algorithm>
-#include "props.hxx"
+#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;
+
+#else
+
+#include <simgear/compiler.h>
+#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
 
 
 \f
@@ -29,7 +51,7 @@ SG_USING_STD(sort);
 class CompareIndices
 {
 public:
-  int operator() (const SGPropertyNode * n1, const SGPropertyNode *n2) const {
+  int operator() (const SGPropertyNode_ptr n1, const SGPropertyNode_ptr n2) const {
     return (n1->getIndex() < n2->getIndex());
   }
 };
@@ -43,23 +65,6 @@ public:
 #define TEST_READ(dflt) if (!getAttribute(READ)) return dflt
 #define TEST_WRITE if (!getAttribute(WRITE)) return false
 
-#define DO_TRACE_READ(type) if(getAttribute(TRACE_READ)) trace_read(type)
-#define DO_TRACE_WRITE(type) if (getAttribute(TRACE_WRITE)) trace_write(type)
-
-#define GET_BOOL (_value.bool_val->getValue())
-#define GET_INT (_value.int_val->getValue())
-#define GET_LONG (_value.long_val->getValue())
-#define GET_FLOAT (_value.float_val->getValue())
-#define GET_DOUBLE (_value.double_val->getValue())
-#define GET_STRING (_value.string_val->getValue())
-
-#define SET_BOOL(val) (_value.bool_val->setValue(val))
-#define SET_INT(val) (_value.int_val->setValue(val))
-#define SET_LONG(val) (_value.long_val->setValue(val))
-#define SET_FLOAT(val) (_value.float_val->setValue(val))
-#define SET_DOUBLE(val) (_value.double_val->setValue(val))
-#define SET_STRING(val) (_value.string_val->setValue(val))
-
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -71,7 +76,7 @@ const int SGRawValue<int>::DefaultValue = 0;
 const long SGRawValue<long>::DefaultValue = 0L;
 const float SGRawValue<float>::DefaultValue = 0.0;
 const double SGRawValue<double>::DefaultValue = 0.0L;
-const string SGRawValue<string>::DefaultValue = "";
+const char * const SGRawValue<const char *>::DefaultValue = "";
 
 
 \f
@@ -93,7 +98,7 @@ struct PathComponent
  *
  * Name: [_a-zA-Z][-._a-zA-Z0-9]*
  */
-static inline string
+static inline const string
 parse_name (const string &path, int &i)
 {
   string name = "";
@@ -221,16 +226,33 @@ parse_path (const string &path, vector<PathComponent> &components)
 ////////////////////////////////////////////////////////////////////////
 
 
+static char *
+copy_string (const char * s)
+{
+                               // FIXME: potential buffer overflow.
+                               // For some reason, strnlen and
+                               // strncpy cause all kinds of crashes.
+  char * copy = new char[strlen(s) + 1];
+  strcpy(copy, s);
+  return copy;
+}
+
+static bool
+compare_strings (const char * s1, const char * s2)
+{
+  return !strncmp(s1, s2, SGPropertyNode::MAX_STRING_LEN);
+}
+
 /**
  * Locate a child node by name and index.
  */
 static int
-find_child (const string &name, int index, vector<SGPropertyNode *> nodes)
+find_child (const char * name, int index, vector<SGPropertyNode_ptr> nodes)
 {
   int nNodes = nodes.size();
   for (int i = 0; i < nNodes; i++) {
     SGPropertyNode * node = nodes[i];
-    if (node->getName() == name && node->getIndex() == index)
+    if (compare_strings(node->getName(), name) && node->getIndex() == index)
       return i;
   }
   return -1;
@@ -278,7 +300,7 @@ find_node (SGPropertyNode * current,
                                // Otherwise, a child name
   else {
     SGPropertyNode * child =
-      current->getChild(components[position].name,
+      current->getChild(components[position].name.c_str(),
                        components[position].index,
                        create);
     return find_node(child, components, position + 1, create);
@@ -288,132 +310,222 @@ find_node (SGPropertyNode * current,
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Implementation of SGPropertyNode.
+// Private methods from SGPropertyNode (may be inlined for speed).
 ////////////////////////////////////////////////////////////////////////
 
+inline bool
+SGPropertyNode::get_bool () const
+{
+  if (_tied)
+    return _value.bool_val->getValue();
+  else
+    return _local_val.bool_val;
+}
 
-/**
- * Default constructor: always creates a root node.
- */
-SGPropertyNode::SGPropertyNode ()
-  : _name(""),
-    _index(0),
-    _parent(0),
-    _path_cache(0),
-    _type(NONE),
-    _tied(false),
-    _attr(READ|WRITE)
+inline int
+SGPropertyNode::get_int () const
 {
+  if (_tied)
+    return _value.int_val->getValue();
+  else
+    return _local_val.int_val;
 }
 
+inline long
+SGPropertyNode::get_long () const
+{
+  if (_tied)
+    return _value.long_val->getValue();
+  else
+    return _local_val.long_val;
+}
 
-/**
- * Copy constructor.
- */
-SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
-  : _name(node._name),
-    _index(node._index),
-    _parent(0),                        // don't copy the parent
-    _path_cache(0),
-    _type(node._type),
-    _tied(node._tied),
-    _attr(node._attr)
+inline float
+SGPropertyNode::get_float () const
 {
-  switch (_type) {
-  case NONE:
-    break;
-  case ALIAS:
-    _value.alias = node._value.alias;
-    break;
-  case BOOL:
-    _value.bool_val = node._value.bool_val->clone();
-    break;
-  case INT:
-    _value.int_val = node._value.int_val->clone();
-    break;
-  case LONG:
-    _value.long_val = node._value.long_val->clone();
-    break;
-  case FLOAT:
-    _value.float_val = node._value.float_val->clone();
-    break;
-  case DOUBLE:
-    _value.double_val = node._value.double_val->clone();
-    break;
-  case STRING:
-  case UNSPECIFIED:
-    _value.string_val = node._value.string_val->clone();
-    break;
+  if (_tied)
+    return _value.float_val->getValue();
+  else
+    return _local_val.float_val;
+}
+
+inline double
+SGPropertyNode::get_double () const
+{
+  if (_tied)
+    return _value.double_val->getValue();
+  else
+    return _local_val.double_val;
+}
+
+inline const char *
+SGPropertyNode::get_string () const
+{
+  if (_tied)
+    return _value.string_val->getValue();
+  else
+    return _local_val.string_val;
+}
+
+inline bool
+SGPropertyNode::set_bool (bool val)
+{
+  if (_tied) {
+    if (_value.bool_val->setValue(val)) {
+      fireValueChanged();
+      return true;
+    } else {
+      return false;
+    }
+  } else {
+    _local_val.bool_val = val;
+    fireValueChanged();
+    return true;
   }
 }
 
+inline bool
+SGPropertyNode::set_int (int val)
+{
+  if (_tied) {
+    if (_value.int_val->setValue(val)) {
+      fireValueChanged();
+      return true;
+    } else {
+      return false;
+    }
+  } else {
+    _local_val.int_val = val;
+    fireValueChanged();
+    return true;
+  }
+}
 
-/**
- * Convenience constructor.
- */
-SGPropertyNode::SGPropertyNode (const string &name,
-                               int index, SGPropertyNode * parent)
-  : _name(name),
-    _index(index),
-    _parent(parent),
-    _path_cache(0),
-    _type(NONE),
-    _tied(false),
-    _attr(READ|WRITE)
+inline bool
+SGPropertyNode::set_long (long val)
 {
+  if (_tied) {
+    if (_value.long_val->setValue(val)) {
+      fireValueChanged();
+      return true;
+    } else {
+      return false;
+    }
+  } else {
+    _local_val.long_val = val;
+    fireValueChanged();
+    return true;
+  }
 }
 
+inline bool
+SGPropertyNode::set_float (float val)
+{
+  if (_tied) {
+    if (_value.float_val->setValue(val)) {
+      fireValueChanged();
+      return true;
+    } else {
+      return false;
+    }
+  } else {
+    _local_val.float_val = val;
+    fireValueChanged();
+    return true;
+  }
+}
 
-/**
- * Destructor.
- */
-SGPropertyNode::~SGPropertyNode ()
+inline bool
+SGPropertyNode::set_double (double val)
 {
-  for (int i = 0; i < (int)_children.size(); i++) {
-    delete _children[i];
+  if (_tied) {
+    if (_value.double_val->setValue(val)) {
+      fireValueChanged();
+      return true;
+    } else {
+      return false;
+    }
+  } else {
+    _local_val.double_val = val;
+    fireValueChanged();
+    return true;
   }
-  delete _path_cache;
-  clear_value();
 }
 
+inline bool
+SGPropertyNode::set_string (const char * val)
+{
+  if (_tied) {
+    if (_value.string_val->setValue(val)) {
+      fireValueChanged();
+      return true;
+    } else {
+      return false;
+    }
+  } else {
+    delete [] _local_val.string_val;
+    _local_val.string_val = copy_string(val);
+    fireValueChanged();
+    return true;
+  }
+}
 
-/**
- * Delete and clear the current value.
- */
 void
 SGPropertyNode::clear_value ()
 {
   switch (_type) {
   case NONE:
+    break;
   case ALIAS:
     _value.alias = 0;
     break;
   case BOOL:
-    delete _value.bool_val;
-    _value.bool_val = 0;
+    if (_tied) {
+      delete _value.bool_val;
+      _value.bool_val = 0;
+    }
+    _local_val.bool_val = SGRawValue<bool>::DefaultValue;
     break;
   case INT:
-    delete _value.int_val;
-    _value.int_val = 0;
+    if (_tied) {
+      delete _value.int_val;
+      _value.int_val = 0;
+    }
+    _local_val.int_val = SGRawValue<int>::DefaultValue;
     break;
   case LONG:
-    delete _value.long_val;
-    _value.long_val = 0L;
+    if (_tied) {
+      delete _value.long_val;
+      _value.long_val = 0L;
+    }
+    _local_val.long_val = SGRawValue<long>::DefaultValue;
     break;
   case FLOAT:
-    delete _value.float_val;
-    _value.float_val = 0;
+    if (_tied) {
+      delete _value.float_val;
+      _value.float_val = 0;
+    }
+    _local_val.float_val = SGRawValue<float>::DefaultValue;
     break;
   case DOUBLE:
-    delete _value.double_val;
-    _value.double_val = 0;
+    if (_tied) {
+      delete _value.double_val;
+      _value.double_val = 0;
+    }
+    _local_val.double_val = SGRawValue<double>::DefaultValue;
     break;
   case STRING:
   case UNSPECIFIED:
-    delete _value.string_val;
-    _value.string_val = 0;
+    if (_tied) {
+      delete _value.string_val;
+      _value.string_val = 0;
+    } else {
+      delete [] _local_val.string_val;
+    }
+    _local_val.string_val = 0;
     break;
   }
+  _tied = false;
   _type = NONE;
 }
 
@@ -421,61 +533,237 @@ SGPropertyNode::clear_value ()
 /**
  * Get the value as a string.
  */
-string
-SGPropertyNode::get_string () const
+const char *
+SGPropertyNode::make_string () const
 {
-  TEST_READ("");
-  char buf[128];
+  if (!getAttribute(READ))
+    return "";
 
   switch (_type) {
   case ALIAS:
     return _value.alias->getStringValue();
   case BOOL:
-    if (GET_BOOL)
+    if (get_bool())
       return "true";
     else
       return "false";
   case INT:
-    sprintf(buf, "%d", GET_INT);
-    return buf;
+    sprintf(_buffer, "%d", get_int());
+    return _buffer;
   case LONG:
-    sprintf(buf, "%ld", GET_LONG);
-    return buf;
+    sprintf(_buffer, "%ld", get_long());
+    return _buffer;
   case FLOAT:
-    sprintf(buf, "%f", GET_FLOAT);
-    return buf;
+    sprintf(_buffer, "%f", get_float());
+    return _buffer;
   case DOUBLE:
-    sprintf(buf, "%f", GET_DOUBLE);
-    return buf;
+    sprintf(_buffer, "%f", get_double());
+    return _buffer;
   case STRING:
   case UNSPECIFIED:
-    return GET_STRING;
+    return get_string();
   case NONE:
   default:
     return "";
   }
 }
 
+/**
+ * Trace a write access for a property.
+ */
+void
+SGPropertyNode::trace_write () const
+{
+#if PROPS_STANDALONE
+  cerr << "TRACE: Write node " << getPath () << ", value\""
+       << make_string() << '"' << endl;
+#else
+  SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Write node " << getPath()
+        << ", value\"" << make_string() << '"');
+#endif
+}
 
 /**
  * Trace a read access for a property.
  */
 void
-SGPropertyNode::trace_read (SGPropertyNode::Type accessType) const
+SGPropertyNode::trace_read () const
 {
+#if PROPS_STANDALONE
+  cerr << "TRACE: Write node " << getPath () << ", value \""
+       << make_string() << '"' << endl;
+#else
   SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Read node " << getPath()
-        << ", value \"" << get_string() << '"');
+        << ", value \"" << make_string() << '"');
+#endif
 }
 
-
 /**
- * Trace a write access for a property.
+ * Increment reference counter
  */
 void
-SGPropertyNode::trace_write (SGPropertyNode::Type accessType) const
+SGPropertyNode::incrementRef()
 {
-  SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Write node " << getPath()
-        << ", value\"" << get_string() << '"');
+  ++_count;
+}
+
+/**
+ * Decrement reference counter
+ */
+int
+SGPropertyNode::decrementRef()
+{
+  return --_count;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Public methods from SGPropertyNode.
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * Last used attribute
+ * Update as needed when enum Attribute is changed
+ */
+const int SGPropertyNode::LAST_USED_ATTRIBUTE = TRACE_WRITE;
+
+/**
+ * Default constructor: always creates a root node.
+ */
+SGPropertyNode::SGPropertyNode ()
+  : _name(copy_string("")),
+    _display_name(0),
+    _index(0),
+    _parent(0),
+    _path(0),
+    _path_cache(0),
+    _type(NONE),
+    _tied(false),
+    _attr(READ|WRITE),
+    _count(0),
+    _listeners(0)
+{
+  _local_val.string_val = 0;
+}
+
+
+/**
+ * Copy constructor.
+ */
+SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
+  : _display_name(0),
+    _index(node._index),
+    _parent(0),                        // don't copy the parent
+    _path(0),
+    _path_cache(0),
+    _type(node._type),
+    _tied(node._tied),
+    _attr(node._attr),
+    _count(0),
+    _listeners(0)              // CHECK!!
+{
+  _name = copy_string(node._name);
+  _local_val.string_val = 0;
+  switch (_type) {
+  case NONE:
+    break;
+  case ALIAS:
+    _value.alias = node._value.alias;
+    _tied = false;
+    break;
+  case BOOL:
+    if (_tied) {
+      _tied = true;
+      _value.bool_val = node._value.bool_val->clone();
+    } else {
+      _tied = false;
+      set_bool(node.get_bool());
+    }
+    break;
+  case INT:
+    if (_tied) {
+      _tied = true;
+      _value.int_val = node._value.int_val->clone();
+    } else {
+      _tied = false;
+      set_int(node.get_int());
+    }
+    break;
+  case LONG:
+    if (_tied) {
+      _tied = true;
+      _value.long_val = node._value.long_val->clone();
+    } else {
+      _tied = false;
+      set_long(node.get_long());
+    }
+    break;
+  case FLOAT:
+    if (_tied) {
+      _tied = true;
+      _value.float_val = node._value.float_val->clone();
+    } else {
+      _tied = false;
+      set_float(node.get_float());
+    }
+    break;
+  case DOUBLE:
+    if (_tied) {
+      _tied = true;
+      _value.double_val = node._value.double_val->clone();
+    } else {
+      _tied = false;
+      set_double(node.get_double());
+    }
+    break;
+  case STRING:
+  case UNSPECIFIED:
+    if (_tied) {
+      _tied = true;
+      _value.string_val = node._value.string_val->clone();
+    } else {
+      _tied = false;
+      set_string(node.get_string());
+    }
+    break;
+  }
+}
+
+
+/**
+ * Convenience constructor.
+ */
+SGPropertyNode::SGPropertyNode (const char * name,
+                               int index,
+                               SGPropertyNode * parent)
+  : _display_name(0),
+    _index(index),
+    _parent(parent),
+    _path(0),
+    _path_cache(0),
+    _type(NONE),
+    _tied(false),
+    _attr(READ|WRITE),
+    _count(0),
+    _listeners(0)
+{
+  _name = copy_string(name);
+  _local_val.string_val = 0;
+}
+
+
+/**
+ * Destructor.
+ */
+SGPropertyNode::~SGPropertyNode ()
+{
+  delete [] _name;
+  delete [] _display_name;
+  delete [] _path;
+  delete _path_cache;
+  clear_value();
+  delete _listeners;
 }
 
 
@@ -498,7 +786,7 @@ SGPropertyNode::alias (SGPropertyNode * target)
  * Alias to another node by path.
  */
 bool
-SGPropertyNode::alias (const string &path)
+SGPropertyNode::alias (const char * path)
 {
   return alias(getNode(path, true));
 }
@@ -565,14 +853,26 @@ SGPropertyNode::getChild (int position) const
  * Get a non-const child by name and index, creating if necessary.
  */
 SGPropertyNode *
-SGPropertyNode::getChild (const string &name, int index, bool create)
+SGPropertyNode::getChild (const char * name, int index, bool create)
 {
   int pos = find_child(name, index, _children);
   if (pos >= 0) {
     return _children[pos];
   } else if (create) {
-    _children.push_back(new SGPropertyNode(name, index, this));
-    return _children[_children.size()-1];
+    SGPropertyNode_ptr node;
+    pos = find_child(name, index, _removedChildren);
+    if (pos >= 0) {
+      vector<SGPropertyNode_ptr>::iterator it = _removedChildren.begin();
+      it += pos;
+      node = _removedChildren[pos];
+      _removedChildren.erase(it);
+      node->setAttribute(REMOVED, false);
+    } else {
+      node = new SGPropertyNode(name, index, this);
+    }
+    _children.push_back(node);
+    fireChildAdded(node);
+    return node;
   } else {
     return 0;
   }
@@ -583,7 +883,7 @@ SGPropertyNode::getChild (const string &name, int index, bool create)
  * Get a const child by name and index.
  */
 const SGPropertyNode *
-SGPropertyNode::getChild (const string &name, int index) const
+SGPropertyNode::getChild (const char * name, int index) const
 {
   int pos = find_child(name, index, _children);
   if (pos >= 0)
@@ -596,14 +896,14 @@ SGPropertyNode::getChild (const string &name, int index) const
 /**
  * Get all children with the same name (but different indices).
  */
-vector<SGPropertyNode *>
-SGPropertyNode::getChildren (const string &name)
+vector<SGPropertyNode_ptr>
+SGPropertyNode::getChildren (const char * name) const
 {
-  vector<SGPropertyNode *> children;
+  vector<SGPropertyNode_ptr> children;
   int max = _children.size();
 
   for (int i = 0; i < max; i++)
-    if (_children[i]->getName() == name)
+    if (compare_strings(_children[i]->getName(), name))
       children.push_back(_children[i]);
 
   sort(children.begin(), children.end(), CompareIndices());
@@ -612,38 +912,60 @@ SGPropertyNode::getChildren (const string &name)
 
 
 /**
- * Get all children const with the same name (but different indices).
+ * Remove a child node
  */
-vector<const SGPropertyNode *>
-SGPropertyNode::getChildren (const string &name) const
+SGPropertyNode_ptr 
+SGPropertyNode::removeChild (const char * name, int index, bool keep)
 {
-  vector<const SGPropertyNode *> children;
-  int max = _children.size();
+  SGPropertyNode_ptr ret;
+  int pos = find_child(name, index, _children);
+  if (pos >= 0) {
+    vector<SGPropertyNode_ptr>::iterator it = _children.begin();
+    it += pos;
+    SGPropertyNode_ptr node = _children[pos];
+    _children.erase(it);
+    if (keep) {
+      _removedChildren.push_back(node);
+    }
+    node->setAttribute(REMOVED, true);
+    ret = node;
+    fireChildRemoved(node);
+  }
+  return ret;
+}
 
-  for (int i = 0; i < max; i++)
-    if (_children[i]->getName() == name)
-      children.push_back(_children[i]);
 
-  sort(children.begin(), children.end(), CompareIndices());
-  return children;
+const char *
+SGPropertyNode::getDisplayName (bool simplify) const
+{
+  string display = _name;
+  if (_index != 0 || !simplify) {
+    char buffer[64];
+    sprintf(buffer, "[%d]", _index);
+    display += buffer;
+  }
+  _display_name = copy_string(display.c_str());
+  return _display_name;
 }
 
 
-string
+const char *
 SGPropertyNode::getPath (bool simplify) const
 {
-  if (_parent == 0)
-    return "";
-
-  string path = _parent->getPath(simplify);
-  path += '/';
-  path += _name;
-  if (_index != 0 || !simplify) {
-    char buffer[128];
-    sprintf(buffer, "[%d]", _index);
-    path += buffer;
+                               // 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;
+
+  return _path;
 }
 
 SGPropertyNode::Type
@@ -659,153 +981,195 @@ SGPropertyNode::getType () const
 bool 
 SGPropertyNode::getBoolValue () const
 {
-  DO_TRACE_READ(BOOL);
-  TEST_READ(false);
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == BOOL)
+    return get_bool();
+
+  if (getAttribute(TRACE_READ))
+    trace_read();
+  if (!getAttribute(READ))
+    return SGRawValue<bool>::DefaultValue;
   switch (_type) {
   case ALIAS:
     return _value.alias->getBoolValue();
   case BOOL:
-    return GET_BOOL;
+    return get_bool();
   case INT:
-    return GET_INT == 0 ? false : true;
+    return get_int() == 0 ? false : true;
   case LONG:
-    return GET_LONG == 0L ? false : true;
+    return get_long() == 0L ? false : true;
   case FLOAT:
-    return GET_FLOAT == 0.0 ? false : true;
+    return get_float() == 0.0 ? false : true;
   case DOUBLE:
-    return GET_DOUBLE == 0.0L ? false : true;
+    return get_double() == 0.0L ? false : true;
   case STRING:
   case UNSPECIFIED:
-    return (GET_STRING == "true" || getDoubleValue() != 0.0L);
+    return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L);
   case NONE:
   default:
-    return false;
+    return SGRawValue<bool>::DefaultValue;
   }
 }
 
 int 
 SGPropertyNode::getIntValue () const
 {
-  DO_TRACE_READ(INT);
-  TEST_READ(0);
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == INT)
+    return get_int();
+
+  if (getAttribute(TRACE_READ))
+    trace_read();
+  if (!getAttribute(READ))
+    return SGRawValue<int>::DefaultValue;
   switch (_type) {
   case ALIAS:
     return _value.alias->getIntValue();
   case BOOL:
-    return int(GET_BOOL);
+    return int(get_bool());
   case INT:
-    return GET_INT;
+    return get_int();
   case LONG:
-    return int(GET_LONG);
+    return int(get_long());
   case FLOAT:
-    return int(GET_FLOAT);
+    return int(get_float());
   case DOUBLE:
-    return int(GET_DOUBLE);
+    return int(get_double());
   case STRING:
   case UNSPECIFIED:
-    return atoi(GET_STRING.c_str());
+    return atoi(get_string());
   case NONE:
   default:
-    return 0;
+    return SGRawValue<int>::DefaultValue;
   }
 }
 
 long 
 SGPropertyNode::getLongValue () const
 {
-  DO_TRACE_READ(LONG);
-  TEST_READ(0L);
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == LONG)
+    return get_long();
+
+  if (getAttribute(TRACE_READ))
+    trace_read();
+  if (!getAttribute(READ))
+    return SGRawValue<long>::DefaultValue;
   switch (_type) {
   case ALIAS:
     return _value.alias->getLongValue();
   case BOOL:
-    return long(GET_BOOL);
+    return long(get_bool());
   case INT:
-    return long(GET_INT);
+    return long(get_int());
   case LONG:
-    return GET_LONG;
+    return get_long();
   case FLOAT:
-    return long(GET_FLOAT);
+    return long(get_float());
   case DOUBLE:
-    return long(GET_DOUBLE);
+    return long(get_double());
   case STRING:
   case UNSPECIFIED:
-    return strtol(GET_STRING.c_str(), 0, 0);
+    return strtol(get_string(), 0, 0);
   case NONE:
   default:
-    return 0L;
+    return SGRawValue<long>::DefaultValue;
   }
 }
 
 float 
 SGPropertyNode::getFloatValue () const
 {
-  DO_TRACE_READ(FLOAT);
-  TEST_READ(0.0);
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == FLOAT)
+    return get_float();
+
+  if (getAttribute(TRACE_READ))
+    trace_read();
+  if (!getAttribute(READ))
+    return SGRawValue<float>::DefaultValue;
   switch (_type) {
   case ALIAS:
     return _value.alias->getFloatValue();
   case BOOL:
-    return float(GET_BOOL);
+    return float(get_bool());
   case INT:
-    return float(GET_INT);
+    return float(get_int());
   case LONG:
-    return float(GET_LONG);
+    return float(get_long());
   case FLOAT:
-    return GET_FLOAT;
+    return get_float();
   case DOUBLE:
-    return float(GET_DOUBLE);
+    return float(get_double());
   case STRING:
   case UNSPECIFIED:
-    return atof(GET_STRING.c_str());
+    return atof(get_string());
   case NONE:
   default:
-    return 0.0;
+    return SGRawValue<float>::DefaultValue;
   }
 }
 
 double 
 SGPropertyNode::getDoubleValue () const
 {
-  DO_TRACE_READ(DOUBLE);
-  TEST_READ(0.0L);
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == DOUBLE)
+    return get_double();
+
+  if (getAttribute(TRACE_READ))
+    trace_read();
+  if (!getAttribute(READ))
+    return SGRawValue<double>::DefaultValue;
+
   switch (_type) {
   case ALIAS:
     return _value.alias->getDoubleValue();
   case BOOL:
-    return double(GET_BOOL);
+    return double(get_bool());
   case INT:
-    return double(GET_INT);
+    return double(get_int());
   case LONG:
-    return double(GET_LONG);
+    return double(get_long());
   case FLOAT:
-    return double(GET_FLOAT);
+    return double(get_float());
   case DOUBLE:
-    return GET_DOUBLE;
+    return get_double();
   case STRING:
   case UNSPECIFIED:
-    return strtod(GET_STRING.c_str(), 0);
+    return strtod(get_string(), 0);
   case NONE:
   default:
-    return 0.0L;
+    return SGRawValue<double>::DefaultValue;
   }
 }
 
-string
+const char *
 SGPropertyNode::getStringValue () const
 {
-  DO_TRACE_READ(STRING);
-  return get_string();
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == STRING)
+    return get_string();
+
+  if (getAttribute(TRACE_READ))
+    trace_read();
+  if (!getAttribute(READ))
+    return SGRawValue<const char *>::DefaultValue;
+  return make_string();
 }
 
 bool
 SGPropertyNode::setBoolValue (bool value)
 {
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == BOOL)
+    return set_bool(value);
+
   bool result = false;
   TEST_WRITE;
   if (_type == NONE || _type == UNSPECIFIED) {
     clear_value();
-    _value.bool_val = new SGRawValueInternal<bool>;
+    _tied = false;
     _type = BOOL;
   }
 
@@ -814,42 +1178,47 @@ SGPropertyNode::setBoolValue (bool value)
     result = _value.alias->setBoolValue(value);
     break;
   case BOOL:
-    result = SET_BOOL(value);
+    result = set_bool(value);
     break;
   case INT:
-    result = SET_INT(int(value));
+    result = set_int(int(value));
     break;
   case LONG:
-    result = SET_LONG(long(value));
+    result = set_long(long(value));
     break;
   case FLOAT:
-    result = SET_FLOAT(float(value));
+    result = set_float(float(value));
     break;
   case DOUBLE:
-    result = SET_DOUBLE(double(value));
+    result = set_double(double(value));
     break;
   case STRING:
   case UNSPECIFIED:
-    result = SET_STRING(value ? "true" : "false");
+    result = set_string(value ? "true" : "false");
     break;
   case NONE:
   default:
     break;
   }
 
-  DO_TRACE_WRITE(BOOL);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
 bool
 SGPropertyNode::setIntValue (int value)
 {
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == INT)
+    return set_int(value);
+
   bool result = false;
   TEST_WRITE;
   if (_type == NONE || _type == UNSPECIFIED) {
     clear_value();
-    _value.int_val = new SGRawValueInternal<int>;
     _type = INT;
+    _local_val.int_val = 0;
   }
 
   switch (_type) {
@@ -857,25 +1226,25 @@ SGPropertyNode::setIntValue (int value)
     result = _value.alias->setIntValue(value);
     break;
   case BOOL:
-    result = SET_BOOL(value == 0 ? false : true);
+    result = set_bool(value == 0 ? false : true);
     break;
   case INT:
-    result = SET_INT(value);
+    result = set_int(value);
     break;
   case LONG:
-    result = SET_LONG(long(value));
+    result = set_long(long(value));
     break;
   case FLOAT:
-    result = SET_FLOAT(float(value));
+    result = set_float(float(value));
     break;
   case DOUBLE:
-    result = SET_DOUBLE(double(value));
+    result = set_double(double(value));
     break;
   case STRING:
   case UNSPECIFIED: {
     char buf[128];
     sprintf(buf, "%d", value);
-    result = SET_STRING(buf);
+    result = set_string(buf);
     break;
   }
   case NONE:
@@ -883,19 +1252,24 @@ SGPropertyNode::setIntValue (int value)
     break;
   }
 
-  DO_TRACE_WRITE(INT);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
 bool
 SGPropertyNode::setLongValue (long value)
 {
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == LONG)
+    return set_long(value);
+
   bool result = false;
   TEST_WRITE;
   if (_type == NONE || _type == UNSPECIFIED) {
     clear_value();
-    _value.long_val = new SGRawValueInternal<long>;
     _type = LONG;
+    _local_val.long_val = 0L;
   }
 
   switch (_type) {
@@ -903,25 +1277,25 @@ SGPropertyNode::setLongValue (long value)
     result = _value.alias->setLongValue(value);
     break;
   case BOOL:
-    result = SET_BOOL(value == 0L ? false : true);
+    result = set_bool(value == 0L ? false : true);
     break;
   case INT:
-    result = SET_INT(int(value));
+    result = set_int(int(value));
     break;
   case LONG:
-    result = SET_LONG(value);
+    result = set_long(value);
     break;
   case FLOAT:
-    result = SET_FLOAT(float(value));
+    result = set_float(float(value));
     break;
   case DOUBLE:
-    result = SET_DOUBLE(double(value));
+    result = set_double(double(value));
     break;
   case STRING:
   case UNSPECIFIED: {
     char buf[128];
     sprintf(buf, "%ld", value);
-    result = SET_STRING(buf);
+    result = set_string(buf);
     break;
   }
   case NONE:
@@ -929,19 +1303,24 @@ SGPropertyNode::setLongValue (long value)
     break;
   }
 
-  DO_TRACE_WRITE(LONG);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
 bool
 SGPropertyNode::setFloatValue (float value)
 {
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == FLOAT)
+    return set_float(value);
+
   bool result = false;
   TEST_WRITE;
   if (_type == NONE || _type == UNSPECIFIED) {
     clear_value();
-    _value.float_val = new SGRawValueInternal<float>;
     _type = FLOAT;
+    _local_val.float_val = 0;
   }
 
   switch (_type) {
@@ -949,25 +1328,25 @@ SGPropertyNode::setFloatValue (float value)
     result = _value.alias->setFloatValue(value);
     break;
   case BOOL:
-    result = SET_BOOL(value == 0.0 ? false : true);
+    result = set_bool(value == 0.0 ? false : true);
     break;
   case INT:
-    result = SET_INT(int(value));
+    result = set_int(int(value));
     break;
   case LONG:
-    result = SET_LONG(long(value));
+    result = set_long(long(value));
     break;
   case FLOAT:
-    result = SET_FLOAT(value);
+    result = set_float(value);
     break;
   case DOUBLE:
-    result = SET_DOUBLE(double(value));
+    result = set_double(double(value));
     break;
   case STRING:
   case UNSPECIFIED: {
     char buf[128];
     sprintf(buf, "%f", value);
-    result = SET_STRING(buf);
+    result = set_string(buf);
     break;
   }
   case NONE:
@@ -975,18 +1354,23 @@ SGPropertyNode::setFloatValue (float value)
     break;
   }
 
-  DO_TRACE_WRITE(FLOAT);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
 bool
 SGPropertyNode::setDoubleValue (double value)
 {
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == DOUBLE)
+    return set_double(value);
+
   bool result = false;
   TEST_WRITE;
   if (_type == NONE || _type == UNSPECIFIED) {
     clear_value();
-    _value.double_val = new SGRawValueInternal<double>;
+    _local_val.double_val = value;
     _type = DOUBLE;
   }
 
@@ -995,25 +1379,25 @@ SGPropertyNode::setDoubleValue (double value)
     result = _value.alias->setDoubleValue(value);
     break;
   case BOOL:
-    result = SET_BOOL(value == 0.0L ? false : true);
+    result = set_bool(value == 0.0L ? false : true);
     break;
   case INT:
-    result = SET_INT(int(value));
+    result = set_int(int(value));
     break;
   case LONG:
-    result = SET_LONG(long(value));
+    result = set_long(long(value));
     break;
   case FLOAT:
-    result = SET_FLOAT(float(value));
+    result = set_float(float(value));
     break;
   case DOUBLE:
-    result = SET_DOUBLE(value);
+    result = set_double(value);
     break;
   case STRING:
   case UNSPECIFIED: {
     char buf[128];
     sprintf(buf, "%f", value);
-    result = SET_STRING(buf);
+    result = set_string(buf);
     break;
   }
   case NONE:
@@ -1021,18 +1405,22 @@ SGPropertyNode::setDoubleValue (double value)
     break;
   }
 
-  DO_TRACE_WRITE(DOUBLE);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
 bool
-SGPropertyNode::setStringValue (string value)
+SGPropertyNode::setStringValue (const char * value)
 {
+                               // Shortcut for common case
+  if (_attr == (READ|WRITE) && _type == STRING)
+    return set_string(value);
+
   bool result = false;
   TEST_WRITE;
   if (_type == NONE || _type == UNSPECIFIED) {
     clear_value();
-    _value.string_val = new SGRawValueInternal<string>;
     _type = STRING;
   }
 
@@ -1041,41 +1429,42 @@ SGPropertyNode::setStringValue (string value)
     result = _value.alias->setStringValue(value);
     break;
   case BOOL:
-    result = SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
+    result = set_bool((compare_strings(value, "true")
+                      || atoi(value)) ? true : false);
     break;
   case INT:
-    result = SET_INT(atoi(value.c_str()));
+    result = set_int(atoi(value));
     break;
   case LONG:
-    result = SET_LONG(strtol(value.c_str(), 0, 0));
+    result = set_long(strtol(value, 0, 0));
     break;
   case FLOAT:
-    result = SET_FLOAT(atof(value.c_str()));
+    result = set_float(atof(value));
     break;
   case DOUBLE:
-    result = SET_DOUBLE(strtod(value.c_str(), 0));
+    result = set_double(strtod(value, 0));
     break;
   case STRING:
   case UNSPECIFIED:
-    result = SET_STRING(value);
+    result = set_string(value);
     break;
   case NONE:
   default:
     break;
   }
 
-  DO_TRACE_WRITE(STRING);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
 bool
-SGPropertyNode::setUnspecifiedValue (string value)
+SGPropertyNode::setUnspecifiedValue (const char * value)
 {
   bool result = false;
   TEST_WRITE;
   if (_type == NONE) {
     clear_value();
-    _value.string_val = new SGRawValueInternal<string>;
     _type = UNSPECIFIED;
   }
 
@@ -1084,30 +1473,32 @@ SGPropertyNode::setUnspecifiedValue (string value)
     result = _value.alias->setUnspecifiedValue(value);
     break;
   case BOOL:
-    result = SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
+    result = set_bool((compare_strings(value, "true")
+                      || atoi(value)) ? true : false);
     break;
   case INT:
-    result = SET_INT(atoi(value.c_str()));
+    result = set_int(atoi(value));
     break;
   case LONG:
-    result = SET_LONG(strtol(value.c_str(), 0, 0));
+    result = set_long(strtol(value, 0, 0));
     break;
   case FLOAT:
-    result = SET_FLOAT(atof(value.c_str()));
+    result = set_float(atof(value));
     break;
   case DOUBLE:
-    result = SET_DOUBLE(strtod(value.c_str(), 0));
+    result = set_double(strtod(value, 0));
     break;
   case STRING:
   case UNSPECIFIED:
-    result = SET_STRING(value);
+    result = set_string(value);
     break;
   case NONE:
   default:
     break;
   }
 
-  DO_TRACE_WRITE(UNSPECIFIED);
+  if (getAttribute(TRACE_WRITE))
+    trace_write();
   return result;
 }
 
@@ -1223,7 +1614,7 @@ SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
 }
 
 bool
-SGPropertyNode::tie (const SGRawValue<string> &rawValue, bool useDefault)
+SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool useDefault)
 {
   if (_type == ALIAS || _tied)
     return false;
@@ -1239,7 +1630,7 @@ SGPropertyNode::tie (const SGRawValue<string> &rawValue, bool useDefault)
   _value.string_val = rawValue.clone();
 
   if (useDefault)
-    setStringValue(old_val);
+    setStringValue(old_val.c_str());
 
   return true;
 }
@@ -1255,40 +1646,35 @@ SGPropertyNode::untie ()
     bool val = getBoolValue();
     clear_value();
     _type = BOOL;
-    _value.bool_val = new SGRawValueInternal<bool>;
-    SET_BOOL(val);
+    _local_val.bool_val = val;
     break;
   }
   case INT: {
     int val = getIntValue();
     clear_value();
     _type = INT;
-    _value.int_val = new SGRawValueInternal<int>;
-    SET_INT(val);
+    _local_val.int_val = val;
     break;
   }
   case LONG: {
     long val = getLongValue();
     clear_value();
     _type = LONG;
-    _value.long_val = new SGRawValueInternal<long>;
-    SET_LONG(val);
+    _local_val.long_val = val;
     break;
   }
   case FLOAT: {
     float val = getFloatValue();
     clear_value();
     _type = FLOAT;
-    _value.float_val = new SGRawValueInternal<float>;
-    SET_FLOAT(val);
+    _local_val.float_val = val;
     break;
   }
   case DOUBLE: {
     double val = getDoubleValue();
     clear_value();
     _type = DOUBLE;
-    _value.double_val = new SGRawValueInternal<double>;
-    SET_DOUBLE(val);
+    _local_val.double_val = val;
     break;
   }
   case STRING:
@@ -1296,8 +1682,7 @@ SGPropertyNode::untie ()
     string val = getStringValue();
     clear_value();
     _type = STRING;
-    _value.string_val = new SGRawValueInternal<string>;
-    SET_STRING(val);
+    _local_val.string_val = copy_string(val.c_str());
     break;
   }
   case NONE:
@@ -1328,25 +1713,25 @@ SGPropertyNode::getRootNode () const
 }
 
 SGPropertyNode *
-SGPropertyNode::getNode (const string &relative_path, bool create)
+SGPropertyNode::getNode (const char * relative_path, bool create)
 {
   if (_path_cache == 0)
-    _path_cache = new cache_map;
+    _path_cache = new hash_table;
 
-  SGPropertyNode * result = (*_path_cache)[relative_path];
+  SGPropertyNode * result = _path_cache->get(relative_path);
   if (result == 0) {
     vector<PathComponent> components;
     parse_path(relative_path, components);
     result = find_node(this, components, 0, create);
     if (result != 0)
-      (*_path_cache)[relative_path] = result;
+      _path_cache->put(relative_path, result);
   }
   
   return result;
 }
 
 SGPropertyNode *
-SGPropertyNode::getNode (const string &relative_path, int index, bool create)
+SGPropertyNode::getNode (const char * relative_path, int index, bool create)
 {
   vector<PathComponent> components;
   parse_path(relative_path, components);
@@ -1356,13 +1741,13 @@ SGPropertyNode::getNode (const string &relative_path, int index, bool create)
 }
 
 const SGPropertyNode *
-SGPropertyNode::getNode (const string &relative_path) const
+SGPropertyNode::getNode (const char * relative_path) const
 {
   return ((SGPropertyNode *)this)->getNode(relative_path, false);
 }
 
 const SGPropertyNode *
-SGPropertyNode::getNode (const string &relative_path, int index) const
+SGPropertyNode::getNode (const char * relative_path, int index) const
 {
   return ((SGPropertyNode *)this)->getNode(relative_path, index, false);
 }
@@ -1377,7 +1762,7 @@ SGPropertyNode::getNode (const string &relative_path, int index) const
  * Test whether another node has a value attached.
  */
 bool
-SGPropertyNode::hasValue (const string &relative_path) const
+SGPropertyNode::hasValue (const char * relative_path) const
 {
   const SGPropertyNode * node = getNode(relative_path);
   return (node == 0 ? false : node->hasValue());
@@ -1388,7 +1773,7 @@ SGPropertyNode::hasValue (const string &relative_path) const
  * Get the value type for another node.
  */
 SGPropertyNode::Type
-SGPropertyNode::getType (const string &relative_path) const
+SGPropertyNode::getType (const char * relative_path) const
 {
   const SGPropertyNode * node = getNode(relative_path);
   return (node == 0 ? UNSPECIFIED : (Type)(node->getType()));
@@ -1399,7 +1784,7 @@ SGPropertyNode::getType (const string &relative_path) const
  * Get a bool value for another node.
  */
 bool
-SGPropertyNode::getBoolValue (const string &relative_path,
+SGPropertyNode::getBoolValue (const char * relative_path,
                              bool defaultValue) const
 {
   const SGPropertyNode * node = getNode(relative_path);
@@ -1411,7 +1796,7 @@ SGPropertyNode::getBoolValue (const string &relative_path,
  * Get an int value for another node.
  */
 int
-SGPropertyNode::getIntValue (const string &relative_path,
+SGPropertyNode::getIntValue (const char * relative_path,
                             int defaultValue) const
 {
   const SGPropertyNode * node = getNode(relative_path);
@@ -1423,7 +1808,7 @@ SGPropertyNode::getIntValue (const string &relative_path,
  * Get a long value for another node.
  */
 long
-SGPropertyNode::getLongValue (const string &relative_path,
+SGPropertyNode::getLongValue (const char * relative_path,
                              long defaultValue) const
 {
   const SGPropertyNode * node = getNode(relative_path);
@@ -1435,7 +1820,7 @@ SGPropertyNode::getLongValue (const string &relative_path,
  * Get a float value for another node.
  */
 float
-SGPropertyNode::getFloatValue (const string &relative_path,
+SGPropertyNode::getFloatValue (const char * relative_path,
                               float defaultValue) const
 {
   const SGPropertyNode * node = getNode(relative_path);
@@ -1447,7 +1832,7 @@ SGPropertyNode::getFloatValue (const string &relative_path,
  * Get a double value for another node.
  */
 double
-SGPropertyNode::getDoubleValue (const string &relative_path,
+SGPropertyNode::getDoubleValue (const char * relative_path,
                                double defaultValue) const
 {
   const SGPropertyNode * node = getNode(relative_path);
@@ -1458,9 +1843,9 @@ SGPropertyNode::getDoubleValue (const string &relative_path,
 /**
  * Get a string value for another node.
  */
-string
-SGPropertyNode::getStringValue (const string &relative_path,
-                               string defaultValue) const
+const char *
+SGPropertyNode::getStringValue (const char * relative_path,
+                               const char * defaultValue) const
 {
   const SGPropertyNode * node = getNode(relative_path);
   return (node == 0 ? defaultValue : node->getStringValue());
@@ -1471,7 +1856,7 @@ SGPropertyNode::getStringValue (const string &relative_path,
  * Set a bool value for another node.
  */
 bool
-SGPropertyNode::setBoolValue (const string &relative_path, bool value)
+SGPropertyNode::setBoolValue (const char * relative_path, bool value)
 {
   return getNode(relative_path, true)->setBoolValue(value);
 }
@@ -1481,7 +1866,7 @@ SGPropertyNode::setBoolValue (const string &relative_path, bool value)
  * Set an int value for another node.
  */
 bool
-SGPropertyNode::setIntValue (const string &relative_path, int value)
+SGPropertyNode::setIntValue (const char * relative_path, int value)
 {
   return getNode(relative_path, true)->setIntValue(value);
 }
@@ -1491,7 +1876,7 @@ SGPropertyNode::setIntValue (const string &relative_path, int value)
  * Set a long value for another node.
  */
 bool
-SGPropertyNode::setLongValue (const string &relative_path, long value)
+SGPropertyNode::setLongValue (const char * relative_path, long value)
 {
   return getNode(relative_path, true)->setLongValue(value);
 }
@@ -1501,7 +1886,7 @@ SGPropertyNode::setLongValue (const string &relative_path, long value)
  * Set a float value for another node.
  */
 bool
-SGPropertyNode::setFloatValue (const string &relative_path, float value)
+SGPropertyNode::setFloatValue (const char * relative_path, float value)
 {
   return getNode(relative_path, true)->setFloatValue(value);
 }
@@ -1511,7 +1896,7 @@ SGPropertyNode::setFloatValue (const string &relative_path, float value)
  * Set a double value for another node.
  */
 bool
-SGPropertyNode::setDoubleValue (const string &relative_path, double value)
+SGPropertyNode::setDoubleValue (const char * relative_path, double value)
 {
   return getNode(relative_path, true)->setDoubleValue(value);
 }
@@ -1521,7 +1906,7 @@ SGPropertyNode::setDoubleValue (const string &relative_path, double value)
  * Set a string value for another node.
  */
 bool
-SGPropertyNode::setStringValue (const string &relative_path, string value)
+SGPropertyNode::setStringValue (const char * relative_path, const char * value)
 {
   return getNode(relative_path, true)->setStringValue(value);
 }
@@ -1531,7 +1916,8 @@ SGPropertyNode::setStringValue (const string &relative_path, string value)
  * Set an unknown value for another node.
  */
 bool
-SGPropertyNode::setUnspecifiedValue (const string &relative_path, string value)
+SGPropertyNode::setUnspecifiedValue (const char * relative_path,
+                                    const char * value)
 {
   return getNode(relative_path, true)->setUnspecifiedValue(value);
 }
@@ -1541,7 +1927,7 @@ SGPropertyNode::setUnspecifiedValue (const string &relative_path, string value)
  * Test whether another node is tied.
  */
 bool
-SGPropertyNode::isTied (const string &relative_path) const
+SGPropertyNode::isTied (const char * relative_path) const
 {
   const SGPropertyNode * node = getNode(relative_path);
   return (node == 0 ? false : node->isTied());
@@ -1552,7 +1938,7 @@ SGPropertyNode::isTied (const string &relative_path) const
  * Tie a node reached by a relative path, creating it if necessary.
  */
 bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
                     const SGRawValue<bool> &rawValue,
                     bool useDefault)
 {
@@ -1564,7 +1950,7 @@ SGPropertyNode::tie (const string &relative_path,
  * Tie a node reached by a relative path, creating it if necessary.
  */
 bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
                     const SGRawValue<int> &rawValue,
                     bool useDefault)
 {
@@ -1576,7 +1962,7 @@ SGPropertyNode::tie (const string &relative_path,
  * Tie a node reached by a relative path, creating it if necessary.
  */
 bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
                     const SGRawValue<long> &rawValue,
                     bool useDefault)
 {
@@ -1588,7 +1974,7 @@ SGPropertyNode::tie (const string &relative_path,
  * Tie a node reached by a relative path, creating it if necessary.
  */
 bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
                     const SGRawValue<float> &rawValue,
                     bool useDefault)
 {
@@ -1600,7 +1986,7 @@ SGPropertyNode::tie (const string &relative_path,
  * Tie a node reached by a relative path, creating it if necessary.
  */
 bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
                     const SGRawValue<double> &rawValue,
                     bool useDefault)
 {
@@ -1612,8 +1998,8 @@ SGPropertyNode::tie (const string &relative_path,
  * Tie a node reached by a relative path, creating it if necessary.
  */
 bool
-SGPropertyNode::tie (const string &relative_path,
-                    const SGRawValue<string> &rawValue,
+SGPropertyNode::tie (const char * relative_path,
+                    const SGRawValue<const char *> &rawValue,
                     bool useDefault)
 {
   return getNode(relative_path, true)->tie(rawValue, useDefault);
@@ -1624,10 +2010,365 @@ SGPropertyNode::tie (const string &relative_path,
  * Attempt to untie another node reached by a relative path.
  */
 bool
-SGPropertyNode::untie (const string &relative_path)
+SGPropertyNode::untie (const char * relative_path)
 {
   SGPropertyNode * node = getNode(relative_path);
   return (node == 0 ? false : node->untie());
 }
 
+void
+SGPropertyNode::addChangeListener (SGPropertyChangeListener * listener)
+{
+  if (_listeners == 0)
+    _listeners = new vector<SGPropertyChangeListener *>;
+  _listeners->push_back(listener);
+  listener->register_property(this);
+}
+
+void
+SGPropertyNode::removeChangeListener (SGPropertyChangeListener * listener)
+{
+  vector<SGPropertyChangeListener *>::iterator it =
+    find(_listeners->begin(), _listeners->end(), listener);
+  if (it != _listeners->end()) {
+    _listeners->erase(it);
+    listener->unregister_property(this);
+    if (_listeners->empty()) {
+      vector<SGPropertyChangeListener *> * tmp = _listeners;
+      _listeners = 0;
+      delete tmp;
+    }
+  }
+}
+
+void
+SGPropertyNode::fireValueChanged ()
+{
+  fireValueChanged(this);
+}
+
+void
+SGPropertyNode::fireChildAdded (SGPropertyNode * child)
+{
+  fireChildAdded(this, child);
+}
+
+void
+SGPropertyNode::fireChildRemoved (SGPropertyNode * child)
+{
+  fireChildRemoved(this, child);
+}
+
+void
+SGPropertyNode::fireValueChanged (SGPropertyNode * node)
+{
+  if (_listeners != 0) {
+    for (unsigned int i = 0; i < _listeners->size(); i++) {
+      (*_listeners)[i]->valueChanged(node);
+    }
+  }
+  if (_parent != 0)
+    _parent->fireValueChanged(node);
+}
+
+void
+SGPropertyNode::fireChildAdded (SGPropertyNode * parent,
+                               SGPropertyNode * child)
+{
+  if (_listeners != 0) {
+    for (unsigned int i = 0; i < _listeners->size(); i++) {
+      (*_listeners)[i]->childAdded(parent, child);
+    }
+  }
+  if (_parent != 0)
+    _parent->fireChildAdded(parent, child);
+}
+
+void
+SGPropertyNode::fireChildRemoved (SGPropertyNode * parent,
+                                 SGPropertyNode * child)
+{
+  if (_listeners != 0) {
+    for (unsigned int i = 0; i < _listeners->size(); i++) {
+      (*_listeners)[i]->childRemoved(parent, child);
+    }
+  }
+  if (_parent != 0)
+    _parent->fireChildRemoved(parent, child);
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Simplified hash table for caching paths.
+////////////////////////////////////////////////////////////////////////
+
+#define HASH_TABLE_SIZE 199
+
+SGPropertyNode::hash_table::entry::entry ()
+  : _key(0),
+    _value(0)
+{
+}
+
+SGPropertyNode::hash_table::entry::~entry ()
+{
+                               // Don't delete the value; we don't own
+                               // the pointer.
+  delete [] _key;
+}
+
+void
+SGPropertyNode::hash_table::entry::set_key (const char * key)
+{
+  _key = copy_string(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];
+}
+
+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;
+  }
+}
+
+
+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];
+}
+
+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);
+}
+
+unsigned int
+SGPropertyNode::hash_table::hashcode (const char * key)
+{
+  unsigned int hash = 0;
+  while (*key != 0) {
+    hash = 31 * hash + *key;
+    key++;
+  }
+  return hash;
+}
+
+
+
+/**
+ * Default constructor
+ */
+SGPropertyNode_ptr::SGPropertyNode_ptr()
+{
+  _ptr = 0;
+}
+
+/**
+ * Copy constructor
+ */
+SGPropertyNode_ptr::SGPropertyNode_ptr( const SGPropertyNode_ptr &r )
+{
+  _ptr = r._ptr;
+  if (_ptr)
+     _ptr->incrementRef();
+}
+
+/**
+ * Constructor from a pointer to a node
+ */
+SGPropertyNode_ptr::SGPropertyNode_ptr( SGPropertyNode *p )
+{
+  _ptr = p;
+  if (_ptr)
+     _ptr->incrementRef();
+}
+
+/**
+ * Destructor
+ */
+SGPropertyNode_ptr::~SGPropertyNode_ptr()
+{
+  if (_ptr && _ptr->decrementRef() == 0)
+    delete _ptr;
+}
+
+/**
+ * Assignement operator
+ */
+SGPropertyNode_ptr &
+SGPropertyNode_ptr::operator=( const SGPropertyNode_ptr &r )
+{
+  if (_ptr && _ptr->decrementRef() == 0)
+    delete _ptr;
+  _ptr = r._ptr;
+  if (_ptr)
+     _ptr->incrementRef();
+
+  return *this;
+}
+
+/**
+ * Pointer access operator
+ */
+SGPropertyNode *
+SGPropertyNode_ptr::operator->()
+{
+  return _ptr;
+}
+
+/**
+ * Pointer access operator (const)
+ */
+const SGPropertyNode *
+SGPropertyNode_ptr::operator->() const
+{
+  return _ptr;
+}
+
+/**
+ * Conversion to SGPropertyNode * operator
+ */
+SGPropertyNode_ptr::operator SGPropertyNode *()
+{
+  return _ptr;
+}
+
+/**
+ * Conversion to const SGPropertyNode * operator
+ */
+SGPropertyNode_ptr::operator const SGPropertyNode *() const
+{
+  return _ptr;
+}
+
+/**
+ * Validity test
+ */
+bool 
+SGPropertyNode_ptr::valid() const
+{
+  return _ptr != 0;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of SGPropertyChangeListener.
+////////////////////////////////////////////////////////////////////////
+
+SGPropertyChangeListener::~SGPropertyChangeListener ()
+{
+                               // This will come back and remove
+                               // the current item each time.  Is
+                               // that OK?
+  vector<SGPropertyNode *>::iterator it;
+  for (it = _properties.begin(); it != _properties.end(); it++)
+    (*it)->removeChangeListener(this);
+}
+
+void
+SGPropertyChangeListener::valueChanged (SGPropertyNode * node)
+{
+  // NO-OP
+}
+
+void
+SGPropertyChangeListener::childAdded (SGPropertyNode * node,
+                                     SGPropertyNode * child)
+{
+  // NO-OP
+}
+
+void
+SGPropertyChangeListener::childRemoved (SGPropertyNode * parent,
+                                       SGPropertyNode * child)
+{
+  // NO-OP
+}
+
+void
+SGPropertyChangeListener::register_property (SGPropertyNode * node)
+{
+  _properties.push_back(node);
+}
+
+void
+SGPropertyChangeListener::unregister_property (SGPropertyNode * node)
+{
+  vector<SGPropertyNode *>::iterator it =
+    find(_properties.begin(), _properties.end(), node);
+  if (it != _properties.end())
+    _properties.erase(it);
+}
+
+
 // end of props.cxx