]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props.cxx
Use plib rad/degrees conversion constants.
[simgear.git] / simgear / misc / props.cxx
index cbc3306865648512c8dd1706b419232dbf9bc3ba..1fbfb31100f3c93dcd08171d54808cfc983185fc 100644 (file)
-// props.cxx -- implementation of FGFS global properties.
+// props.cxx - implementation of a property list.
+// Started Fall 2000 by David Megginson, david@megginson.com
+// This code is released into the Public Domain.
 //
-// Copyright (C) 2000  David Megginson - david@megginson.com
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// See props.html for documentation [replace with URL when available].
 //
 // $Id$
 
 #ifdef HAVE_CONFIG_H
-#  include <config.h>
+#include <config.h>
 #endif
 
-#include <simgear/debug/logstream.hxx>
+#include <simgear/compiler.h>
 
+#include <stdio.h>
+#include <stdlib.h>
+#include STL_IOSTREAM
+#include <algorithm>
 #include "props.hxx"
 
-#include <stdlib.h>
+SG_USING_STD(sort);
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Local classes.
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * Comparator class for sorting by index.
+ */
+class CompareIndices
+{
+public:
+  int operator() (const SGPropertyNode * n1, const SGPropertyNode *n2) const {
+    return (n1->getIndex() < n2->getIndex());
+  }
+};
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Convenience macros for value access.
+////////////////////////////////////////////////////////////////////////
+
+#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
+////////////////////////////////////////////////////////////////////////
+// Default values for every type.
+////////////////////////////////////////////////////////////////////////
+
+const bool SGRawValue<bool>::DefaultValue = false;
+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 = "";
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Local path normalization code.
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * A component in a path.
+ */
+struct PathComponent
+{
+  string name;
+  int index;
+};
+
+/**
+ * Parse the name for a path component.
+ *
+ * Name: [_a-zA-Z][-._a-zA-Z0-9]*
+ */
+static inline string
+parse_name (const string &path, int &i)
+{
+  string name = "";
+  int max = path.size();
+
+  if (path[i] == '.') {
+    i++;
+    if (i < max && path[i] == '.') {
+      i++;
+      name = "..";
+    } else {
+      name = ".";
+    }
+    if (i < max && path[i] != '/')
+      throw string(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 = 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 ']')");
+}
 
-#include <string>
 
-using std::string;
+/**
+ * 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 = 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++;
+  }
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Other static utility functions.
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Locate a child node by name and index.
+ */
+static int
+find_child (const string &name, int index, vector<SGPropertyNode *> nodes)
+{
+  int nNodes = nodes.size();
+  for (int i = 0; i < nNodes; i++) {
+    SGPropertyNode * node = nodes[i];
+    if (node->getName() == name && node->getIndex() == index)
+      return i;
+  }
+  return -1;
+}
+
+
+/**
+ * Locate another node, given a relative path.
+ */
+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;
+  }
+
+                               // 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);
+  }
 
-FGPropertyList current_properties;
+                               // .. 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);
+  }
 
-static string empty_string;
+                               // Otherwise, a child name
+  else {
+    SGPropertyNode * child =
+      current->getChild(components[position].name,
+                       components[position].index,
+                       create);
+    return find_node(child, components, position + 1, create);
+  }
+}
 
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Implementation of FGValue.
+// Implementation of SGValue.
 ////////////////////////////////////////////////////////////////////////
 
 
 /**
- * Construct a new value.
+ * Default constructor.
+ *
+ * The type will be UNKNOWN and the raw value will be "".
  */
-FGValue::FGValue ()
+SGValue::SGValue ()
   : _type(UNKNOWN), _tied(false)
 {
+  _value.string_val = new SGRawValueInternal<string>;
+}
+
+
+/**
+ * Copy constructor.
+ */
+SGValue::SGValue (const SGValue &source)
+{
+  _type = source._type;
+  _tied = source._tied;
+  switch (source._type) {
+  case ALIAS:
+                               // FIXME!!!
+    _value.alias = (SGValue *)(source.getAlias());
+    break;
+  case BOOL:
+    _value.bool_val = source._value.bool_val->clone();
+    break;
+  case INT:
+    _value.int_val = source._value.int_val->clone();
+    break;
+  case LONG:
+    _value.long_val = source._value.long_val->clone();
+    break;
+  case FLOAT:
+    _value.float_val = source._value.float_val->clone();
+    break;
+  case DOUBLE:
+    _value.double_val = source._value.double_val->clone();
+    break;
+  case STRING:
+  case UNKNOWN:
+    _value.string_val = source._value.string_val->clone();
+    break;
+  }
+}
+
+
+/**
+ * Destructor.
+ */
+SGValue::~SGValue ()
+{
+  if (_type != ALIAS)
+    clear_value();
 }
 
 
 /**
- * Destroy a value.
+ * Delete and clear the current value.
  */
