-// props.cxx -- implementation of SimGear Property Manager.
-//
-// Written by David Megginson - david@megginson.com
-//
-// This module is in the PUBLIC DOMAIN.
-//
-// 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.
+// props.cxx - implementation of a property list.
+// Started Fall 2000 by David Megginson, david@megginson.com
+// This code is released into the Public Domain.
//
// See props.html for documentation [replace with URL when available].
//
// $Id$
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include "props.hxx"
+
+#include <algorithm>
+#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>
-#include "props.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
+////////////////////////////////////////////////////////////////////////
+// Local classes.
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * Comparator class for sorting by index.
+ */
+class CompareIndices
+{
+public:
+ int operator() (const SGPropertyNode_ptr n1, const SGPropertyNode_ptr n2) const {
+ return (n1->getIndex() < n2->getIndex());
+ }
+};
-#include <stdlib.h>
-#include <string>
+\f
+////////////////////////////////////////////////////////////////////////
+// Convenience macros for value access.
+////////////////////////////////////////////////////////////////////////
+
+#define TEST_READ(dflt) if (!getAttribute(READ)) return dflt
+#define TEST_WRITE if (!getAttribute(WRITE)) return false
-using std::string;
-FGPropertyList current_properties;
+\f
+////////////////////////////////////////////////////////////////////////
+// Default values for every type.
+////////////////////////////////////////////////////////////////////////
-static string empty_string;
+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 char * const SGRawValue<const char *>::DefaultValue = "";
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGValue.
+// Local path normalization code.
////////////////////////////////////////////////////////////////////////
+/**
+ * A component in a path.
+ */
+struct PathComponent
+{
+ string name;
+ int index;
+};
/**
- * Construct a new value.
+ * Parse the name for a path component.
+ *
+ * Name: [_a-zA-Z][-._a-zA-Z0-9]*
*/
-FGValue::FGValue ()
- : _type(UNKNOWN), _tied(false)
+static inline const 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;
}
/**
- * Destroy a value.
+ * Parse the optional integer index for a path component.
+ *
+ * Index: "[" [0-9]+ "]"
*/
-FGValue::~FGValue ()
+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 ']')");
}
/**
- * Return a raw boolean value (no type coercion).
+ * Parse a single path component.
+ *
+ * Component: Name Index?
*/
-bool
-FGValue::getRawBool () const
+static inline PathComponent
+parse_component (const string &path, int &i)
{
- if (_tied) {
- if (_value.bool_func.getter != 0)
- return (*(_value.bool_func.getter))();
- else
- return false;
- } else {
- return _value.bool_val;
- }
+ PathComponent component;
+ component.name = parse_name(path, i);
+ if (component.name[0] != '.')
+ component.index = parse_index(path, i);
+ else
+ component.index = -1;
+ return component;
}
/**
- * Return a raw integer value (no type coercion).
+ * Parse a path into its components.
*/
-int
-FGValue::getRawInt () const
+static void
+parse_path (const string &path, vector<PathComponent> &components)
{
- if (_tied) {
- if (_value.int_func.getter != 0)
- return (*(_value.int_func.getter))();
- else
- return 0;
- } else {
- return _value.int_val;
+ 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.
+////////////////////////////////////////////////////////////////////////
+
+
+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);
+}
+
/**
- * Return a raw floating-point value (no type coercion).
+ * Locate a child node by name and index.
*/
-float
-FGValue::getRawFloat () const
+static int
+find_child (const char * name, int index, vector<SGPropertyNode_ptr> nodes)
{
- if (_tied) {
- if (_value.float_func.getter != 0)
- return (*(_value.float_func.getter))();
- else
- return 0.0;
- } else {
- return _value.float_val;
+ int nNodes = nodes.size();
+ for (int i = 0; i < nNodes; i++) {
+ SGPropertyNode * node = nodes[i];
+ if (compare_strings(node->getName(), name) && node->getIndex() == index)
+ return i;
}
+ return -1;
}
/**
- * Return a raw double-precision floating-point value (no type coercion).
+ * Locate another node, given a relative path.
*/
-double
-FGValue::getRawDouble () const
+static SGPropertyNode *
+find_node (SGPropertyNode * current,
+ const vector<PathComponent> &components,
+ int position,
+ bool create)
{
- if (_tied) {
- if (_value.double_func.getter != 0)
- return (*(_value.double_func.getter))();
+ // 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);
+ }
+
+ // .. 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 0.0L;
- } else {
- return _value.double_val;
+ return find_node(parent, components, position + 1, create);
+ }
+
+ // Otherwise, a child name
+ else {
+ SGPropertyNode * child =
+ current->getChild(components[position].name.c_str(),
+ components[position].index,
+ create);
+ return find_node(child, components, position + 1, create);
}
}
-/**
- * Return a raw string value (no type coercion).
- */
-const string &
-FGValue::getRawString () const
+\f
+////////////////////////////////////////////////////////////////////////
+// Private methods from SGPropertyNode (may be inlined for speed).
+////////////////////////////////////////////////////////////////////////
+
+inline bool
+SGPropertyNode::get_bool () const
{
- if (_tied && _value.string_func.getter != 0)
- return (*(_value.string_func.getter))();
+ if (_tied)
+ return _value.bool_val->getValue();
else
- return string_val;
+ return _local_val.bool_val;
}
+inline int
+SGPropertyNode::get_int () const
+{
+ if (_tied)
+ return _value.int_val->getValue();
+ else
+ return _local_val.int_val;
+}
-/**
- * Set a raw boolean value (no type coercion).
- *
- * Return false if the value could not be set, true otherwise.
- */
-bool
-FGValue::setRawBool (bool value)
+inline long
+SGPropertyNode::get_long () const
+{
+ if (_tied)
+ return _value.long_val->getValue();
+ else
+ return _local_val.long_val;
+}
+
+inline float
+SGPropertyNode::get_float () const
+{
+ 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_func.setter != 0) {
- (*_value.bool_func.setter)(value);
+ if (_value.bool_val->setValue(val)) {
+ fireValueChanged();
return true;
} else {
return false;
}
} else {
- _value.bool_val = value;
+ _local_val.bool_val = val;
+ fireValueChanged();
return true;
}
}
-
-/**
- * Set a raw integer value (no type coercion).
- *
- * Return false if the value could not be set, true otherwise.
- */
-bool
-FGValue::setRawInt (int value)
+inline bool
+SGPropertyNode::set_int (int val)
{
if (_tied) {
- if (_value.int_func.setter != 0) {
- (*_value.int_func.setter)(value);
+ if (_value.int_val->setValue(val)) {
+ fireValueChanged();
return true;
} else {
return false;
}
} else {
- _value.int_val = value;
+ _local_val.int_val = val;
+ fireValueChanged();
return true;
}
}
-
-/**
- * Set a raw floating-point value (no type coercion).
- *
- * Return false if the value could not be set, true otherwise.
- */
-bool
-FGValue::setRawFloat (float value)
+inline bool
+SGPropertyNode::set_long (long val)
{
if (_tied) {
- if (_value.float_func.setter != 0) {
- (*_value.float_func.setter)(value);
+ if (_value.long_val->setValue(val)) {
+ fireValueChanged();
return true;
} else {
return false;
}
} else {
- _value.float_val = value;
+ _local_val.long_val = val;
+ fireValueChanged();
return true;
}
}
-
-/**
- * Set a raw double-precision floating-point value (no type coercion).
- *
- * Return false if the value could not be set, true otherwise.
- */
-bool
-FGValue::setRawDouble (double value)
+inline bool
+SGPropertyNode::set_float (float val)
{
if (_tied) {
- if (_value.double_func.setter != 0) {
- (*_value.double_func.setter)(value);
+ if (_value.float_val->setValue(val)) {
+ fireValueChanged();
return true;
} else {
return false;
}
} else {
- _value.double_val = value;
+ _local_val.float_val = val;
+ fireValueChanged();
return true;
}
}
-
-/**
- * Set a raw string value (no type coercion).
- *
- * Return false if the value could not be set, true otherwise.
- */
-bool
-FGValue::setRawString (const string &value)
+inline bool
+SGPropertyNode::set_double (double val)
{
if (_tied) {
- if (_value.string_func.setter != 0) {
- (*_value.string_func.setter)(value);
+ if (_value.double_val->setValue(val)) {
+ fireValueChanged();
return true;
} else {
return false;
}
} else {
- string_val = value;
+ _local_val.double_val = val;
+ fireValueChanged();
return true;
}
}
-
-/**
- * Get the boolean value of a property.
- *
- * If the native type is not boolean, attempt to coerce it.
- */
-bool
-FGValue::getBoolValue () const
+inline bool
+SGPropertyNode::set_string (const char * val)
{
- switch (_type) {
- 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 UNKNOWN:
- case STRING:
- return ((getRawString() == "false" || getIntValue() == 0) ? false : true);
+ 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;
}
- return false;
}
-
-/**
- * Get the integer value of a property.
- *
- * If the native type is not integer, attempt to coerce it.
- */
-int
-FGValue::getIntValue () const
+void
+SGPropertyNode::clear_value ()
{
switch (_type) {
+ case NONE:
+ break;
+ case ALIAS:
+ _value.alias = 0;
+ break;
case BOOL:
- return getRawBool();
+ if (_tied) {
+ delete _value.bool_val;
+ _value.bool_val = 0;
+ }
+ _local_val.bool_val = SGRawValue<bool>::DefaultValue;
+ break;
case INT:
- return getRawInt();
+ if (_tied) {
+ delete _value.int_val;
+ _value.int_val = 0;
+ }
+ _local_val.int_val = SGRawValue<int>::DefaultValue;
+ break;
+ case LONG:
+ if (_tied) {
+ delete _value.long_val;
+ _value.long_val = 0L;
+ }
+ _local_val.long_val = SGRawValue<long>::DefaultValue;
+ break;
case FLOAT:
- return (int)(getRawFloat());
+ if (_tied) {
+ delete _value.float_val;
+ _value.float_val = 0;
+ }
+ _local_val.float_val = SGRawValue<float>::DefaultValue;
+ break;
case DOUBLE:
- return (int)(getRawDouble());
- case UNKNOWN:
+ if (_tied) {
+ delete _value.double_val;
+ _value.double_val = 0;
+ }
+ _local_val.double_val = SGRawValue<double>::DefaultValue;
+ break;
case STRING:
- return atoi(getRawString().c_str());
+ case UNSPECIFIED:
+ if (_tied) {
+ delete _value.string_val;
+ _value.string_val = 0;
+ } else {
+ delete [] _local_val.string_val;
+ }
+ _local_val.string_val = 0;
+ break;
}
- return false;
+ _tied = false;
+ _type = NONE;
}
/**
- * Get the floating-point value of a property.
- *
- * If the native type is not float, attempt to coerce it.
+ * Get the value as a string.
*/
-float
-FGValue::getFloatValue () const
+const char *
+SGPropertyNode::make_string () const
{
+ if (!getAttribute(READ))
+ return "";
+
switch (_type) {
- case UNKNOWN:
- return 0.0;
+ case ALIAS:
+ return _value.alias->getStringValue();
case BOOL:
- return (float)(getRawBool());
+ if (get_bool())
+ return "true";
+ else
+ return "false";
case INT:
- return (float)(getRawInt());
+ sprintf(_buffer, "%d", get_int());
+ return _buffer;
+ case LONG:
+ sprintf(_buffer, "%ld", get_long());
+ return _buffer;
case FLOAT:
- return getRawFloat();
+ sprintf(_buffer, "%f", get_float());
+ return _buffer;
case DOUBLE:
- return (float)(getRawDouble());
+ sprintf(_buffer, "%f", get_double());
+ return _buffer;
case STRING:
- return (float)atof(getRawString().c_str());
+ case UNSPECIFIED:
+ return get_string();
+ case NONE:
+ default:
+ return "";
}
- return false;
}
-
/**
- * Get the double-precision floating-point value of a property.
- *
- * If the native type is not double, attempt to coerce it.
+ * Trace a write access for a property.
*/
-double
-FGValue::getDoubleValue () const
+void
+SGPropertyNode::trace_write () const
{
- 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());
- }
- return false;
+#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
}
-
/**
- * Get the string value of a property.
- *
- * If the native type is not string, attempt to coerce it.
+ * Trace a read access for a property.
*/
-const string &
-FGValue::getStringValue () const
+void
+SGPropertyNode::trace_read () const
{
- char buf[512];
- switch (_type) {
- case UNKNOWN:
- return getRawString();
- case BOOL:
- if (getRawBool())
- string_val = "true";
- else
- string_val = "false";
- return string_val;
- case INT:
- sprintf(buf, "%d", getRawInt());
- string_val = buf;
- return string_val;
- case FLOAT:
- sprintf(buf, "%f", getRawFloat());
- string_val = buf;
- return string_val;
- case DOUBLE:
- sprintf(buf, "%f", getRawDouble());
- string_val = buf;
- return string_val;
- case STRING:
- return getRawString();
- }
- return empty_string;
+#if PROPS_STANDALONE
+ cerr << "TRACE: Write node " << getPath () << ", value \""
+ << make_string() << '"' << endl;
+#else
+ SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Read node " << getPath()
+ << ", value \"" << make_string() << '"');
+#endif
}
-
/**
- * Set the boolean value and change the type if unknown.
- *
- * Returns true on success.
+ * Increment reference counter
*/
-bool
-FGValue::setBoolValue (bool value)
+void
+SGPropertyNode::incrementRef()
{
- if (_type == UNKNOWN || _type == BOOL) {
- _type = BOOL;
- return setRawBool(value);
- } else {
- return false;
- }
+ ++_count;
}
-
/**
- * Set the integer value and change the type if unknown.
- *
- * Returns true on success.
+ * Decrement reference counter
*/
-bool
-FGValue::setIntValue (int value)
+int
+SGPropertyNode::decrementRef()
{
- if (_type == UNKNOWN || _type == INT) {
- _type = INT;
- return setRawInt(value);
- } else {
- return false;
- }
+ return --_count;
}
+\f
+////////////////////////////////////////////////////////////////////////
+// Public methods from SGPropertyNode.
+////////////////////////////////////////////////////////////////////////
+
/**
- * Set the floating-point value and change the type if unknown.
- *
- * Returns true on success.
+ * Last used attribute
+ * Update as needed when enum Attribute is changed
*/
-bool
-FGValue::setFloatValue (float value)
-{
- if (_type == UNKNOWN || _type == FLOAT) {
- _type = FLOAT;
- return setRawFloat(value);
- } else {
- return false;
- }
-}
-
+const int SGPropertyNode::LAST_USED_ATTRIBUTE = TRACE_WRITE;
/**
- * Set the double-precision value and change the type if unknown.
- *
- * Returns true on success.
+ * Default constructor: always creates a root node.
*/
-bool
-FGValue::setDoubleValue (double value)
+SGPropertyNode::SGPropertyNode ()
+ : _name(copy_string("")),
+ _index(0),
+ _parent(0),
+ _path_cache(0),
+ _type(NONE),
+ _tied(false),
+ _attr(READ|WRITE),
+ _count(0),
+ _listeners(0)
{
- if (_type == UNKNOWN || _type == DOUBLE) {
- _type = DOUBLE;
- return setRawDouble(value);
- } else {
- return false;
- }
+ _local_val.string_val = 0;
}
/**
- * Set the string value and change the type if unknown.
- *
- * Returns true on success.
+ * Copy constructor.
*/
-bool
-FGValue::setStringValue (const string &value)
+SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
+ : _index(node._index),
+ _parent(0), // don't copy the parent
+ _path_cache(0),
+ _type(node._type),
+ _tied(node._tied),
+ _attr(node._attr),
+ _count(0),
+ _listeners(0) // CHECK!!
{
- if (_type == UNKNOWN || _type == STRING) {
- _type = STRING;
- return setRawString(value);
- } else {
- return false;
- }
-}
+ _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;
+ }
+}
/**
- * Set a string value and don't modify the type.
- *
- * Returns true on success.
+ * Convenience constructor.
*/
-bool
-FGValue::setUnknownValue (const string &value)
+SGPropertyNode::SGPropertyNode (const char * name,
+ int index,
+ SGPropertyNode * parent)
+ : _index(index),
+ _parent(parent),
+ _path_cache(0),
+ _type(NONE),
+ _tied(false),
+ _attr(READ|WRITE),
+ _count(0),
+ _listeners(0)
{
- if (_type == UNKNOWN || _type == STRING) {
- return setRawString(value);
- } else {
- return false;
- }
+ _name = copy_string(name);
+ _local_val.string_val = 0;
}
/**
- * Tie a boolean value to external functions.
- *
- * If useDefault is true, attempt the assign the current value
- * (if any) after tying the functions.
- *
- * Returns true on success (i.e. the value is not currently tied).
+ * Destructor.
*/
-bool
-FGValue::tieBool (bool_getter getter, bool_setter setter = 0,
- bool useDefault = true)
+SGPropertyNode::~SGPropertyNode ()
{
- 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;
- }
+ delete [] _name;
+ delete _path_cache;
+ clear_value();
+ delete _listeners;
}
/**
- * Tie an integer value to external functions.
- *
- * If useDefault is true, attempt the assign the current value
- * (if any) after tying the functions.
- *
- * Returns true on success (i.e. the value is not currently tied).
+ * Alias to another node.
*/
bool
-FGValue::tieInt (int_getter getter, int_setter setter = 0,
- bool useDefault = true)
+SGPropertyNode::alias (SGPropertyNode * target)
{
- if (_tied) {
+ if (target == 0 || _type == ALIAS || _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;
- }
+ clear_value();
+ _value.alias = target;
+ _type = ALIAS;
+ return true;
}
/**
- * Tie a floating-point value to external functions.
- *
- * If useDefault is true, attempt the assign the current value
- * (if any) after tying the functions.
- *
- * Returns true on success (i.e. the value is not currently tied).
+ * Alias to another node by path.
*/
bool
-FGValue::tieFloat (float_getter getter, float_setter setter = 0,
- bool useDefault = true)
+SGPropertyNode::alias (const char * path)
{
- 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;
- }
+ return alias(getNode(path, true));
}
/**
- * Tie a double-precision floating-point value to external functions.
- *
- * If useDefault is true, attempt the assign the current value
- * (if any) after tying the functions.
- *
- * Returns true on success (i.e. the value is not currently tied).
+ * Remove an alias.
*/
bool
-FGValue::tieDouble (double_getter getter, double_setter setter = 0,
- bool useDefault = true)
+SGPropertyNode::unalias ()
{
- if (_tied) {
+ if (_type != ALIAS)
return false;
+ _type = NONE;
+ _value.alias = 0;
+ return true;
+}
+
+
+/**
+ * Get the target of an alias.
+ */
+SGPropertyNode *
+SGPropertyNode::getAliasTarget ()
+{
+ return (_type == ALIAS ? _value.alias : 0);
+}
+
+
+const SGPropertyNode *
+SGPropertyNode::getAliasTarget () const
+{
+ return (_type == ALIAS ? _value.alias : 0);
+}
+
+
+/**
+ * Get a non-const child by index.
+ */
+SGPropertyNode *
+SGPropertyNode::getChild (int position)
+{
+ if (position >= 0 && position < nChildren())
+ return _children[position];
+ else
+ return 0;
+}
+
+
+/**
+ * Get a const child by index.
+ */
+const SGPropertyNode *
+SGPropertyNode::getChild (int position) const
+{
+ if (position >= 0 && position < nChildren())
+ return _children[position];
+ else
+ return 0;
+}
+
+
+/**
+ * Get a non-const child by name and index, creating if necessary.
+ */
+SGPropertyNode *
+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) {
+ 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 {
- if (useDefault && setter && _type != UNKNOWN)
- (*setter)(getDoubleValue());
- _tied = true;
- _type = DOUBLE;
- _value.double_func.getter = getter;
- _value.double_func.setter = setter;
- return true;
+ return 0;
}
}
/**
- * Tie a string value to external functions.
- *
- * If useDefault is true, attempt the assign the current value
- * (if any) after tying the functions.
- *
- * Returns true on success (i.e. the value is not currently tied).
+ * Get a const child by name and index.
*/
+const SGPropertyNode *
+SGPropertyNode::getChild (const char * name, int index) const
+{
+ int pos = find_child(name, index, _children);
+ if (pos >= 0)
+ return _children[pos];
+ else
+ return 0;
+}
+
+
+/**
+ * Get all children with the same name (but different indices).
+ */
+vector<SGPropertyNode_ptr>
+SGPropertyNode::getChildren (const char * name) const
+{
+ vector<SGPropertyNode_ptr> children;
+ int max = _children.size();
+
+ for (int i = 0; i < max; i++)
+ if (compare_strings(_children[i]->getName(), name))
+ children.push_back(_children[i]);
+
+ sort(children.begin(), children.end(), CompareIndices());
+ return children;
+}
+
+
+/**
+ * Remove a child node
+ */
+SGPropertyNode_ptr
+SGPropertyNode::removeChild (const char * name, int index, bool keep)
+{
+ 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;
+}
+
+
+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;
+ }
+ strncpy(_buffer, path.c_str(), MAX_STRING_LEN);
+ return _buffer;
+}
+
+SGPropertyNode::Type
+SGPropertyNode::getType () const
+{
+ if (_type == ALIAS)
+ return _value.alias->getType();
+ else
+ return _type;
+}
+
+
+bool
+SGPropertyNode::getBoolValue () const
+{
+ // 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();
+ 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 UNSPECIFIED:
+ return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L);
+ case NONE:
+ default:
+ return SGRawValue<bool>::DefaultValue;
+ }
+}
+
+int
+SGPropertyNode::getIntValue () const
+{
+ // 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());
+ 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 UNSPECIFIED:
+ return atoi(get_string());
+ case NONE:
+ default:
+ return SGRawValue<int>::DefaultValue;
+ }
+}
+
+long
+SGPropertyNode::getLongValue () const
+{
+ // 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());
+ 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 UNSPECIFIED:
+ return strtol(get_string(), 0, 0);
+ case NONE:
+ default:
+ return SGRawValue<long>::DefaultValue;
+ }
+}
+
+float
+SGPropertyNode::getFloatValue () const
+{
+ // 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());
+ 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 UNSPECIFIED:
+ return atof(get_string());
+ case NONE:
+ default:
+ return SGRawValue<float>::DefaultValue;
+ }
+}
+
+double
+SGPropertyNode::getDoubleValue () const
+{
+ // 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());
+ 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 UNSPECIFIED:
+ return strtod(get_string(), 0);
+ case NONE:
+ default:
+ return SGRawValue<double>::DefaultValue;
+ }
+}
+
+const char *
+SGPropertyNode::getStringValue () const
+{
+ // 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
-FGValue::tieString (string_getter getter, string_setter setter = 0,
- bool useDefault = true)
+SGPropertyNode::setBoolValue (bool value)
{
- if (_tied) {
- return false;
- } else {
- if (useDefault && setter && _type != UNKNOWN)
- (*setter)(getStringValue());
- _tied = true;
+ // 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();
+ _tied = false;
+ _type = BOOL;
+ }
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setBoolValue(value);
+ break;
+ case BOOL:
+ result = set_bool(value);
+ break;
+ case INT:
+ result = set_int(int(value));
+ break;
+ case LONG:
+ result = set_long(long(value));
+ break;
+ case FLOAT:
+ result = set_float(float(value));
+ break;
+ case DOUBLE:
+ result = set_double(double(value));
+ break;
+ case STRING:
+ case UNSPECIFIED:
+ result = set_string(value ? "true" : "false");
+ break;
+ case NONE:
+ default:
+ break;
+ }
+
+ 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();
+ _type = INT;
+ _local_val.int_val = 0;
+ }
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setIntValue(value);
+ break;
+ case BOOL:
+ result = set_bool(value == 0 ? false : true);
+ break;
+ case INT:
+ result = set_int(value);
+ break;
+ case LONG:
+ result = set_long(long(value));
+ break;
+ case FLOAT:
+ result = set_float(float(value));
+ break;
+ case DOUBLE:
+ result = set_double(double(value));
+ break;
+ case STRING:
+ case UNSPECIFIED: {
+ char buf[128];
+ sprintf(buf, "%d", value);
+ result = set_string(buf);
+ break;
+ }
+ case NONE:
+ default:
+ break;
+ }
+
+ 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();
+ _type = LONG;
+ _local_val.long_val = 0L;
+ }
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setLongValue(value);
+ break;
+ case BOOL:
+ result = set_bool(value == 0L ? false : true);
+ break;
+ case INT:
+ result = set_int(int(value));
+ break;
+ case LONG:
+ result = set_long(value);
+ break;
+ case FLOAT:
+ result = set_float(float(value));
+ break;
+ case DOUBLE:
+ result = set_double(double(value));
+ break;
+ case STRING:
+ case UNSPECIFIED: {
+ char buf[128];
+ sprintf(buf, "%ld", value);
+ result = set_string(buf);
+ break;
+ }
+ case NONE:
+ default:
+ break;
+ }
+
+ 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();
+ _type = FLOAT;
+ _local_val.float_val = 0;
+ }
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setFloatValue(value);
+ break;
+ case BOOL:
+ result = set_bool(value == 0.0 ? false : true);
+ break;
+ case INT:
+ result = set_int(int(value));
+ break;
+ case LONG:
+ result = set_long(long(value));
+ break;
+ case FLOAT:
+ result = set_float(value);
+ break;
+ case DOUBLE:
+ result = set_double(double(value));
+ break;
+ case STRING:
+ case UNSPECIFIED: {
+ char buf[128];
+ sprintf(buf, "%f", value);
+ result = set_string(buf);
+ break;
+ }
+ case NONE:
+ default:
+ break;
+ }
+
+ 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();
+ _local_val.double_val = value;
+ _type = DOUBLE;
+ }
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setDoubleValue(value);
+ break;
+ case BOOL:
+ result = set_bool(value == 0.0L ? false : true);
+ break;
+ case INT:
+ result = set_int(int(value));
+ break;
+ case LONG:
+ result = set_long(long(value));
+ break;
+ case FLOAT:
+ result = set_float(float(value));
+ break;
+ case DOUBLE:
+ result = set_double(value);
+ break;
+ case STRING:
+ case UNSPECIFIED: {
+ char buf[128];
+ sprintf(buf, "%f", value);
+ result = set_string(buf);
+ break;
+ }
+ case NONE:
+ default:
+ break;
+ }
+
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
+}
+
+bool
+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();
_type = STRING;
- _value.string_func.getter = getter;
- _value.string_func.setter = setter;
- return true;
}
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setStringValue(value);
+ break;
+ case BOOL:
+ result = set_bool((compare_strings(value, "true")
+ || atoi(value)) ? true : false);
+ break;
+ case INT:
+ result = set_int(atoi(value));
+ break;
+ case LONG:
+ result = set_long(strtol(value, 0, 0));
+ break;
+ case FLOAT:
+ result = set_float(atof(value));
+ break;
+ case DOUBLE:
+ result = set_double(strtod(value, 0));
+ break;
+ case STRING:
+ case UNSPECIFIED:
+ result = set_string(value);
+ break;
+ case NONE:
+ default:
+ break;
+ }
+
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
}
+bool
+SGPropertyNode::setUnspecifiedValue (const char * value)
+{
+ bool result = false;
+ TEST_WRITE;
+ if (_type == NONE) {
+ clear_value();
+ _type = UNSPECIFIED;
+ }
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setUnspecifiedValue(value);
+ break;
+ case BOOL:
+ result = set_bool((compare_strings(value, "true")
+ || atoi(value)) ? true : false);
+ break;
+ case INT:
+ result = set_int(atoi(value));
+ break;
+ case LONG:
+ result = set_long(strtol(value, 0, 0));
+ break;
+ case FLOAT:
+ result = set_float(atof(value));
+ break;
+ case DOUBLE:
+ result = set_double(strtod(value, 0));
+ break;
+ case STRING:
+ case UNSPECIFIED:
+ result = set_string(value);
+ break;
+ case NONE:
+ default:
+ break;
+ }
+
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
+}
+
+bool
+SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
+{
+ if (_type == ALIAS || _tied)
+ return false;
+
+ useDefault = useDefault && hasValue();
+ bool old_val = false;
+ if (useDefault)
+ old_val = getBoolValue();
+
+ clear_value();
+ _type = BOOL;
+ _tied = true;
+ _value.bool_val = rawValue.clone();
+
+ if (useDefault)
+ setBoolValue(old_val);
+
+ return true;
+}
+
+bool
+SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
+{
+ if (_type == ALIAS || _tied)
+ return false;
+
+ useDefault = useDefault && hasValue();
+ int old_val = 0;
+ if (useDefault)
+ old_val = getIntValue();
+
+ clear_value();
+ _type = INT;
+ _tied = true;
+ _value.int_val = rawValue.clone();
+
+ if (useDefault)
+ setIntValue(old_val);
+
+ return true;
+}
+
+bool
+SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
+{
+ if (_type == ALIAS || _tied)
+ return false;
+
+ useDefault = useDefault && hasValue();
+ long old_val = 0;
+ if (useDefault)
+ old_val = getLongValue();
+
+ clear_value();
+ _type = LONG;
+ _tied = true;
+ _value.long_val = rawValue.clone();
+
+ if (useDefault)
+ setLongValue(old_val);
+
+ return true;
+}
+
+bool
+SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
+{
+ if (_type == ALIAS || _tied)
+ return false;
+
+ useDefault = useDefault && hasValue();
+ float old_val = 0.0;
+ if (useDefault)
+ old_val = getFloatValue();
+
+ clear_value();
+ _type = FLOAT;
+ _tied = true;
+ _value.float_val = rawValue.clone();
+
+ if (useDefault)
+ setFloatValue(old_val);
+
+ return true;
+}
+
+bool
+SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
+{
+ if (_type == ALIAS || _tied)
+ return false;
+
+ useDefault = useDefault && hasValue();
+ double old_val = 0.0;
+ if (useDefault)
+ old_val = getDoubleValue();
+
+ clear_value();
+ _type = DOUBLE;
+ _tied = true;
+ _value.double_val = rawValue.clone();
+
+ if (useDefault)
+ setDoubleValue(old_val);
+
+ return true;
+
+}
+
+bool
+SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool useDefault)
+{
+ if (_type == ALIAS || _tied)
+ return false;
+
+ useDefault = useDefault && hasValue();
+ string old_val;
+ if (useDefault)
+ old_val = getStringValue();
+
+ clear_value();
+ _type = STRING;
+ _tied = true;
+ _value.string_val = rawValue.clone();
+
+ if (useDefault)
+ setStringValue(old_val.c_str());
+
+ return true;
+}
-/**
- * Untie a value from external functions.
- *
- * Will always attempt to intialize the internal value from
- * the getter before untying.
- *
- * Returns true on success (i.e. the value had been tied).
- */
bool
-FGValue::untie ()
+SGPropertyNode::untie ()
{
if (!_tied)
return false;
switch (_type) {
case BOOL: {
- bool value = getRawBool();
- _tied = false;
- setRawBool(value);
+ bool val = getBoolValue();
+ clear_value();
+ _type = BOOL;
+ _local_val.bool_val = val;
break;
}
case INT: {
- int value = getRawInt();
- _tied = false;
- setRawInt(value);
+ int val = getIntValue();
+ clear_value();
+ _type = INT;
+ _local_val.int_val = val;
+ break;
+ }
+ case LONG: {
+ long val = getLongValue();
+ clear_value();
+ _type = LONG;
+ _local_val.long_val = val;
break;
}
case FLOAT: {
- float value = getRawFloat();
- _tied = false;
- setRawFloat(value);
+ float val = getFloatValue();
+ clear_value();
+ _type = FLOAT;
+ _local_val.float_val = val;
break;
}
case DOUBLE: {
- double value = getRawDouble();
- _tied = false;
- setRawDouble(value);
+ double val = getDoubleValue();
+ clear_value();
+ _type = DOUBLE;
+ _local_val.double_val = val;
break;
}
- case STRING: {
- string value = getRawString();
- _tied = false;
- setRawString(value);
+ case STRING:
+ case UNSPECIFIED: {
+ string val = getStringValue();
+ clear_value();
+ _type = STRING;
+ _local_val.string_val = copy_string(val.c_str());
break;
}
+ case NONE:
+ default:
+ break;
}
+ _tied = false;
return true;
}
+SGPropertyNode *
+SGPropertyNode::getRootNode ()
+{
+ if (_parent == 0)
+ return this;
+ else
+ return _parent->getRootNode();
+}
+
+const SGPropertyNode *
+SGPropertyNode::getRootNode () const
+{
+ if (_parent == 0)
+ return this;
+ else
+ return _parent->getRootNode();
+}
+
+SGPropertyNode *
+SGPropertyNode::getNode (const char * relative_path, bool create)
+{
+ if (_path_cache == 0)
+ _path_cache = new hash_table;
+
+ 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->put(relative_path, result);
+ }
+
+ return result;
+}
+
+SGPropertyNode *
+SGPropertyNode::getNode (const char * relative_path, int index, bool create)
+{
+ vector<PathComponent> components;
+ parse_path(relative_path, components);
+ if (components.size() > 0)
+ components[components.size()-1].index = index;
+ return find_node(this, components, 0, create);
+}
+
+const SGPropertyNode *
+SGPropertyNode::getNode (const char * relative_path) const
+{
+ return ((SGPropertyNode *)this)->getNode(relative_path, false);
+}
+
+const SGPropertyNode *
+SGPropertyNode::getNode (const char * relative_path, int index) const
+{
+ return ((SGPropertyNode *)this)->getNode(relative_path, index, false);
+}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGPropertyList.
+// Convenience methods using relative paths.
////////////////////////////////////////////////////////////////////////
/**
- * Constructor.
+ * Test whether another node has a value attached.
*/
-FGPropertyList::FGPropertyList ()
+bool
+SGPropertyNode::hasValue (const char * relative_path) const
{
+ const SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? false : node->hasValue());
}
/**
- * Destructor.
+ * Get the value type for another node.
*/
-FGPropertyList::~FGPropertyList ()
+SGPropertyNode::Type
+SGPropertyNode::getType (const char * relative_path) const
{
+ const SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? UNSPECIFIED : (Type)(node->getType()));
}
/**
- * Look up the FGValue structure associated with a property.
- *
- * Run some basic validity checks on the property name: it must
- * not be empty, must begin with '/', must never have two '//' in a row,
- * and must not end with '/'.
+ * Get a bool value for another node.
*/
-FGValue *
-FGPropertyList::getValue (const string &name, bool create = false)
-{
- 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 << '\'');
- if (name.size() == 0 ||
- name[0] != '/' ||
- name[name.size()-1] == '/' ||
- name.find("//") != string::npos) {
- FG_LOG(FG_GENERAL, FG_ALERT, "Illegal property name: '"
- << name << '\'');
- return 0;
- }
- }
- }
- return &(_props[name]);
+bool
+SGPropertyNode::getBoolValue (const char * relative_path,
+ bool defaultValue) const
+{
+ const SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? defaultValue : node->getBoolValue());
}
/**
- * Look up a const value (never created).
+ * Get an int value for another node.
*/
-const FGValue *
-FGPropertyList::getValue (const string &name) const
+int
+SGPropertyNode::getIntValue (const char * relative_path,
+ int defaultValue) const
{
- value_map::const_iterator el = _props.find(name);
- if (el == _props.end())
- return 0;
- else
- return &(el->second);
+ const SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? defaultValue : node->getIntValue());
}
/**
- * Extract a boolean from the value.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * Get a long value for another node.
*/
-bool
-FGPropertyList::getBoolValue (const string &name) const
+long
+SGPropertyNode::getLongValue (const char * relative_path,
+ long 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->getLongValue());
}
/**
- * Extract an integer from the value.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * Get a float value for another node.
*/
-int
-FGPropertyList::getIntValue (const string &name) const
+float
+SGPropertyNode::getFloatValue (const char * relative_path,
+ float 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->getFloatValue());
}
/**
- * Extract a float from the value.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * Get a double value for another node.
*/
-float
-FGPropertyList::getFloatValue (const string &name) const
+double
+SGPropertyNode::getDoubleValue (const char * relative_path,
+ double 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->getDoubleValue());
}
/**
- * Extract a double from the value.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to get the FGValue and query it repeatedly.
+ * Get a string value for another node.
*/
-double
-FGPropertyList::getDoubleValue (const string &name) const
+const char *
+SGPropertyNode::getStringValue (const char * relative_path,
+ const char * 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->getStringValue());
}
/**
- * Extract a string from the value.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and query it repeatedly.
+ * Set a bool value for another node.
*/
-const string &
-FGPropertyList::getStringValue (const string &name) const
+bool
+SGPropertyNode::setBoolValue (const char * relative_path, bool value)
{
- const FGValue * val = getValue(name);
- if (val == 0)
- return empty_string;
- else
- return val->getStringValue();
+ return getNode(relative_path, true)->setBoolValue(value);
}
/**
- * Assign a bool to the value and change the type if unknown.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
- *
- * Returns true on success.
+ * Set an int value for another node.
*/
bool
-FGPropertyList::setBoolValue (const string &name, bool value)
+SGPropertyNode::setIntValue (const char * relative_path, int value)
{
- return getValue(name, true)->setBoolValue(value);
+ return getNode(relative_path, true)->setIntValue(value);
}
/**
- * Assign an integer to the value and change the type if unknown.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
- *
- * Returns true on success.
+ * Set a long value for another node.
*/
bool
-FGPropertyList::setIntValue (const string &name, int value)
+SGPropertyNode::setLongValue (const char * relative_path, long value)
{
- return getValue(name, true)->setIntValue(value);
+ return getNode(relative_path, true)->setLongValue(value);
}
/**
- * Assign a float to the value and change the type if unknown.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
- *
- * Returns true on success.
+ * Set a float value for another node.
*/
bool
-FGPropertyList::setFloatValue (const string &name, float value)
+SGPropertyNode::setFloatValue (const char * relative_path, float value)
{
- return getValue(name, true)->setFloatValue(value);
+ return getNode(relative_path, true)->setFloatValue(value);
}
/**
- * Assign a double to the value and change the type if unknown.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
- *
- * Returns true on success.
+ * Set a double value for another node.
*/
bool
-FGPropertyList::setDoubleValue (const string &name, double value)
+SGPropertyNode::setDoubleValue (const char * relative_path, double value)
{
- return getValue(name, true)->setDoubleValue(value);
+ return getNode(relative_path, true)->setDoubleValue(value);
}
/**
- * Assign a string to the value and change the type if unknown.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
- *
- * Returns true on success.
+ * Set a string value for another node.
*/
bool
-FGPropertyList::setStringValue (const string &name, const string &value)
+SGPropertyNode::setStringValue (const char * relative_path, const char * value)
{
- return getValue(name, true)->setStringValue(value);
+ return getNode(relative_path, true)->setStringValue(value);
}
/**
- * Assign a string to the value, but don't change the type.
- *
- * Note that this is inefficient for use in a tight loop: it is
- * better to save the FGValue and modify it repeatedly.
- *
- * Returns true on success.
+ * Set an unknown value for another node.
*/
bool
-FGPropertyList::setUnknownValue (const string &name, const string &value)
+SGPropertyNode::setUnspecifiedValue (const char * relative_path,
+ const char * value)
{
- return getValue(name, true)->setUnknownValue(value);
+ return getNode(relative_path, true)->setUnspecifiedValue(value);
}
/**
- * Tie a boolean value to external functions.
- *
- * Invokes FGValue::tieBool
+ * Test whether another node is tied.
*/
bool
-FGPropertyList::tieBool (const string &name,
- bool_getter getter,
- bool_setter setter,
- bool useDefault = true)
+SGPropertyNode::isTied (const char * relative_path) const
{
- FG_LOG(FG_GENERAL, FG_INFO, "Tying bool property '" << name << '\'');
- return getValue(name, true)->tieBool(getter, setter, useDefault);
+ const SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? false : node->isTied());
}
/**
- * Tie an integer value to external functions.
- *
- * Invokes FGValue::tieInt
+ * Tie a node reached by a relative path, creating it if necessary.
*/
bool
-FGPropertyList::tieInt (const string &name,
- int_getter getter,
- int_setter setter,
- bool useDefault = true)
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<bool> &rawValue,
+ bool useDefault)
{
- FG_LOG(FG_GENERAL, FG_INFO, "Tying int property '" << name << '\'');
- return getValue(name, true)->tieInt(getter, setter, useDefault);
+ return getNode(relative_path, true)->tie(rawValue, useDefault);
}
/**
- * Tie a float value to external functions.
- *
- * Invokes FGValue::tieFloat
+ * Tie a node reached by a relative path, creating it if necessary.
*/
bool
-FGPropertyList::tieFloat (const string &name,
- float_getter getter,
- float_setter setter,
- bool useDefault = true)
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<int> &rawValue,
+ bool useDefault)
{
- FG_LOG(FG_GENERAL, FG_INFO, "Tying float property '" << name << '\'');
- return getValue(name, true)->tieFloat(getter, setter, useDefault);
+ return getNode(relative_path, true)->tie(rawValue, useDefault);
}
/**
- * Tie a double value to external functions.
- *
- * Invokes FGValue::tieDouble
+ * Tie a node reached by a relative path, creating it if necessary.
*/
bool
-FGPropertyList::tieDouble (const string &name,
- double_getter getter,
- double_setter setter,
- bool useDefault = true)
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<long> &rawValue,
+ bool useDefault)
{
- FG_LOG(FG_GENERAL, FG_INFO, "Tying double property '" << name << '\'');
- return getValue(name, true)->tieDouble(getter, setter, useDefault);
+ return getNode(relative_path, true)->tie(rawValue, useDefault);
}
/**
- * Tie a string value to external functions.
- *
- * Invokes FGValue::tieString
+ * 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 char * relative_path,
+ const SGRawValue<float> &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);
}
/**
- * Untie a value from external functions.
- *
- * Invokes FGValue::untie
+ * Tie a node reached by a relative path, creating it if necessary.
*/
bool
-FGPropertyList::untie (const string &name)
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<double> &rawValue,
+ bool useDefault)
{
- FG_LOG(FG_GENERAL, FG_INFO, "Untying property '" << name << '\'');
- return getValue(name, true)->untie();
+ return getNode(relative_path, true)->tie(rawValue, useDefault);
}
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of FGPropertyNode.
-////////////////////////////////////////////////////////////////////////
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
+bool
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<const char *> &rawValue,
+ bool useDefault)
+{
+ return getNode(relative_path, true)->tie(rawValue, useDefault);
+}
/**
- * Extract the base name of the next level down from the parent.
- *
- * The parent must have a '/' appended. Note that basename may
- * be modified even if the test fails.
+ * Attempt to untie another node reached by a relative path.
*/
-static bool
-get_base (const string &parent, const string &child,
- string &basename)
+bool
+SGPropertyNode::untie (const char * relative_path)
{
- // First, check that the parent name
- // is a prefix of the child name, and
- // extract the remainder
- if (child.find(parent) != 0)
- return false;
+ SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? false : node->untie());
+}
- basename = child.substr(parent.size());
+void
+SGPropertyNode::addChangeListener (SGPropertyChangeListener * listener)
+{
+ if (_listeners == 0)
+ _listeners = new vector<SGPropertyChangeListener *>;
+ _listeners->push_back(listener);
+ listener->register_property(this);
+}
- string::size_type pos = basename.find('/');
- if (pos != string::npos) {
- basename.resize(pos);
+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;
+ }
}
+}
- if (basename.size() == 0)
- return false;
- else
- return true;
+void
+SGPropertyNode::fireValueChanged ()
+{
+ fireValueChanged(this);
}
+void
+SGPropertyNode::fireChildAdded (SGPropertyNode * child)
+{
+ fireChildAdded(this, child);
+}
-/**
- * Constructor.
- */
-FGPropertyNode::FGPropertyNode (const string &path = "",
- FGPropertyList * props = 0)
- : _props(props)
+void
+SGPropertyNode::fireChildRemoved (SGPropertyNode * child)
{
- setPath(path);
+ fireChildRemoved(this, child);
}
+void
+SGPropertyNode::fireValueChanged (SGPropertyNode * node)
+{
+ if (_listeners != 0) {
+ for (int i = 0; i < _listeners->size(); i++) {
+ (*_listeners)[i]->valueChanged(node);
+ }
+ }
+ if (_parent != 0)
+ _parent->fireValueChanged(node);
+}
-/**
- * Destructor.
- */
-FGPropertyNode::~FGPropertyNode ()
+void
+SGPropertyNode::fireChildAdded (SGPropertyNode * parent,
+ SGPropertyNode * child)
+{
+ if (_listeners != 0) {
+ for (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 (int i = 0; i < _listeners->size(); i++) {
+ (*_listeners)[i]->childRemoved(parent, child);
+ }
+ }
+ if (_parent != 0)
+ _parent->fireChildRemoved(parent, child);
}
-/**
- * Set the path.
- *
- * Strip the trailing '/', if any.
- */
+\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
-FGPropertyNode::setPath (const string &path)
+SGPropertyNode::hash_table::entry::set_key (const char * key)
{
- _path = path;
+ _key = copy_string(key);
+}
- // Chop the final '/', if present.
- if (_path.size() > 0 && _path[_path.size()-1] == '/')
- _path.resize(_path.size()-1);
+void
+SGPropertyNode::hash_table::entry::set_value (SGPropertyNode * value)
+{
+ _value = value;
}
+SGPropertyNode::hash_table::bucket::bucket ()
+ : _length(0),
+ _entries(0)
+{
+}
-/**
- * Return the local name of the property.
- *
- * The local name is just everything after the last slash.
- */
-const string &
-FGPropertyNode::getName () const
+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)
{
- string::size_type pos = _path.rfind('/');
- if (pos != string::npos) {
- _name = _path.substr(pos+1);
- return _name;
+ 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 empty_string;
+ return 0;
}
}
-/**
- * Return the value of the current node.
- *
- * Currently, this does a lookup each time, but we could cache the
- * value safely as long as it's non-zero.
- *
- * Note that this will not create the value if it doesn't already exist.
- */
-FGValue *
-FGPropertyNode::getValue ()
+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 (_props == 0 || _path.size() == 0)
+ 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 _props->getValue(_path);
+ 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;
}
+
/**
- * Return the number of children for the current node.
+ * Default constructor
*/
-int
-FGPropertyNode::size () const
+SGPropertyNode_ptr::SGPropertyNode_ptr()
{
- if (_props == 0)
- return 0;
+ _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();
+}
- int s = 0;
+/**
+ * Destructor
+ */
+SGPropertyNode_ptr::~SGPropertyNode_ptr()
+{
+ if (_ptr && _ptr->decrementRef() == 0)
+ delete _ptr;
+}
- string base;
- string lastBase;
- string pattern = _path;
- pattern += '/';
+/**
+ * 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();
- FGPropertyList::const_iterator it = _props->begin();
- FGPropertyList::const_iterator end = _props->end();
- while (it != end) {
- if (get_base(pattern, it->first, base) && base != lastBase) {
- s++;
- lastBase = base;
- }
- it++;
- }
+ return *this;
+}
- return s;
+/**
+ * Pointer access operator
+ */
+SGPropertyNode *
+SGPropertyNode_ptr::operator->()
+{
+ return _ptr;
}
+/**
+ * Pointer access operator (const)
+ */
+const SGPropertyNode *
+SGPropertyNode_ptr::operator->() const
+{
+ return _ptr;
+}
/**
- * Initialize a node to represent this node's parent.
- *
- * A return value of true means success; otherwise, the node supplied
- * is unmodified.
+ * Conversion to SGPropertyNode * operator
*/
-bool
-FGPropertyNode::getParent (FGPropertyNode &parent) const
+SGPropertyNode_ptr::operator SGPropertyNode *()
{
- string::size_type pos = _path.rfind('/');
- if (pos != string::npos) {
- parent.setPath(_path.substr(0, pos-1));
- parent.setPropertyList(_props);
- return true;
- } else {
- return false;
- }
+ return _ptr;
}
+/**
+ * Conversion to const SGPropertyNode * operator
+ */
+SGPropertyNode_ptr::operator const SGPropertyNode *() const
+{
+ return _ptr;
+}
/**
- * Initialize a node to represent this node's nth child.
- *
- * A return value of true means success; otherwise, the node supplied
- * is unmodified.
+ * Validity test
*/
-bool
-FGPropertyNode::getChild (FGPropertyNode &child, int n) const
+bool
+SGPropertyNode_ptr::valid() const
{
- if (_props == 0)
- return false;
+ return _ptr != 0;
+}
- int s = 0;
- string base;
- string lastBase;
- string pattern = _path;
- pattern += '/';
-
- FGPropertyList::const_iterator it = _props->begin();
- FGPropertyList::const_iterator end = _props->end();
- while (it != end) {
- if (get_base(pattern, it->first, base) && base != lastBase) {
- if (s == n) {
- string path = _path;
- path += '/';
- path += base;
- child.setPath(path);
- child.setPropertyList(_props);
- return true;
- } else {
- s++;
- lastBase = base;
- }
- }
- it++;
- }
- return false;
+\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