+ return 0;
+ }
+}
+
+
+/**
+ * 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 *>
+SGPropertyNode::getChildren (const char * name)
+{
+ vector<SGPropertyNode *> 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;
+}
+
+
+/**
+ * Get all children const with the same name (but different indices).
+ */
+vector<const SGPropertyNode *>
+SGPropertyNode::getChildren (const char * name) const
+{
+ vector<const SGPropertyNode *> 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;
+}
+
+
+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();
+}
+
+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
+SGPropertyNode::setBoolValue (bool value)
+{
+ // Shortcut for common case
+ if (_attr == (READ|WRITE) && _type == BOOL)
+ return set_bool(value);
+
+ bool result = false;
+ TEST_WRITE;
+ if (_type == NONE || _type == UNSPECIFIED) {
+ clear_value();
+ _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;