-FGValue::~FGValue ()
+void
+SGValue::clear_value ()
 {
-  if (!_tied && _type == STRING) {
+  switch (_type) {
+  case ALIAS:
+    _value.alias->clear_value();
+  case BOOL:
+    delete _value.bool_val;
+    _value.bool_val = 0;
+    break;
+  case INT:
+    delete _value.int_val;
+    _value.int_val = 0;
+    break;
+  case LONG:
+    delete _value.long_val;
+    _value.long_val = 0L;
+    break;
+  case FLOAT:
+    delete _value.float_val;
+    _value.float_val = 0;
+    break;
+  case DOUBLE:
+    delete _value.double_val;
+    _value.double_val = 0;
+    break;
+  case STRING:
+  case UNKNOWN:
     delete _value.string_val;
     _value.string_val = 0;
+    break;
   }
 }
 
 
+/**
+ * Get the current type.
+ *
+ * Does not return a type of ALIAS.
+ */
+SGValue::Type
+SGValue::getType () const
+{
+  if (_type == ALIAS)
+    return _value.alias->getType();
+  else
+    return (Type)_type;
+}
+
+
+/**
+ * Get the current aliased value.
+ */
+SGValue *
+SGValue::getAlias ()
+{
+  return (_type == ALIAS ? _value.alias : 0);
+}
+
+
+/**
+ * Get the current aliased value.
+ */
+const SGValue *
+SGValue::getAlias () const
+{
+  return (_type == ALIAS ? _value.alias : 0);
+}
+
+
+/**
+ * Alias to another value.
+ */
 bool
-FGValue::getRawBool () const
+SGValue::alias (SGValue * alias)
 {
-  if (_tied) {
-    if (_value.bool_func.getter != 0)
-      return (*(_value.bool_func.getter))();
-    else
-      return false;
-  } else {
-    return _value.bool_val;
+  if (alias == 0 || _type == ALIAS || _tied)
+    return false;
+  clear_value();
+  _value.alias = alias;
+  _type = ALIAS;
+  return true;
+}
+
+
+/**
+ * Unalias from another value.
+ */
+bool
+SGValue::unalias ()
+{
+                               // FIXME: keep copy of previous value,
+                               // as with untie()
+  if (_type != ALIAS)
+    return false;
+  _value.string_val = new SGRawValueInternal<string>;
+  _type = UNKNOWN;
+  return true;
+}
+
+
+/**
+ * Get a boolean value.
+ */
+bool
+SGValue::getBoolValue () const
+{
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->getBoolValue();
+  case BOOL:
+    return GET_BOOL;
+  case INT:
+    return GET_INT == 0 ? false : true;
+  case LONG:
+    return GET_LONG == 0L ? false : true;
+  case FLOAT:
+    return GET_FLOAT == 0.0 ? false : true;
+  case DOUBLE:
+    return GET_DOUBLE == 0.0L ? false : true;
+  case STRING:
+  case UNKNOWN:
+    return (GET_STRING == "true" || getDoubleValue() != 0.0L);
   }
+
+  return false;
 }
 
 
+/**
+ * Get an integer value.
+ */
 int
-FGValue::getRawInt () const
+SGValue::getIntValue () const
 {
-  if (_tied) {
-    if (_value.int_func.getter != 0)
-      return (*(_value.int_func.getter))();
-    else
-      return 0;
-  } else {
-    return _value.int_val;
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->getIntValue();
+  case BOOL:
+    return int(GET_BOOL);
+  case INT:
+    return GET_INT;
+  case LONG:
+    return int(GET_LONG);
+  case FLOAT:
+    return int(GET_FLOAT);
+  case DOUBLE:
+    return int(GET_DOUBLE);
+  case STRING:
+  case UNKNOWN:
+    return atoi(GET_STRING.c_str());
+  }
+
+  return 0;
+}
+
+
+/**
+ * Get a long integer value.
+ */
+long
+SGValue::getLongValue () const
+{
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->getLongValue();
+  case BOOL:
+    return long(GET_BOOL);
+  case INT:
+    return long(GET_INT);
+  case LONG:
+    return GET_LONG;
+  case FLOAT:
+    return long(GET_FLOAT);
+  case DOUBLE:
+    return long(GET_DOUBLE);
+  case STRING:
+  case UNKNOWN:
+    return strtol(GET_STRING.c_str(), 0, 0);
   }
 }
 
 
+/**
+ * Get a float value.
+ */
 float
-FGValue::getRawFloat () const
+SGValue::getFloatValue () const
 {
-  if (_tied) {
-    if (_value.float_func.getter != 0)
-      return (*(_value.float_func.getter))();
-    else
-      return 0.0;
-  } else {
-    return _value.float_val;
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->getFloatValue();
+  case BOOL:
+    return float(GET_BOOL);
+  case INT:
+    return float(GET_INT);
+  case LONG:
+    return float(GET_LONG);
+  case FLOAT:
+    return GET_FLOAT;
+  case DOUBLE:
+    return float(GET_DOUBLE);
+  case STRING:
+  case UNKNOWN:
+    return atof(GET_STRING.c_str());
   }
+
+  return 0.0;
 }
 
 
+/**
+ * Get a double value.
+ */
 double
-FGValue::getRawDouble () const
+SGValue::getDoubleValue () const
 {
-  if (_tied) {
-    if (_value.double_func.getter != 0)
-      return (*(_value.double_func.getter))();
-    else
-      return 0.0L;
-  } else {
-    return _value.double_val;
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->getDoubleValue();
+  case BOOL:
+    return double(GET_BOOL);
+  case INT:
+    return double(GET_INT);
+  case LONG:
+    return double(GET_LONG);
+  case FLOAT:
+    return double(GET_FLOAT);
+  case DOUBLE:
+    return GET_DOUBLE;
+  case STRING:
+  case UNKNOWN:
+    return strtod(GET_STRING.c_str(), 0);
   }
+
+  return 0.0;
 }
 
 
-const string &
-FGValue::getRawString () const
+/**
+ * Get a string value.
+ */
+string
+SGValue::getStringValue () const
 {
-  if (_tied) {
-    if (_value.string_func.getter != 0)
-      return (*(_value.string_func.getter))();
+  char buf[128];
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->getStringValue();
+  case BOOL:
+    if (GET_BOOL)
+      return "true";
     else
-      return empty_string;
-  } else {
-    return *_value.string_val;
+      return "false";
+  case INT:
+    sprintf(buf, "%d", GET_INT);
+    return buf;
+  case LONG:
+    sprintf(buf, "%ld", GET_LONG);
+    return buf;
+  case FLOAT:
+    sprintf(buf, "%f", GET_FLOAT);
+    return buf;
+  case DOUBLE:
+    sprintf(buf, "%f", GET_DOUBLE);
+    return buf;
+  case STRING:
+  case UNKNOWN:
+    return GET_STRING;
   }
+
+  return "";
 }
 
 
+/**
+ * Set a bool value.
+ */
 bool
