//
// $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::sort;
+
+#else
#include <simgear/compiler.h>
+#include <simgear/debug/logstream.hxx>
-#include <stdio.h>
-#include <stdlib.h>
-#include STL_IOSTREAM
-#include <algorithm>
-#include "props.hxx"
+SG_USING_STD(sort);
-#if !defined(FG_HAVE_NATIVE_SGI_COMPILERS)
-FG_USING_STD(cerr);
-FG_USING_STD(endl);
#endif
-FG_USING_STD(sort);
\f
////////////////////////////////////////////////////////////////////////
-// Convenience macros for value access.
+// Local classes.
////////////////////////////////////////////////////////////////////////
-#define GET_BOOL (_value.bool_val->getValue())
-#define GET_INT (_value.int_val->getValue())
-#define GET_FLOAT (_value.float_val->getValue())
-#define GET_DOUBLE (_value.double_val->getValue())
-#define GET_STRING (_value.string_val->getValue())
+/**
+ * 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 SET_BOOL(val) (_value.bool_val->setValue(val))
-#define SET_INT(val) (_value.int_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))
+#define TEST_READ(dflt) if (!getAttribute(READ)) return dflt
+#define TEST_WRITE if (!getAttribute(WRITE)) return false
\f
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 = "";
+const char * const SGRawValue<const char *>::DefaultValue = "";
\f
*
* Name: [_a-zA-Z][-._a-zA-Z0-9]*
*/
-static inline string
+static inline const string
parse_name (const string &path, int &i)
{
string name = "";
////////////////////////////////////////////////////////////////////////
+static const char *
+copy_string (const char * s)
+{
+ // FIXME: potential buffer overflow.
+ // For some reason, strnlen and
+ // strncpy cause all kinds of crashes.
+ char * copy = new char[strlen(s) + 1];
+ strcpy(copy, s);
+ return copy;
+}
+
+static bool
+compare_strings (const char * s1, const char * s2)
+{
+ return !strncmp(s1, s2, SGPropertyNode::MAX_STRING_LEN);
+}
+
/**
* Locate a child node by name and index.
*/
static int
-find_child (const string &name, int index, vector<SGPropertyNode *> nodes)
+find_child (const char * name, int index, vector<SGPropertyNode *> nodes)
{
int nNodes = nodes.size();
for (int i = 0; i < nNodes; i++) {
SGPropertyNode * node = nodes[i];
- if (node->getName() == name && node->getIndex() == index)
+ if (compare_strings(node->getName(), name) && node->getIndex() == index)
return i;
}
return -1;
int position,
bool create)
{
+ // Run off the end of the list
if (current == 0) {
return 0;
}
- else if (position >= components.size()) {
+ // 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)
return find_node(parent, components, position + 1, create);
}
+ // Otherwise, a child name
else {
SGPropertyNode * child =
- current->getChild(components[position].name,
+ current->getChild(components[position].name.c_str(),
components[position].index,
create);
return find_node(child, components, position + 1, create);
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of SGValue.
+// Private methods from SGPropertyNode (may be inlined for speed).
////////////////////////////////////////////////////////////////////////
+inline bool
+SGPropertyNode::get_bool () const
+{
+ if (_tied)
+ return _value.bool_val->getValue();
+ else
+ return _local_val.bool_val;
+}
-/**
- * Default constructor.
- *
- * The type will be UNKNOWN and the raw value will be "".
- */
-SGValue::SGValue ()
- : _type(UNKNOWN), _tied(false)
+inline int
+SGPropertyNode::get_int () const
{
- _value.string_val = new SGRawValueInternal<string>;
+ if (_tied)
+ return _value.int_val->getValue();
+ else
+ return _local_val.int_val;
}
+inline long
+SGPropertyNode::get_long () const
+{
+ if (_tied)
+ return _value.long_val->getValue();
+ else
+ return _local_val.long_val;
+}
-/**
- * Copy constructor.
- */
-SGValue::SGValue (const SGValue &source)
+inline float
+SGPropertyNode::get_float () const
{
- _type = source._type;
- _tied = source._tied;
- switch (source._type) {
- case BOOL:
- _value.bool_val = source._value.bool_val->clone();
- break;
- case INT:
- _value.int_val = source._value.int_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;
+ 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) {
+ return _value.bool_val->setValue(val);
+ } else {
+ _local_val.bool_val = val;
+ return true;
}
}
+inline bool
+SGPropertyNode::set_int (int val)
+{
+ if (_tied) {
+ return _value.int_val->setValue(val);
+ } else {
+ _local_val.int_val = val;
+ return true;
+ }
+}
-/**
- * Destructor.
- */
-SGValue::~SGValue ()
+inline bool
+SGPropertyNode::set_long (long val)
{
- clear_value();
+ if (_tied) {
+ return _value.long_val->setValue(val);
+ } else {
+ _local_val.long_val = val;
+ return true;
+ }
+}
+
+inline bool
+SGPropertyNode::set_float (float val)
+{
+ if (_tied) {
+ return _value.float_val->setValue(val);
+ } else {
+ _local_val.float_val = val;
+ return true;
+ }
}
+inline bool
+SGPropertyNode::set_double (double val)
+{
+ if (_tied) {
+ return _value.double_val->setValue(val);
+ } else {
+ _local_val.double_val = val;
+ return true;
+ }
+}
+
+inline bool
+SGPropertyNode::set_string (const char * val)
+{
+ if (_tied) {
+ return _value.string_val->setValue(val);
+ } else {
+ delete [] (char *)_local_val.string_val;
+ _local_val.string_val = copy_string(val);
+ return true;
+ }
+}
-/**
- * Delete and clear the current value.
- */
void
-SGValue::clear_value ()
+SGPropertyNode::clear_value ()
{
switch (_type) {
+ case NONE:
+ break;
+ case ALIAS:
+ _value.alias = 0;
+ break;
case BOOL:
- delete _value.bool_val;
- _value.bool_val = 0;
+ if (_tied) {
+ delete _value.bool_val;
+ _value.bool_val = 0;
+ }
+ _local_val.bool_val = SGRawValue<bool>::DefaultValue;
break;
case INT:
- delete _value.int_val;
- _value.int_val = 0;
+ if (_tied) {
+ delete _value.int_val;
+ _value.int_val = 0;
+ }
+ _local_val.int_val = SGRawValue<int>::DefaultValue;
+ break;
+ case LONG:
+ if (_tied) {
+ delete _value.long_val;
+ _value.long_val = 0L;
+ }
+ _local_val.long_val = SGRawValue<long>::DefaultValue;
break;
case FLOAT:
- delete _value.float_val;
- _value.float_val = 0;
+ if (_tied) {
+ delete _value.float_val;
+ _value.float_val = 0;
+ }
+ _local_val.float_val = SGRawValue<float>::DefaultValue;
break;
case DOUBLE:
- delete _value.double_val;
- _value.double_val = 0;
+ if (_tied) {
+ delete _value.double_val;
+ _value.double_val = 0;
+ }
+ _local_val.double_val = SGRawValue<double>::DefaultValue;
break;
case STRING:
- case UNKNOWN:
- delete _value.string_val;
- _value.string_val = 0;
+ case UNSPECIFIED:
+ if (_tied) {
+ delete _value.string_val;
+ _value.string_val = 0;
+ } else {
+ delete [] (char *)_local_val.string_val;
+ }
+ _local_val.string_val = 0;
break;
}
+ _tied = false;
+ _type = NONE;
}
/**
- * Get a boolean value.
+ * Get the value as a string.
*/
-bool
-SGValue::getBoolValue () const
+const char *
+SGPropertyNode::make_string () const
{
+ if (!getAttribute(READ))
+ return "";
+
switch (_type) {
+ case ALIAS:
+ return _value.alias->getStringValue();
case BOOL:
- return GET_BOOL;
+ if (get_bool())
+ return "true";
+ else
+ return "false";
case INT:
- return GET_INT == 0 ? false : true;
+ sprintf(_buffer, "%d", get_int());
+ return _buffer;
+ case LONG:
+ sprintf(_buffer, "%ld", get_long());
+ return _buffer;
case FLOAT:
- return GET_FLOAT == 0.0 ? false : true;
+ sprintf(_buffer, "%f", get_float());
+ return _buffer;
case DOUBLE:
- return GET_DOUBLE == 0.0L ? false : true;
+ sprintf(_buffer, "%f", get_double());
+ return _buffer;
case STRING:
- case UNKNOWN:
- return (GET_STRING == "true" || getDoubleValue() != 0.0L);
+ case UNSPECIFIED:
+ return get_string();
+ case NONE:
+ default:
+ return "";
}
}
+/**
+ * Trace a write access for a property.
+ */
+void
+SGPropertyNode::trace_write () const
+{
+#if PROPS_STANDALONE
+ cerr << "TRACE: Write node " << getPath () << ", value\""
+ << make_string() << '"' << endl;
+#else
+ SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Write node " << getPath()
+ << ", value\"" << make_string() << '"');
+#endif
+}
/**
- * Get an integer value.
+ * Trace a read access for a property.
*/
-int
-SGValue::getIntValue () const
-{
- switch (_type) {
- case BOOL:
- return (int)GET_BOOL;
- case INT:
- return GET_INT;
- case FLOAT:
- return (int)GET_FLOAT;
- case DOUBLE:
- return (int)GET_DOUBLE;
- case STRING:
- case UNKNOWN:
- return atoi(GET_STRING.c_str());
- }
+void
+SGPropertyNode::trace_read () const
+{
+#if PROPS_STANDALONE
+ cerr << "TRACE: Write node " << getPath () << ", value \""
+ << make_string() << '"' << endl;
+#else
+ SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Read node " << getPath()
+ << ", value \"" << make_string() << '"');
+#endif
}
+\f
+////////////////////////////////////////////////////////////////////////
+// Public methods from SGPropertyNode.
+////////////////////////////////////////////////////////////////////////
+
/**
- * Get a float value.
+ * Default constructor: always creates a root node.
*/
-float
-SGValue::getFloatValue () const
+SGPropertyNode::SGPropertyNode ()
+ : _name(copy_string("")),
+ _index(0),
+ _parent(0),
+ _path_cache(0),
+ _type(NONE),
+ _tied(false),
+ _attr(READ|WRITE)
{
- switch (_type) {
- case BOOL:
- return (float)GET_BOOL;
- case INT:
- return (float)GET_INT;
- case FLOAT:
- return GET_FLOAT;
- case DOUBLE:
- return GET_DOUBLE;
- case STRING:
- case UNKNOWN:
- return atof(GET_STRING.c_str());
- }
+ _local_val.string_val = 0;
}
/**
- * Get a double value.
+ * Copy constructor.
*/
-double
-SGValue::getDoubleValue () const
-{
+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)
+{
+ _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:
- return (double)GET_BOOL;
+ if (_tied) {
+ _tied = true;
+ _value.bool_val = node._value.bool_val->clone();
+ } else {
+ _tied = false;
+ set_bool(node.get_bool());
+ }
+ break;
case INT:
- return (double)GET_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:
- return (double)GET_FLOAT;
+ if (_tied) {
+ _tied = true;
+ _value.float_val = node._value.float_val->clone();
+ } else {
+ _tied = false;
+ set_float(node.get_float());
+ }
+ break;
case DOUBLE:
- return GET_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 UNKNOWN:
- return (double)atof(GET_STRING.c_str());
+ case UNSPECIFIED:
+ if (_tied) {
+ _tied = true;
+ _value.string_val = node._value.string_val->clone();
+ } else {
+ _tied = false;
+ set_string(node.get_string());
+ }
+ break;
}
}
/**
- * Get a string value.
+ * Convenience constructor.
*/
-string
-SGValue::getStringValue () const
+SGPropertyNode::SGPropertyNode (const char * name,
+ int index,
+ SGPropertyNode * parent)
+ : _index(index),
+ _parent(parent),
+ _path_cache(0),
+ _type(NONE),
+ _tied(false),
+ _attr(READ|WRITE)
{
- char buf[128];
-
- switch (_type) {
- case BOOL:
- if (GET_BOOL)
- return "true";
- else
- return "false";
- case INT:
- sprintf(buf, "%d", GET_INT);
- return buf;
- case FLOAT:
- sprintf(buf, "%f", GET_FLOAT);
- return buf;
- case DOUBLE:
- sprintf(buf, "%lf", GET_DOUBLE);
- return buf;
- case STRING:
- case UNKNOWN:
- return GET_STRING;
- }
+ _name = copy_string(name);
+ _local_val.string_val = 0;
}
/**
- * Set a bool value.
+ * Destructor.
*/
-bool
-SGValue::setBoolValue (bool value)
+SGPropertyNode::~SGPropertyNode ()
{
- if (_type == UNKNOWN) {
- clear_value();
- _value.bool_val = new SGRawValueInternal<bool>;
- _type = BOOL;
- }
-
- switch (_type) {
- case BOOL:
- return SET_BOOL(value);
- case INT:
- return SET_INT((int)value);
- case FLOAT:
- return SET_FLOAT((float)value);
- case DOUBLE:
- return SET_DOUBLE((double)value);
- case STRING:
- return SET_STRING(value ? "true" : "false");
+ delete [] (char *)_name;
+ for (int i = 0; i < (int)_children.size(); i++) {
+ delete _children[i];
}
-
- return false;
+// delete _path_cache;
+ clear_value();
}
/**
- * Set an int value.
+ * Alias to another node.
*/
bool
-SGValue::setIntValue (int value)
+SGPropertyNode::alias (SGPropertyNode * target)
{
- if (_type == UNKNOWN) {
- clear_value();
- _value.int_val = new SGRawValueInternal<int>;
- _type = INT;
- }
-
- switch (_type) {
- case BOOL:
- return SET_BOOL(value == 0 ? false : true);
- case INT:
- return SET_INT(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;
+ if (target == 0 || _type == ALIAS || _tied)
+ return false;
+ clear_value();
+ _value.alias = target;
+ _type = ALIAS;
+ return true;
}
/**
- * Set a float value.
+ * Alias to another node by path.
*/
bool
-SGValue::setFloatValue (float value)
+SGPropertyNode::alias (const char * path)
{
- if (_type == UNKNOWN) {
- clear_value();
- _value.float_val = new SGRawValueInternal<float>;
- _type = FLOAT;
- }
+ return alias(getNode(path, true));
+}
- switch (_type) {
- case BOOL:
- return SET_BOOL(value == 0.0 ? false : true);
- case INT:
- return SET_INT((int)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;
+/**
+ * Remove an alias.
+ */
+bool
+SGPropertyNode::unalias ()
+{
+ if (_type != ALIAS)
+ return false;
+ _type = NONE;
+ _value.alias = 0;
+ return true;
}
/**
- * Set a double value.
+ * Get the target of an alias.
*/
-bool
-SGValue::setDoubleValue (double value)
+SGPropertyNode *
+SGPropertyNode::getAliasTarget ()
{
- if (_type == UNKNOWN) {
- clear_value();
- _value.double_val = new SGRawValueInternal<double>;
- _type = DOUBLE;
- }
+ return (_type == ALIAS ? _value.alias : 0);
+}
- switch (_type) {
- case BOOL:
- return SET_BOOL(value == 0.0L ? false : true);
- case INT:
- return SET_INT((int)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;
+const SGPropertyNode *
+SGPropertyNode::getAliasTarget () const
+{
+ return (_type == ALIAS ? _value.alias : 0);
}
/**
- * Set a string value.
+ * Get a non-const child by index.
*/
-bool
-SGValue::setStringValue (string value)
+SGPropertyNode *
+SGPropertyNode::getChild (int position)
{
- if (_type == UNKNOWN) {
- clear_value();
- _value.string_val = new SGRawValueInternal<string>;
- _type = STRING;
- }
+ if (position >= 0 && position < nChildren())
+ return _children[position];
+ else
+ return 0;
+}
- switch (_type) {
- case BOOL:
- return SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
- case INT:
- return SET_INT(atoi(value.c_str()));
- case FLOAT:
- return SET_FLOAT(atof(value.c_str()));
- case DOUBLE:
- return SET_DOUBLE((double)atof(value.c_str()));
- case STRING:
- return SET_STRING(value);
- }
- return false;
+/**
+ * Get a const child by index.
+ */
+const SGPropertyNode *
+SGPropertyNode::getChild (int position) const
+{
+ if (position >= 0 && position < nChildren())
+ return _children[position];
+ else
+ return 0;
}
/**
- * Set a value of unknown type (stored as a string).
+ * Get a non-const child by name and index, creating if necessary.
*/
-bool
-SGValue::setUnknownValue (string value)
+SGPropertyNode *
+SGPropertyNode::getChild (const char * name, int index, bool create)
{
- switch (_type) {
- case BOOL:
- return SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
- case INT:
- return SET_INT(atoi(value.c_str()));
- case FLOAT:
- return SET_FLOAT(atof(value.c_str()));
- case DOUBLE:
- return SET_DOUBLE((double)atof(value.c_str()));
- case STRING:
- case UNKNOWN:
- return SET_STRING(value);
+ 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 false;
}
/**
- * Tie a bool value.
+ * Get a const child by name and index.
*/
-bool
-SGValue::tie (const SGRawValue<bool> &value, bool use_default)
+const SGPropertyNode *
+SGPropertyNode::getChild (const char * name, int index) const
{
- if (_tied)
- return false;
-
- bool old_val;
- 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;
+ int pos = find_child(name, index, _children);
+ if (pos >= 0)
+ return _children[pos];
+ else
+ return 0;
}
/**
- * Tie an int value.
+ * Get all children with the same name (but different indices).
*/
-bool
-SGValue::tie (const SGRawValue<int> &value, bool use_default)
+vector<SGPropertyNode *>
+SGPropertyNode::getChildren (const char * name)
{
- if (_tied)
- return false;
-
- int old_val;
- if (use_default)
- old_val = getIntValue();
-
- clear_value();
- _type = INT;
- _tied = true;
- _value.int_val = value.clone();
+ vector<SGPropertyNode *> children;
+ int max = _children.size();
- if (use_default)
- setIntValue(old_val);
+ for (int i = 0; i < max; i++)
+ if (compare_strings(_children[i]->getName(), name))
+ children.push_back(_children[i]);
- return true;
+ sort(children.begin(), children.end(), CompareIndices());
+ return children;
}
/**
- * Tie a float value.
+ * Get all children const with the same name (but different indices).
*/
-bool
-SGValue::tie (const SGRawValue<float> &value, bool use_default)
+vector<const SGPropertyNode *>
+SGPropertyNode::getChildren (const char * name) const
{
- if (_tied)
- return false;
+ vector<const SGPropertyNode *> children;
+ int max = _children.size();
- float old_val;
- if (use_default)
- old_val = getFloatValue();
+ for (int i = 0; i < max; i++)
+ if (compare_strings(_children[i]->getName(), name))
+ children.push_back(_children[i]);
- clear_value();
- _type = FLOAT;
- _tied = true;
- _value.float_val = value.clone();
+ sort(children.begin(), children.end(), CompareIndices());
+ return children;
+}
- if (use_default)
- setFloatValue(old_val);
- return true;
-}
+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;
+ }
+ return path.c_str();
+}
-/**
- * Tie a double value.
- */
-bool
-SGValue::tie (const SGRawValue<double> &value, bool use_default)
+SGPropertyNode::Type
+SGPropertyNode::getType () const
{
- if (_tied)
- return false;
+ if (_type == ALIAS)
+ return _value.alias->getType();
+ else
+ return _type;
+}
- double old_val;
- if (use_default)
- old_val = getDoubleValue();
- clear_value();
- _type = DOUBLE;
- _tied = true;
- _value.double_val = value.clone();
+bool
+SGPropertyNode::getBoolValue () const
+{
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == BOOL)
+ return get_bool();
- if (use_default)
- setDoubleValue(old_val);
+ 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;
+ }
+}
- return true;
+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();
-/**
- * Tie a string value.
- */
-bool
-SGValue::tie (const SGRawValue<string> &value, bool use_default)
+ 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
{
- if (_tied)
- return false;
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == FLOAT)
+ return get_float();
- string old_val;
- if (use_default)
- old_val = getStringValue();
+ 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;
+ }
+}
- clear_value();
- _type = STRING;
- _tied = true;
- _value.string_val = value.clone();
+double
+SGPropertyNode::getDoubleValue () const
+{
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == DOUBLE)
+ return get_double();
- if (use_default)
- setStringValue(old_val);
+ if (getAttribute(TRACE_READ))
+ trace_read();
+ if (!getAttribute(READ))
+ return SGRawValue<double>::DefaultValue;
- return true;
+ 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();
+}
-/**
- * Untie a value.
- */
bool
-SGValue::untie ()
+SGPropertyNode::setBoolValue (bool value)
{
- if (!_tied)
- return false;
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == BOOL)
+ return set_bool(value);
- switch (_type) {
- case BOOL: {
- bool val = getBoolValue();
+ bool result = false;
+ TEST_WRITE;
+ if (_type == NONE || _type == UNSPECIFIED) {
clear_value();
- _value.bool_val = new SGRawValueInternal<bool>;
- SET_BOOL(val);
- break;
+ _tied = false;
+ _type = BOOL;
}
- case INT: {
- int val = getIntValue();
- clear_value();
- _value.int_val = new SGRawValueInternal<int>;
- SET_INT(val);
+
+ switch (_type) {
+ case ALIAS:
+ result = _value.alias->setBoolValue(value);
break;
- }
- case FLOAT: {
- float val = getFloatValue();
- clear_value();
- _value.float_val = new SGRawValueInternal<float>;
- SET_FLOAT(val);
+ case BOOL:
+ result = set_bool(value);
break;
- }
- case DOUBLE: {
- double val = getDoubleValue();
- clear_value();
- _value.double_val = new SGRawValueInternal<double>;
- SET_DOUBLE(val);
+ case INT:
+ result = set_int(int(value));
break;
- }
- case STRING: {
- string val = getStringValue();
- clear_value();
- _value.string_val = new SGRawValueInternal<string>;
- SET_STRING(val);
+ 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;
- }
}
- _tied = false;
- return true;
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
}
-
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of SGPropertyNode.
-////////////////////////////////////////////////////////////////////////
-
-
-/**
- * Default constructor: always creates a root node.
- */
-SGPropertyNode::SGPropertyNode ()
- : _value(0), _name(""), _index(0), _parent(0)
+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;
+ }
-/**
- * Convenience constructor.
- */
-SGPropertyNode::SGPropertyNode (const string &name,
- int index, SGPropertyNode * parent)
- : _value(0), _name(name), _index(index), _parent(parent)
-{
-}
+ 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;
+ }
-SGPropertyNode::~SGPropertyNode ()
-{
- delete _value;
- for (int i = 0; i < _children.size(); i++)
- delete _children[i];
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
}
-SGPropertyNode *
-SGPropertyNode::getChild (int position)
+bool
+SGPropertyNode::setLongValue (long value)
{
- if (position >= 0 && position < nChildren())
- return _children[position];
- else
- return 0;
-}
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == LONG)
+ return set_long(value);
-const SGPropertyNode *
-SGPropertyNode::getChild (int position) const
-{
- if (position >= 0 && position < nChildren())
- return _children[position];
- else
- return 0;
-}
+ bool result = false;
+ TEST_WRITE;
+ if (_type == NONE || _type == UNSPECIFIED) {
+ clear_value();
+ _type = LONG;
+ _local_val.long_val = 0L;
+ }
-SGPropertyNode *
-SGPropertyNode::getChild (const string &name, int index, bool create)
-{
- int pos = find_child(name, index, _children);
- if (pos >= 0) {
- return getChild(pos);
- } else if (create) {
- _children.push_back(new SGPropertyNode(name, index, this));
- return _children[_children.size()-1];
- } else {
- return 0;
+ 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;
}
-const SGPropertyNode *
-SGPropertyNode::getChild (const string &name, int index) const
+bool
+SGPropertyNode::setFloatValue (float value)
{
- int pos = find_child(name, index, _children);
- if (pos >= 0)
- _children[_children.size()-1];
- else
- return 0;
-}
+ // 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;
+ }
-class CompareIndices
-{
-public:
- int operator() (const SGPropertyNode * n1, const SGPropertyNode *n2) const {
- return (n1->getIndex() < n2->getIndex());
+ 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;
+}
-/**
- * Get all children with the same name (but different indices).
- */
-vector<SGPropertyNode *>
-SGPropertyNode::getChildren (const string &name)
+bool
+SGPropertyNode::setDoubleValue (double value)
{
- vector<SGPropertyNode *> children;
- int max = _children.size();
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == DOUBLE)
+ return set_double(value);
- for (int i = 0; i < max; i++)
- if (_children[i]->getName() == name)
- children.push_back(_children[i]);
+ 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;
+ }
- sort(children.begin(), children.end(), CompareIndices());
- return children;
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
}
-
-/**
- * Get all children with the same name (but different indices).
- */
-vector<const SGPropertyNode *>
-SGPropertyNode::getChildren (const string &name) const
+bool
+SGPropertyNode::setStringValue (const char * value)
{
- vector<const SGPropertyNode *> children;
- int max = _children.size();
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == STRING)
+ return set_string(value);
- for (int i = 0; i < max; i++)
- if (_children[i]->getName() == name)
- children.push_back(_children[i]);
+ bool result = false;
+ TEST_WRITE;
+ if (_type == NONE || _type == UNSPECIFIED) {
+ clear_value();
+ _type = STRING;
+ }
- sort(children.begin(), children.end(), CompareIndices());
- return children;
-}
+ 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;
+}
-string
-SGPropertyNode::getPath (bool simplify) const
+bool
+SGPropertyNode::setUnspecifiedValue (const char * value)
{
- if (_parent == 0)
- return "";
+ bool result = false;
+ TEST_WRITE;
+ if (_type == NONE) {
+ clear_value();
+ _type = UNSPECIFIED;
+ }
- string path = _parent->getPath(simplify);
- path += '/';
- path += _name;
- if (_index != 0 || !simplify) {
- char buffer[128];
- sprintf(buffer, "[%d]", _index);
- path += buffer;
+ 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;
}
- return path;
-}
-SGValue::Type
-SGPropertyNode::getType () const
-{
- if (_value != 0)
- return _value->getType();
- else
- return SGValue::UNKNOWN;
+ if (getAttribute(TRACE_WRITE))
+ trace_write();
+ return result;
}
-bool
-SGPropertyNode::getBoolValue () const
+bool
+SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
{
- return (_value == 0 ? SGRawValue<bool>::DefaultValue
- : _value->getBoolValue());
-}
+ if (_type == ALIAS || _tied)
+ return false;
-int
-SGPropertyNode::getIntValue () const
-{
- return (_value == 0 ? SGRawValue<int>::DefaultValue
- : _value->getIntValue());
-}
+ useDefault = useDefault && hasValue();
+ bool old_val = false;
+ if (useDefault)
+ old_val = getBoolValue();
-float
-SGPropertyNode::getFloatValue () const
-{
- return (_value == 0 ? SGRawValue<float>::DefaultValue
- : _value->getFloatValue());
-}
+ clear_value();
+ _type = BOOL;
+ _tied = true;
+ _value.bool_val = rawValue.clone();
-double
-SGPropertyNode::getDoubleValue () const
-{
- return (_value == 0 ? SGRawValue<double>::DefaultValue
- : _value->getDoubleValue());
-}
+ if (useDefault)
+ setBoolValue(old_val);
-string
-SGPropertyNode::getStringValue () const
-{
- return (_value == 0 ? SGRawValue<string>::DefaultValue
- : _value->getStringValue());
+ return true;
}
bool
-SGPropertyNode::setBoolValue (bool val)
+SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
{
- if (_value == 0)
- _value = new SGValue();
- return _value->setBoolValue(val);
-}
+ if (_type == ALIAS || _tied)
+ return false;
-bool
-SGPropertyNode::setIntValue (int val)
-{
- if (_value == 0)
- _value = new SGValue();
- return _value->setIntValue(val);
-}
+ useDefault = useDefault && hasValue();
+ int old_val = 0;
+ if (useDefault)
+ old_val = getIntValue();
-bool
-SGPropertyNode::setFloatValue (float val)
-{
- if (_value == 0)
- _value = new SGValue();
- return _value->setFloatValue(val);
-}
+ clear_value();
+ _type = INT;
+ _tied = true;
+ _value.int_val = rawValue.clone();
-bool
-SGPropertyNode::setDoubleValue (double val)
-{
- if (_value == 0)
- _value = new SGValue();
- return _value->setDoubleValue(val);
-}
+ if (useDefault)
+ setIntValue(old_val);
-bool
-SGPropertyNode::setStringValue (string val)
-{
- if (_value == 0)
- _value = new SGValue();
- return _value->setStringValue(val);
+ return true;
}
bool
-SGPropertyNode::setUnknownValue (string val)
+SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
{
- if (_value == 0)
- _value = new SGValue();
- return _value->setUnknownValue(val);
-}
+ if (_type == ALIAS || _tied)
+ return false;
-bool
-SGPropertyNode::isTied () const
-{
- return (_value == 0 ? false : _value->isTied());
-}
+ useDefault = useDefault && hasValue();
+ long old_val = 0;
+ if (useDefault)
+ old_val = getLongValue();
-bool
-SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
-{
- if (_value == 0)
- _value = new SGValue();
- return _value->tie(rawValue, useDefault);
-}
+ clear_value();
+ _type = LONG;
+ _tied = true;
+ _value.long_val = rawValue.clone();
-bool
-SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
-{
- if (_value == 0)
- _value = new SGValue();
- return _value->tie(rawValue, useDefault);
+ if (useDefault)
+ setLongValue(old_val);
+
+ return true;
}
bool
SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
{
- if (_value == 0)
- _value = new SGValue();
- return _value->tie(rawValue, 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 (_value == 0)
- _value = new SGValue();
- return _value->tie(rawValue, 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<string> &rawValue, bool useDefault)
+SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool useDefault)
{
- if (_value == 0)
- _value = new SGValue();
- return _value->tie(rawValue, 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;
}
bool
SGPropertyNode::untie ()
{
- return (_value == 0 ? false : _value->untie());
+ if (!_tied)
+ return false;
+
+ switch (_type) {
+ case BOOL: {
+ bool val = getBoolValue();
+ clear_value();
+ _type = BOOL;
+ _local_val.bool_val = val;
+ break;
+ }
+ case INT: {
+ 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 val = getFloatValue();
+ clear_value();
+ _type = FLOAT;
+ _local_val.float_val = val;
+ break;
+ }
+ case DOUBLE: {
+ double val = getDoubleValue();
+ clear_value();
+ _type = DOUBLE;
+ _local_val.double_val = val;
+ break;
+ }
+ 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 *
-SGPropertyNode::getNode (const string &relative_path, bool create)
-{
+SGPropertyNode::getNode (const char * relative_path, bool create)
+{
+// if (_path_cache == 0)
+// _path_cache = new cache_map;
+
+// SGPropertyNode * result = (*_path_cache)[relative_path];
+// if (result == 0) {
+// vector<PathComponent> components;
+// parse_path(relative_path, components);
+// result = find_node(this, components, 0, create);
+// if (result != 0)
+// (*_path_cache)[relative_path] = result;
+// }
+
+// return result;
vector<PathComponent> components;
parse_path(relative_path, components);
return find_node(this, components, 0, create);
}
-const SGPropertyNode *
-SGPropertyNode::getNode (const string &relative_path) const
+SGPropertyNode *
+SGPropertyNode::getNode (const char * relative_path, int index, bool create)
{
vector<PathComponent> components;
parse_path(relative_path, components);
- // FIXME: cast away const
- return find_node((SGPropertyNode *)this, components, 0, false);
+ 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
////////////////////////////////////////////////////////////////////////
* Test whether another node has a value attached.
*/
bool
-SGPropertyNode::hasValue (const string &relative_path) const
+SGPropertyNode::hasValue (const char * relative_path) const
{
const SGPropertyNode * node = getNode(relative_path);
return (node == 0 ? false : node->hasValue());
}
-/**
- * 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());
-}
-
-
-/**
- * Get the value for another node.
- */
-const SGValue *
-SGPropertyNode::getValue (const string &relative_path) const
-{
- const SGPropertyNode * node = getNode(relative_path);
- return (node == 0 ? 0 : node->getValue());
-}
-
-
/**
* Get the value type for another node.
*/
-SGValue::Type
-SGPropertyNode::getType (const string &relative_path) const
+SGPropertyNode::Type
+SGPropertyNode::getType (const char * relative_path) const
{
const SGPropertyNode * node = getNode(relative_path);
- return (node == 0 ? SGValue::UNKNOWN : node->getType());
+ return (node == 0 ? UNSPECIFIED : (Type)(node->getType()));
}
* Get a bool value for another node.
*/
bool
-SGPropertyNode::getBoolValue (const string &relative_path,
+SGPropertyNode::getBoolValue (const char * relative_path,
bool defaultValue) const
{
const SGPropertyNode * node = getNode(relative_path);
* Get an int value for another node.
*/
int
-SGPropertyNode::getIntValue (const string &relative_path,
+SGPropertyNode::getIntValue (const char * relative_path,
int defaultValue) const
{
const SGPropertyNode * node = getNode(relative_path);
}
+/**
+ * Get a long value for another node.
+ */
+long
+SGPropertyNode::getLongValue (const char * relative_path,
+ long defaultValue) const
+{
+ const SGPropertyNode * node = getNode(relative_path);
+ return (node == 0 ? defaultValue : node->getLongValue());
+}
+
+
/**
* Get a float value for another node.
*/
float
-SGPropertyNode::getFloatValue (const string &relative_path,
+SGPropertyNode::getFloatValue (const char * relative_path,
float defaultValue) const
{
const SGPropertyNode * node = getNode(relative_path);
* Get a double value for another node.
*/
double
-SGPropertyNode::getDoubleValue (const string &relative_path,
+SGPropertyNode::getDoubleValue (const char * relative_path,
double defaultValue) const
{
const SGPropertyNode * node = getNode(relative_path);
/**
* Get a string value for another node.
*/
-string
-SGPropertyNode::getStringValue (const string &relative_path,
- string defaultValue) const
+const char *
+SGPropertyNode::getStringValue (const char * relative_path,
+ const char * defaultValue) const
{
const SGPropertyNode * node = getNode(relative_path);
return (node == 0 ? defaultValue : node->getStringValue());
* Set a bool value for another node.
*/
bool
-SGPropertyNode::setBoolValue (const string &relative_path, bool value)
+SGPropertyNode::setBoolValue (const char * relative_path, bool value)
{
return getNode(relative_path, true)->setBoolValue(value);
}
* Set an int value for another node.
*/
bool
-SGPropertyNode::setIntValue (const string &relative_path, int value)
+SGPropertyNode::setIntValue (const char * relative_path, int value)
{
return getNode(relative_path, true)->setIntValue(value);
}
+/**
+ * Set a long value for another node.
+ */
+bool
+SGPropertyNode::setLongValue (const char * relative_path, long value)
+{
+ return getNode(relative_path, true)->setLongValue(value);
+}
+
+
/**
* Set a float value for another node.
*/
bool
-SGPropertyNode::setFloatValue (const string &relative_path, float value)
+SGPropertyNode::setFloatValue (const char * relative_path, float value)
{
return getNode(relative_path, true)->setFloatValue(value);
}
* Set a double value for another node.
*/
bool
-SGPropertyNode::setDoubleValue (const string &relative_path, double value)
+SGPropertyNode::setDoubleValue (const char * relative_path, double value)
{
return getNode(relative_path, true)->setDoubleValue(value);
}
* Set a string value for another node.
*/
bool
-SGPropertyNode::setStringValue (const string &relative_path, string value)
+SGPropertyNode::setStringValue (const char * relative_path, const char * value)
{
return getNode(relative_path, true)->setStringValue(value);
}
* Set an unknown value for another node.
*/
bool
-SGPropertyNode::setUnknownValue (const string &relative_path, string value)
+SGPropertyNode::setUnspecifiedValue (const char * relative_path,
+ const char * value)
{
- return getNode(relative_path, true)->setUnknownValue(value);
+ return getNode(relative_path, true)->setUnspecifiedValue(value);
}
* Test whether another node is tied.
*/
bool
-SGPropertyNode::isTied (const string &relative_path) const
+SGPropertyNode::isTied (const char * relative_path) const
{
const SGPropertyNode * node = getNode(relative_path);
return (node == 0 ? false : node->isTied());
* Tie a node reached by a relative path, creating it if necessary.
*/
bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
const SGRawValue<bool> &rawValue,
bool useDefault)
{
* Tie a node reached by a relative path, creating it if necessary.
*/
bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
const SGRawValue<int> &rawValue,
bool useDefault)
{
* Tie a node reached by a relative path, creating it if necessary.
*/
bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<long> &rawValue,
+ bool useDefault)
+{
+ return getNode(relative_path, true)->tie(rawValue, useDefault);
+}
+
+
+/**
+ * Tie a node reached by a relative path, creating it if necessary.
+ */
+bool
+SGPropertyNode::tie (const char * relative_path,
const SGRawValue<float> &rawValue,
bool useDefault)
{
* Tie a node reached by a relative path, creating it if necessary.
*/
bool
-SGPropertyNode::tie (const string &relative_path,
+SGPropertyNode::tie (const char * relative_path,
const SGRawValue<double> &rawValue,
bool useDefault)
{
* Tie a node reached by a relative path, creating it if necessary.
*/
bool
-SGPropertyNode::tie (const string &relative_path,
- const SGRawValue<string> &rawValue,
+SGPropertyNode::tie (const char * relative_path,
+ const SGRawValue<const char *> &rawValue,
bool useDefault)
{
return getNode(relative_path, true)->tie(rawValue, useDefault);
* Attempt to untie another node reached by a relative path.
*/
bool
-SGPropertyNode::untie (const string &relative_path)
+SGPropertyNode::untie (const char * relative_path)
{
SGPropertyNode * node = getNode(relative_path);
return (node == 0 ? false : node->untie());