-FGValue::setRawBool (bool value)
+SGValue::setBoolValue (bool value)
 {
-  if (_tied) {
-    if (_value.bool_func.setter != 0) {
-      (*_value.bool_func.setter)(value);
-      return true;
-    } else {
-      return false;
-    }
-  } else {
-    _value.bool_val = value;
-    return true;
+  if (_type == UNKNOWN) {
+    clear_value();
+    _value.bool_val = new SGRawValueInternal<bool>;
+    _type = BOOL;
   }
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setBoolValue(value);
+  case BOOL:
+    return SET_BOOL(value);
+  case INT:
+    return SET_INT(int(value));
+  case LONG:
+    return SET_LONG(long(value));
+  case FLOAT:
+    return SET_FLOAT(float(value));
+  case DOUBLE:
+    return SET_DOUBLE(double(value));
+  case STRING:
+    return SET_STRING(value ? "true" : "false");
+  }
+
+  return false;
+}
+
+
+/**
+ * Set an int value.
+ */
+bool
+SGValue::setIntValue (int value)
+{
+  if (_type == UNKNOWN) {
+    clear_value();
+    _value.int_val = new SGRawValueInternal<int>;
+    _type = INT;
+  }
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setIntValue(value);
+  case BOOL:
+    return SET_BOOL(value == 0 ? false : true);
+  case INT:
+    return SET_INT(value);
+  case LONG:
+    return SET_LONG(long(value));
+  case FLOAT:
+    return SET_FLOAT(float(value));
+  case DOUBLE:
+    return SET_DOUBLE(double(value));
+  case STRING: {
+    char buf[128];
+    sprintf(buf, "%d", value);
+    return SET_STRING(buf);
+  }
+  }
+
+  return false;
+}
+
+
+/**
+ * Set a long value.
+ */
+bool
+SGValue::setLongValue (long value)
+{
+  if (_type == UNKNOWN) {
+    clear_value();
+    _value.long_val = new SGRawValueInternal<long>;
+    _type = LONG;
+  }
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setLongValue(value);
+  case BOOL:
+    return SET_BOOL(value == 0L ? false : true);
+  case INT:
+    return SET_INT(int(value));
+  case LONG:
+    return SET_LONG(value);
+  case FLOAT:
+    return SET_FLOAT(float(value));
+  case DOUBLE:
+    return SET_DOUBLE(double(value));
+  case STRING: {
+    char buf[128];
+    sprintf(buf, "%d", value);
+    return SET_STRING(buf);
+  }
+  }
+
+  return false;
+}
+
+
+/**
+ * Set a float value.
+ */
+bool
+SGValue::setFloatValue (float value)
+{
+  if (_type == UNKNOWN) {
+    clear_value();
+    _value.float_val = new SGRawValueInternal<float>;
+    _type = FLOAT;
+  }
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setFloatValue(value);
+  case BOOL:
+    return SET_BOOL(value == 0.0 ? false : true);
+  case INT:
+    return SET_INT(int(value));
+  case LONG:
+    return SET_LONG(long(value));
+  case FLOAT:
+    return SET_FLOAT(value);
+  case DOUBLE:
+    return SET_DOUBLE(double(value));
+  case STRING: {
+    char buf[128];
+    sprintf(buf, "%f", value);
+    return SET_STRING(buf);
+  }
+  }
+
+  return false;
+}
+
+
+/**
+ * Set a double value.
+ */
+bool
+SGValue::setDoubleValue (double value)
+{
+  if (_type == UNKNOWN) {
+    clear_value();
+    _value.double_val = new SGRawValueInternal<double>;
+    _type = DOUBLE;
+  }
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setDoubleValue(value);
+  case BOOL:
+    return SET_BOOL(value == 0.0L ? false : true);
+  case INT:
+    return SET_INT(int(value));
+  case LONG:
+    return SET_LONG(long(value));
+  case FLOAT:
+    return SET_FLOAT(float(value));
+  case DOUBLE:
+    return SET_DOUBLE(value);
+  case STRING: {
+    char buf[128];
+    sprintf(buf, "%lf", value);
+    return SET_STRING(buf);
+  }
+  }
+
+  return false;
+}
+
+
+/**
+ * Set a string value.
+ */
+bool
+SGValue::setStringValue (string value)
+{
+  if (_type == UNKNOWN) {
+    clear_value();
+    _value.string_val = new SGRawValueInternal<string>;
+    _type = STRING;
+  }
+
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setStringValue(value);
+  case BOOL:
+    return SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
+  case INT:
+    return SET_INT(atoi(value.c_str()));
+  case LONG:
+    return SET_LONG(strtol(value.c_str(), 0, 0));
+  case FLOAT:
+    return SET_FLOAT(atof(value.c_str()));
+  case DOUBLE:
+    return SET_DOUBLE(strtod(value.c_str(), 0));
+  case STRING:
+    return SET_STRING(value);
+  }
+
+  return false;
+}
+
+
+/**
+ * Set a value of unknown type (stored as a string).
+ */
+bool
+SGValue::setUnknownValue (string value)
+{
+  switch (_type) {
+  case ALIAS:
+    return _value.alias->setUnknownValue(value);
+  case BOOL:
+    return SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
+  case INT:
+    return SET_INT(atoi(value.c_str()));
+  case LONG:
+    return SET_LONG(strtol(value.c_str(), 0, 0));
+  case FLOAT:
+    return SET_FLOAT(atof(value.c_str()));
+  case DOUBLE:
+    return SET_DOUBLE(strtod(value.c_str(), 0));
+  case STRING:
+  case UNKNOWN:
+    return SET_STRING(value);
+  }
+
+  return false;
+}
+
+
+/**
+ * Tie a bool value.
+ */
+bool
+SGValue::tie (const SGRawValue<bool> &value, bool use_default)
+{
+  if (_type == ALIAS)
+    return _value.alias->tie(value, use_default);
+  else if (_tied)
+    return false;
+
+  bool old_val = false;
+  if (use_default)
+    old_val = getBoolValue();
+
+  clear_value();
+  _type = BOOL;
+  _tied = true;
+  _value.bool_val = value.clone();
+
+  if (use_default)
+    setBoolValue(old_val);
+
+  return true;
+}
+
+
+/**
+ * Tie an int value.
+ */
+bool
+SGValue::tie (const SGRawValue<int> &value, bool use_default)
+{
+  if (_type == ALIAS)
+    return _value.alias->tie(value, use_default);
+  else if (_tied)
+    return false;
+
+  int old_val = 0;
+  if (use_default)
+    old_val = getIntValue();
+
+  clear_value();
+  _type = INT;
+  _tied = true;
+  _value.int_val = value.clone();
+
+  if (use_default)
+    setIntValue(old_val);
+
+  return true;
+}
+
+
+/**
+ * Tie a long value.
+ */
+bool
+SGValue::tie (const SGRawValue<long> &value, bool use_default)
+{
+  if (_type == ALIAS)
+    return _value.alias->tie(value, use_default);
+  else if (_tied)
+    return false;
+
+  long old_val;
+  if (use_default)
+    old_val = getLongValue();
+
+  clear_value();
+  _type = LONG;
+  _tied = true;
+  _value.long_val = value.clone();
+
+  if (use_default)
+    setLongValue(old_val);
+
+  return true;
+}
+
+
+/**
+ * Tie a float value.
+ */
+bool
+SGValue::tie (const SGRawValue<float> &value, bool use_default)
+{
+  if (_type == ALIAS)
+    return _value.alias->tie(value, use_default);
+  else if (_tied)
+    return false;
+
+  float old_val = 0.0;
+  if (use_default)
+    old_val = getFloatValue();
+
+  clear_value();
+  _type = FLOAT;
+  _tied = true;
+  _value.float_val = value.clone();
+
+  if (use_default)
+    setFloatValue(old_val);
+
+  return true;
+}
+
+
+/**
+ * Tie a double value.
+ */
+bool
+SGValue::tie (const SGRawValue<double> &value, bool use_default)
+{
+  if (_type == ALIAS)
+    return _value.alias->tie(value, use_default);
+  else if (_tied)
+    return false;
+
+  double old_val = 0.0;
+  if (use_default)
+    old_val = getDoubleValue();
+
+  clear_value();
+  _type = DOUBLE;
+  _tied = true;
+  _value.double_val = value.clone();
+
+  if (use_default)
+    setDoubleValue(old_val);
+
+  return true;
+}
+
+
+/**
+ * Tie a string value.
+ */
+bool
+SGValue::tie (const SGRawValue<string> &value, bool use_default)
+{
+  if (_type == ALIAS)
+    return _value.alias->tie(value, use_default);
+  else if (_tied)
+    return false;
+
+  string old_val;
+  if (use_default)
+    old_val = getStringValue();
+
+  clear_value();
+  _type = STRING;
+  _tied = true;
+  _value.string_val = value.clone();
+
+  if (use_default)
+    setStringValue(old_val);
+
+  return true;
+}
+
+
+/**
+ * Untie a value.
+ */
+bool
+SGValue::untie ()
+{
+  if (!_tied)
+    return false;
+
+  switch (_type) {
+  case ALIAS: {
+    return _value.alias->untie();
+  }
+  case BOOL: {
+    bool val = getBoolValue();
+    clear_value();
+    _value.bool_val = new SGRawValueInternal<bool>;
+    SET_BOOL(val);
+    break;
+  }
+  case INT: {
+    int val = getIntValue();
+    clear_value();
+    _value.int_val = new SGRawValueInternal<int>;
+    SET_INT(val);
+    break;
+  }
+  case LONG: {
+    long val = getLongValue();
+    clear_value();
+    _value.long_val = new SGRawValueInternal<long>;
+    SET_LONG(val);
+    break;
+  }
+  case FLOAT: {
+    float val = getFloatValue();
+    clear_value();
+    _value.float_val = new SGRawValueInternal<float>;
+    SET_FLOAT(val);
+    break;
+  }
+  case DOUBLE: {
+    double val = getDoubleValue();
+    clear_value();
+    _value.double_val = new SGRawValueInternal<double>;
+    SET_DOUBLE(val);
+    break;
+  }
+  case STRING: {
+    string val = getStringValue();
+    clear_value();
+    _value.string_val = new SGRawValueInternal<string>;
+    SET_STRING(val);
+    break;
+  }
+  }
+
+  _tied = false;
+  return true;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of SGPropertyNode.
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Utility function: given a value, find the property node.
+ */
+static SGPropertyNode *
+find_node_by_value (SGPropertyNode * start_node, const SGValue * value)
+{
+  if (start_node->getValue() == value) {
+    return start_node;
+  } else for (int i = 0; i < start_node->nChildren(); i++) {
+    SGPropertyNode * child =
+      find_node_by_value(start_node->getChild(i), value);
+    if (child != 0)
+      return child;
+  }
+  return 0;
+}
+
+
+/**
+ * Default constructor: always creates a root node.
+ */
+SGPropertyNode::SGPropertyNode ()
+  : _value(0), _name(""), _index(0), _parent(0), _target(0)
+{
+}
+
+
+/**
+ * Convenience constructor.
+ */
+SGPropertyNode::SGPropertyNode (const string &name,
+                               int index, SGPropertyNode * parent)
+  : _value(0), _name(name), _index(index), _parent(parent), _target(0)
+{
+}
+
+
+/**
+ * Destructor.
+ */
+SGPropertyNode::~SGPropertyNode ()
+{
+  delete _value;
+  for (int i = 0; i < (int)_children.size(); i++)
+    delete _children[i];
+}
+
+
+/**
+ * Get a value, optionally creating it if not present.
+ */
+SGValue *
+SGPropertyNode::getValue (bool create)
+{
+  if (_value == 0 && create)
+    _value = new SGValue();
+  return _value;
+}
+
+
+/**
+ * Alias to another node.
+ */
+bool
+SGPropertyNode::alias (SGPropertyNode * target)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  _target = target;
+  return _value->alias(target->getValue(true));
+}
+
+
+/**
+ * Alias to another node by path.
+ */
+bool
+SGPropertyNode::alias (const string &path)
+{
+  return alias(getNode(path, true));
 }
 
 
+/**
+ * Remove an alias.
+ */
 bool
-FGValue::setRawInt (int value)
+SGPropertyNode::unalias ()
 {
-  if (_tied) {
-    if (_value.int_func.setter != 0) {
-      (*_value.int_func.setter)(value);
-      return true;
-    } else {
-      return false;
-    }
-  } else {
-    _value.int_val = value;
-    return true;
-  }
+  _target = 0;
+  return (_value != 0 ? _value->unalias() : false);
 }
 
 
+/**
+ * Test whether this node is aliased.
+ */
 bool
-FGValue::setRawFloat (float value)
+SGPropertyNode::isAlias () const
 {
-  if (_tied) {
-    if (_value.float_func.setter != 0) {
-      (*_value.float_func.setter)(value);
-      return true;
-    } else {
-      return false;
-    }
-  } else {
-    _value.float_val = value;
-    return true;
-  }
+  return (_value != 0 ? _value->isAlias() : false);
 }
 
 
-bool
-FGValue::setRawDouble (double value)
+/**
+ * Get the target of an alias.
+ *
+ * This is tricky, because it is actually the value that is aliased,
+ * and someone could realias or unalias the value directly without
+ * going through the property node.  The node caches its best guess,
+ * but it may have to search the whole property tree.
+ *
+ * @return The target node for the alias, or 0 if the node is not aliased.
+ */
+SGPropertyNode *
+SGPropertyNode::getAliasTarget ()
 {
-  if (_tied) {
-    if (_value.double_func.setter != 0) {
-      (*_value.double_func.setter)(value);
-      return true;
-    } else {
-      return false;
-    }
+  if (_value == 0 || !_value->isAlias()) {
+    return 0;
+  } else if (_target != 0 && _target->getValue() == _value->getAlias()) {
+    return _target;
   } else {
-    _value.double_val = value;
-    return true;
+    _target = find_node_by_value(getRootNode(), _value->getAlias());
   }
 }
 
 
-bool
-FGValue::setRawString (const string &value)
+const SGPropertyNode *
+SGPropertyNode::getAliasTarget () const
 {
-  if (_tied) {
-    if (_value.string_func.setter != 0) {
-      (*_value.string_func.setter)(value);
-      return true;
-    } else {
-      return false;
-    }
+  if (_value == 0 || !_value->isAlias()) {
+    return 0;
+  } else if (_target != 0 && _target->getValue() == _value->getAlias()) {
+    return _target;
   } else {
-    if (_value.string_val == 0)
-      _value.string_val = new string;
-    *(_value.string_val) = value;
-    return true;
+                               // FIXME: const cast
+    _target =
+      find_node_by_value((SGPropertyNode *)getRootNode(), _value->getAlias());
   }
 }
 
 
 /**
- * Attempt to get the boolean value of a property.
+ * Get a non-const child by index.
  */
-bool
-FGValue::getBoolValue () const
+SGPropertyNode *
+SGPropertyNode::getChild (int position)
 {
-  switch (_type) {
-  case UNKNOWN:
-    return false;
-  case BOOL:
-    return getRawBool();
-  case INT:
-    return (getRawInt() == 0 ? false : true);
-  case FLOAT:
-    return (getRawFloat() == 0.0 ? false : true);
-  case DOUBLE:
-    return (getRawDouble() == 0.0 ? false : true);
-  case STRING:
-    return (getRawString() == "false" ? false : true);
-  }
-
-  return false;
+  if (position >= 0 && position < nChildren())
+    return _children[position];
+  else
+    return 0;
 }
 
 
 /**
- * Attempt to get the integer value of a property.
+ * Get a const child by index.
  */
-int
-FGValue::getIntValue () const
+const SGPropertyNode *
+SGPropertyNode::getChild (int position) const
 {
-  switch (_type) {
-  case UNKNOWN:
+  if (position >= 0 && position < nChildren())
+    return _children[position];
+  else
     return 0;
-  case BOOL:
-    return getRawBool();
-  case INT:
-    return getRawInt();
-  case FLOAT:
-    return (int)(getRawFloat());
-  case DOUBLE:
-    return (int)(getRawDouble());
-  case STRING:
-    return atoi(getRawString().c_str());
-  }
-
-  return 0;
 }
 
 
 /**
- * Attempt to get the float value of a property.
+ * Get a non-const child by name and index, creating if necessary.
  */
-float
-FGValue::getFloatValue () const
+SGPropertyNode *
+SGPropertyNode::getChild (const string &name, int index, bool create)
 {
-  switch (_type) {
-  case UNKNOWN:
-    return 0.0;
-  case BOOL:
-    return (float)(getRawBool());
-  case INT:
-    return (float)(getRawInt());
-  case FLOAT:
-    return getRawFloat();
-  case DOUBLE:
-    return (float)(getRawDouble());
-  case STRING:
-    return (float)atof(getRawString().c_str());
+  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];
+  } else {
+    return 0;
   }
+}
 
-  return 0.0;
+
+/**
+ * Get a const child by name and index.
+ */
+const SGPropertyNode *
+SGPropertyNode::getChild (const string &name, int index) const
+{
+  int pos = find_child(name, index, _children);
+  if (pos >= 0)
+    return _children[pos];
+  else
+    return 0;
 }
 
 
 /**
- * Attempt to get the double value of a property.
+ * Get all children with the same name (but different indices).
  */
-double
-FGValue::getDoubleValue () const
+vector<SGPropertyNode *>
+SGPropertyNode::getChildren (const string &name)
 {
-  switch (_type) {
-  case UNKNOWN:
-    return 0.0;
-  case BOOL:
-    return (double)(getRawBool());
-  case INT:
-    return (double)(getRawInt());
-  case FLOAT:
-    return (double)(getRawFloat());
-  case DOUBLE:
-    return getRawDouble();
-  case STRING:
-    return atof(getRawString().c_str());
-  }
+  vector<SGPropertyNode *> children;
+  int max = _children.size();
 
-  return 0.0;
+  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;
 }
 
 
 /**
- * Attempt to get the string value of a property.
+ * Get all children const with the same name (but different indices).
  */
-const string &
-FGValue::getStringValue () const
+vector<const SGPropertyNode *>
+SGPropertyNode::getChildren (const string &name) const
 {
-  switch (_type) {
-  case UNKNOWN:
-  case BOOL:
-  case INT:
-  case FLOAT:
-  case DOUBLE:
-    return empty_string;
-  case STRING:
-    return getRawString();
-  }
+  vector<const SGPropertyNode *> children;
+  int max = _children.size();
+
+  for (int i = 0; i < max; i++)
+    if (_children[i]->getName() == name)
+      children.push_back(_children[i]);
 
-  return empty_string;
+  sort(children.begin(), children.end(), CompareIndices());
+  return children;
 }
 
 
-bool
-FGValue::setBoolValue (bool value)
+string
+SGPropertyNode::getPath (bool simplify) const
 {
-  if (_type == UNKNOWN || _type == BOOL) {
-    _type = BOOL;
-    return setRawBool(value);
-  } else {
-    return false;
+  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;
   }
+  return path;
 }
 
-
-bool
-FGValue::setIntValue (int value)
+SGValue::Type
+SGPropertyNode::getType () const
 {
-  if (_type == UNKNOWN || _type == INT) {
-    _type = INT;
-    return setRawInt(value);
-  } else {
-    return false;
-  }
+  if (_value != 0)
+    return _value->getType();
+  else
+    return SGValue::UNKNOWN;
 }
 
 
-bool
-FGValue::setFloatValue (float value)
+bool 
+SGPropertyNode::getBoolValue () const
 {
-  if (_type == UNKNOWN || _type == FLOAT) {
-    _type = FLOAT;
-    return setRawFloat(value);
-  } else {
-    return false;
-  }
+  return (_value == 0 ? SGRawValue<bool>::DefaultValue
+         : _value->getBoolValue());
 }
 
+int 
+SGPropertyNode::getIntValue () const
+{
+  return (_value == 0 ? SGRawValue<int>::DefaultValue
+         : _value->getIntValue());
+}
 
-bool
-FGValue::setDoubleValue (double value)
+long 
+SGPropertyNode::getLongValue () const
 {
-  if (_type == UNKNOWN || _type == DOUBLE) {
-    _type = DOUBLE;
-    return setRawDouble(value);
-  } else {
-    return false;
-  }
+  return (_value == 0 ? SGRawValue<long>::DefaultValue
+         : _value->getLongValue());
 }
 
+float 
+SGPropertyNode::getFloatValue () const
+{
+  return (_value == 0 ? SGRawValue<float>::DefaultValue
+         : _value->getFloatValue());
+}
 
-bool
-FGValue::setStringValue (const string &value)
+double 
+SGPropertyNode::getDoubleValue () const
 {
-  if (_type == UNKNOWN || _type == STRING) {
-    _type = STRING;
-    return setRawString(value);
-  } else {
-    return false;
-  }
+  return (_value == 0 ? SGRawValue<double>::DefaultValue
+         : _value->getDoubleValue());
 }
 
+string
+SGPropertyNode::getStringValue () const
+{
+  return (_value == 0 ? SGRawValue<string>::DefaultValue
+         : _value->getStringValue());
+}
 
 bool
-FGValue::tieBool (bool_getter getter, bool_setter setter = 0,
-                 bool useDefault = true)
+SGPropertyNode::setBoolValue (bool val)
 {
-  if (_tied) {
-    return false;
-  } else {
-    if (useDefault && setter && _type != UNKNOWN)
-      (*setter)(getBoolValue());
-    _tied = true;
-    _type = BOOL;
-    _value.bool_func.getter = getter;
-    _value.bool_func.setter = setter;
-    return true;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setBoolValue(val);
 }
 
+bool
+SGPropertyNode::setIntValue (int val)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setIntValue(val);
+}
 
 bool
-FGValue::tieInt (int_getter getter, int_setter setter = 0,
-                bool useDefault = true)
+SGPropertyNode::setLongValue (long val)
 {
-  if (_tied) {
-    return false;
-  } else {
-    if (useDefault && setter && _type != UNKNOWN)
-      (*setter)(getIntValue());
-    _tied = true;
-    _type = INT;
-    _value.int_func.getter = getter;
-    _value.int_func.setter = setter;
-    return true;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setLongValue(val);
 }
 
+bool
+SGPropertyNode::setFloatValue (float val)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setFloatValue(val);
+}
 
 bool
-FGValue::tieFloat (float_getter getter, float_setter setter = 0,
-                  bool useDefault = true)
+SGPropertyNode::setDoubleValue (double val)
 {
-  if (_tied) {
-    return false;
-  } else {
-    if (useDefault && setter && _type != UNKNOWN)
-      (*setter)(getFloatValue());
-    _tied = true;
-    _type = FLOAT;
-    _value.float_func.getter = getter;
-    _value.float_func.setter = setter;
-    return true;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setDoubleValue(val);
 }
 
+bool
+SGPropertyNode::setStringValue (string val)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setStringValue(val);
+}
 
 bool
-FGValue::tieDouble (double_getter getter, double_setter setter = 0,
-                   bool useDefault = true)
+SGPropertyNode::setUnknownValue (string val)
 {
-  if (_tied) {
-    return false;
-  } else {
-    if (useDefault && setter && _type != UNKNOWN)
-      (*setter)(getDoubleValue());
-    _tied = true;
-    _type = DOUBLE;
-    _value.double_func.getter = getter;
-    _value.double_func.setter = setter;
-    return true;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->setUnknownValue(val);
 }
 
+bool
+SGPropertyNode::isTied () const
+{
+  return (_value == 0 ? false : _value->isTied());
+}
 
 bool
-FGValue::tieString (string_getter getter, string_setter setter = 0,
-                   bool useDefault = true)
+SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
 {
-  if (_tied) {
-    return false;
-  } else {
-    if (useDefault && setter && _type != UNKNOWN)
-      (*setter)(getStringValue());
-    if (_type == STRING)
-      delete _value.string_val;
-    _tied = true;
-    _type = STRING;
-    _value.string_func.getter = getter;
-    _value.string_func.setter = setter;
-    return true;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->tie(rawValue, useDefault);
 }
 
+bool
+SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->tie(rawValue, useDefault);
+}
 
 bool
-FGValue::untieBool ()
+SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
 {
-  if (_tied && _type == BOOL) {
-    bool value = getRawBool();
-    _value.bool_val = value;
-    _tied = false;
-    return true;
-  } else {
-    return false;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->tie(rawValue, useDefault);
 }
 
+bool
+SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->tie(rawValue, useDefault);
+}
 
 bool
-FGValue::untieInt ()
+SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
 {
-  if (_tied && _type == INT) {
-    int value = getRawInt();
-    _value.int_val = value;
-    _tied = false;
-    return true;
-  } else {
-    return false;
-  }
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->tie(rawValue, useDefault);
 }
 
+bool
+SGPropertyNode::tie (const SGRawValue<string> &rawValue, bool useDefault)
+{
+  if (_value == 0)
+    _value = new SGValue();
+  return _value->tie(rawValue, useDefault);
+}
 
 bool
-FGValue::untieFloat ()
+SGPropertyNode::untie ()
 {
-  if (_tied && _type == FLOAT) {
-    float value = getRawFloat();
-    _value.float_val = value;
-    _tied = false;
-    return true;
-  } else {
-    return false;
-  }
+  return (_value == 0 ? false : _value->untie());
 }
 
+SGPropertyNode *
+SGPropertyNode::getRootNode ()
+{
+  if (_parent == 0)
+    return this;
+  else
+    return _parent->getRootNode();
+}
 
-bool
-FGValue::untieDouble ()
+const SGPropertyNode *
+SGPropertyNode::getRootNode () const
 {
-  if (_tied && _type == DOUBLE) {
-    double value = getRawDouble();
-    _value.double_val = value;
-    _tied = false;
-    return true;
-  } else {
-    return false;
-  }
+  if (_parent == 0)
+    return this;
+  else
+    return _parent->getRootNode();
 }
 
+SGPropertyNode *
+SGPropertyNode::getNode (const string &relative_path, bool create)
+{
+  vector<PathComponent> components;
+  parse_path(relative_path, components);
+  return find_node(this, components, 0, create);
+}
 
-bool
-FGValue::untieString ()
+const SGPropertyNode *
+SGPropertyNode::getNode (const string &relative_path) const
 {
-  if (_tied && _type == STRING) {
-    const string &value = getRawString();
-    _value.string_val = new string(value);
-    _tied = false;
-    return true;
-  } else {
-    return false;
-  }
+  vector<PathComponent> components;
+  parse_path(relative_path, components);
+                               // FIXME: cast away const
+  return find_node((SGPropertyNode *)this, components, 0, false);
 }
 
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Implementation of FGPropertyList.
+// Convenience methods using relative paths.
 ////////////////////////////////////////////////////////////////////////
 
-FGPropertyList::FGPropertyList ()
+
+/**
+ * Test whether another node has a value attached.
+ */
+bool
+SGPropertyNode::hasValue (const string &relative_path) const
 {
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? false : node->hasValue());
 }
 
-FGPropertyList::~FGPropertyList ()
+
+/**
+ * Get the value for another node.
+ */
+SGValue *
+SGPropertyNode::getValue (const string &relative_path, bool create)
 {
+  SGPropertyNode * node = getNode(relative_path, create);
+  if (node != 0 && !node->hasValue())
+    node->setUnknownValue("");
+  return (node == 0 ? 0 : node->getValue(create));
 }
 
 
-FGValue *
-FGPropertyList::getValue (const string &name, bool create = false)
+/**
+ * Get the value for another node.
+ */
+const SGValue *
+SGPropertyNode::getValue (const string &relative_path) const
 {
-  const_iterator el = _props.find(name);
-  if (el == _props.end()) {
-    if (!create)
-      return 0;
-    else {
-      FG_LOG(FG_GENERAL, FG_INFO, "Creating new property '" << name << '\'');
-    }
-  }
-  return &(_props[name]);
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? 0 : node->getValue());
 }
 
 
-const FGValue *
-FGPropertyList::getValue (const string &name) const
+/**
+ * Get the value type for another node.
+ */
+SGValue::Type
+SGPropertyNode::getType (const string &relative_path) const
 {
-  value_map::const_iterator el = _props.find(name);
-  return &(el->second);
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? SGValue::UNKNOWN : node->getType());
 }
 
 
+/**
+ * Get a bool value for another node.
+ */
 bool
-FGPropertyList::getBoolValue (const string &name) const
+SGPropertyNode::getBoolValue (const string &relative_path,
+                             bool defaultValue) const
 {
-  const FGValue * val = getValue(name);
-  if (val == 0)
-    return false;
-  else
-    return val->getBoolValue();
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? defaultValue : node->getBoolValue());
 }
 
 
+/**
+ * Get an int value for another node.
+ */
 int
-FGPropertyList::getIntValue (const string &name) const
+SGPropertyNode::getIntValue (const string &relative_path,
+                            int defaultValue) const
 {
-  const FGValue * val = getValue(name);
-  if (val == 0)
-    return 0;
-  else
-    return val->getIntValue();
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? defaultValue : node->getIntValue());
 }
 
 
-float
-FGPropertyList::getFloatValue (const string &name) const
+/**
+ * Get a long value for another node.
+ */
+long
+SGPropertyNode::getLongValue (const string &relative_path,
+                             long defaultValue) const
 {
-  const FGValue * val = getValue(name);
-  if (val == 0)
-    return 0.0;
-  else
-    return val->getFloatValue();
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? defaultValue : node->getLongValue());
 }
 
 
-double
-FGPropertyList::getDoubleValue (const string &name) const
+/**
+ * Get a float value for another node.
+ */
+float
+SGPropertyNode::getFloatValue (const string &relative_path,
+                              float defaultValue) const
 {
-  const FGValue * val = getValue(name);
-  if (val == 0)
-    return 0.0;
-  else
-    return val->getDoubleValue();
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? defaultValue : node->getFloatValue());
 }
 
 
-const string &
-FGPropertyList::getStringValue (const string &name) const
+/**
+ * Get a double value for another node.
+ */
+double
+SGPropertyNode::getDoubleValue (const string &relative_path,
+                               double defaultValue) const
 {
-  const FGValue * val = getValue(name);
-  if (val == 0)
-    return empty_string;
-  else
-    return val->getStringValue();
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? defaultValue : node->getDoubleValue());
 }
 
 
-bool
-FGPropertyList::setBoolValue (const string &name, bool value)
+/**
+ * Get a string value for another node.
+ */
+string
+SGPropertyNode::getStringValue (const string &relative_path,
+                               string defaultValue) const
 {
-  return getValue(name, true)->setBoolValue(value);
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? defaultValue : node->getStringValue());
 }
 
 
+/**
+ * Set a bool value for another node.
+ */
 bool
-FGPropertyList::setIntValue (const string &name, int value)
+SGPropertyNode::setBoolValue (const string &relative_path, bool value)
 {
-  return getValue(name, true)->setIntValue(value);
+  return getNode(relative_path, true)->setBoolValue(value);
 }
 
 
+/**
+ * Set an int value for another node.
+ */
 bool
-FGPropertyList::setFloatValue (const string &name, float value)
+SGPropertyNode::setIntValue (const string &relative_path, int value)
 {
-  return getValue(name, true)->setFloatValue(value);
+  return getNode(relative_path, true)->setIntValue(value);
 }
 
 
+/**
+ * Set a long value for another node.
+ */
 bool
-FGPropertyList::setDoubleValue (const string &name, double value)
+SGPropertyNode::setLongValue (const string &relative_path, long value)
 {
-  return getValue(name, true)->setDoubleValue(value);
+  return getNode(relative_path, true)->setLongValue(value);
 }
 
 
+/**
+ * Set a float value for another node.
+ */
 bool
-FGPropertyList::setStringValue (const string &name, const string &value)
+SGPropertyNode::setFloatValue (const string &relative_path, float value)
 {
-  return getValue(name, true)->setStringValue(value);
+  return getNode(relative_path, true)->setFloatValue(value);
 }
 
 
+/**
+ * Set a double value for another node.
+ */
 bool
-FGPropertyList::tieBool (const string &name, 
-                        bool_getter getter,
-                        bool_setter setter,
-                        bool useDefault = true)
+SGPropertyNode::setDoubleValue (const string &relative_path, double value)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Tying bool property '" << name << '\'');
-  return getValue(name, true)->tieBool(getter, setter, useDefault);
+  return getNode(relative_path, true)->setDoubleValue(value);
 }
 
 
+/**
+ * Set a string value for another node.
+ */
 bool
-FGPropertyList::tieInt (const string &name, 
-                       int_getter getter,
-                       int_setter setter,
-                       bool useDefault = true)
+SGPropertyNode::setStringValue (const string &relative_path, string value)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Tying int property '" << name << '\'');
-  return getValue(name, true)->tieInt(getter, setter, useDefault);
+  return getNode(relative_path, true)->setStringValue(value);
 }
 
 
+/**
+ * Set an unknown value for another node.
+ */
 bool
-FGPropertyList::tieFloat (const string &name, 
-                         float_getter getter,
-                         float_setter setter,
-                         bool useDefault = true)
+SGPropertyNode::setUnknownValue (const string &relative_path, string value)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Tying float property '" << name << '\'');
-  return getValue(name, true)->tieFloat(getter, setter, useDefault);
+  return getNode(relative_path, true)->setUnknownValue(value);
 }
 
 
+/**
+ * Test whether another node is tied.
+ */
 bool
-FGPropertyList::tieDouble (const string &name, 
-                          double_getter getter,
-                          double_setter setter,
-                          bool useDefault = true)
+SGPropertyNode::isTied (const string &relative_path) const
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Tying double property '" << name << '\'');
-  return getValue(name, true)->tieDouble(getter, setter, useDefault);
+  const SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? false : node->isTied());
 }
 
 
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
 bool
-FGPropertyList::tieString (const string &name, 
-                          string_getter getter,
-                          string_setter setter,
-                          bool useDefault = true)
+SGPropertyNode::tie (const string &relative_path,
+                    const SGRawValue<bool> &rawValue,
+                    bool useDefault)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Tying string property '" << name << '\'');
-  return getValue(name, true)->tieString(getter, setter, useDefault);
+  return getNode(relative_path, true)->tie(rawValue, useDefault);
 }
 
 
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
 bool
-FGPropertyList::untieBool (const string &name)
+SGPropertyNode::tie (const string &relative_path,
+                    const SGRawValue<int> &rawValue,
+                    bool useDefault)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Untying bool property '" << name << '\'');
-  return getValue(name, true)->untieBool();
+  return getNode(relative_path, true)->tie(rawValue, useDefault);
 }
 
 
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
 bool
-FGPropertyList::untieInt (const string &name)
+SGPropertyNode::tie (const string &relative_path,
+                    const SGRawValue<long> &rawValue,
+                    bool useDefault)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Untying int property '" << name << '\'');
-  return getValue(name, true)->untieInt();
+  return getNode(relative_path, true)->tie(rawValue, useDefault);
 }
 
 
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
 bool
-FGPropertyList::untieFloat (const string &name)
+SGPropertyNode::tie (const string &relative_path,
+                    const SGRawValue<float> &rawValue,
+                    bool useDefault)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Untying float property '" << name << '\'');
-  return getValue(name, true)->untieFloat();
+  return getNode(relative_path, true)->tie(rawValue, useDefault);
 }
 
 
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
 bool
-FGPropertyList::untieDouble (const string &name)
+SGPropertyNode::tie (const string &relative_path,
+                    const SGRawValue<double> &rawValue,
+                    bool useDefault)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Untying double property '" << name << '\'');
-  return getValue(name, true)->untieDouble();
+  return getNode(relative_path, true)->tie(rawValue, useDefault);
 }
 
 
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
 bool
-FGPropertyList::untieString (const string &name)
+SGPropertyNode::tie (const string &relative_path,
+                    const SGRawValue<string> &rawValue,
+                    bool useDefault)
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Untying string property '" << name << '\'');
-  return getValue(name, true)->untieString();
+  return getNode(relative_path, true)->tie(rawValue, useDefault);
 }
 
 
-void
-FGPropertyList::dumpToLog () const
+/**
+ * Attempt to untie another node reached by a relative path.
+ */
+bool
+SGPropertyNode::untie (const string &relative_path)
 {
-  const_iterator it = FGPropertyList::begin();
-  FG_LOG(FG_GENERAL, FG_INFO, "Begin property list dump...");
-  while (it != end()) {
-    FG_LOG(FG_GENERAL, FG_INFO, "Property: " << it->first);
-    it++;
-  }
-  FG_LOG(FG_GENERAL, FG_INFO, "...End property list dump");
+  SGPropertyNode * node = getNode(relative_path);
+  return (node == 0 ? false : node->untie());
 }
 
-
-
 // end of props.cxx