1 // props.cxx - implementation of a property list.
2 // Started Fall 2000 by David Megginson, david@megginson.com
3 // This code is released into the Public Domain.
5 // See props.html for documentation [replace with URL when available].
20 #include <simgear/compiler.h>
21 #include <simgear/debug/logstream.hxx>
33 ////////////////////////////////////////////////////////////////////////
35 ////////////////////////////////////////////////////////////////////////
38 * Comparator class for sorting by index.
43 int operator() (const SGPropertyNode * n1, const SGPropertyNode *n2) const {
44 return (n1->getIndex() < n2->getIndex());
50 ////////////////////////////////////////////////////////////////////////
51 // Convenience macros for value access.
52 ////////////////////////////////////////////////////////////////////////
54 #define TEST_READ(dflt) if (!getAttribute(READ)) return dflt
55 #define TEST_WRITE if (!getAttribute(WRITE)) return false
59 ////////////////////////////////////////////////////////////////////////
60 // Default values for every type.
61 ////////////////////////////////////////////////////////////////////////
63 const bool SGRawValue<bool>::DefaultValue = false;
64 const int SGRawValue<int>::DefaultValue = 0;
65 const long SGRawValue<long>::DefaultValue = 0L;
66 const float SGRawValue<float>::DefaultValue = 0.0;
67 const double SGRawValue<double>::DefaultValue = 0.0L;
68 const char * const SGRawValue<const char *>::DefaultValue = "";
72 ////////////////////////////////////////////////////////////////////////
73 // Local path normalization code.
74 ////////////////////////////////////////////////////////////////////////
77 * A component in a path.
86 * Parse the name for a path component.
88 * Name: [_a-zA-Z][-._a-zA-Z0-9]*
90 static inline const string
91 parse_name (const string &path, int &i)
94 int max = path.size();
98 if (i < max && path[i] == '.') {
104 if (i < max && path[i] != '/')
105 throw string(string("Illegal character after ") + name);
108 else if (isalpha(path[i]) || path[i] == '_') {
112 // The rules inside a name are a little
115 if (isalpha(path[i]) || isdigit(path[i]) || path[i] == '_' ||
116 path[i] == '-' || path[i] == '.') {
118 } else if (path[i] == '[' || path[i] == '/') {
121 throw string("name may contain only ._- and alphanumeric characters");
128 if (name.size() == 0)
129 throw string("name must begin with alpha or '_'");
137 * Parse the optional integer index for a path component.
139 * Index: "[" [0-9]+ "]"
142 parse_index (const string &path, int &i)
151 for (int max = path.size(); i < max; i++) {
152 if (isdigit(path[i])) {
153 index = (index * 10) + (path[i] - '0');
154 } else if (path[i] == ']') {
162 throw string("unterminated index (looking for ']')");
167 * Parse a single path component.
169 * Component: Name Index?
171 static inline PathComponent
172 parse_component (const string &path, int &i)
174 PathComponent component;
175 component.name = parse_name(path, i);
176 if (component.name[0] != '.')
177 component.index = parse_index(path, i);
179 component.index = -1;
185 * Parse a path into its components.
188 parse_path (const string &path, vector<PathComponent> &components)
191 int max = path.size();
193 // Check for initial '/'
194 if (path[pos] == '/') {
198 components.push_back(root);
200 while (pos < max && path[pos] == '/')
205 components.push_back(parse_component(path, pos));
206 while (pos < max && path[pos] == '/')
213 ////////////////////////////////////////////////////////////////////////
214 // Other static utility functions.
215 ////////////////////////////////////////////////////////////////////////
219 copy_string (const char * s)
221 // FIXME: potential buffer overflow.
222 // For some reason, strnlen and
223 // strncpy cause all kinds of crashes.
225 char * copy = new char[str.size() + 1];
226 strcpy(copy, str.c_str());
231 compare_strings (const char * s1, const char * s2)
233 return !strncmp(s1, s2, SGPropertyNode::MAX_STRING_LEN);
237 * Locate a child node by name and index.
240 find_child (const char * name, int index, vector<SGPropertyNode *> nodes)
242 int nNodes = nodes.size();
243 for (int i = 0; i < nNodes; i++) {
244 SGPropertyNode * node = nodes[i];
245 if (compare_strings(node->getName(), name) && node->getIndex() == index)
253 * Locate another node, given a relative path.
255 static SGPropertyNode *
256 find_node (SGPropertyNode * current,
257 const vector<PathComponent> &components,
261 // Run off the end of the list
266 // Success! This is the one we want.
267 else if (position >= (int)components.size()) {
271 // Empty component means root.
272 else if (components[position].name == "") {
273 return find_node(current->getRootNode(), components, position + 1, create);
276 // . means current directory
277 else if (components[position].name == ".") {
278 return find_node(current, components, position + 1, create);
281 // .. means parent directory
282 else if (components[position].name == "..") {
283 SGPropertyNode * parent = current->getParent();
285 throw string("Attempt to move past root with '..'");
287 return find_node(parent, components, position + 1, create);
290 // Otherwise, a child name
292 SGPropertyNode * child =
293 current->getChild(components[position].name.c_str(),
294 components[position].index,
296 return find_node(child, components, position + 1, create);
302 ////////////////////////////////////////////////////////////////////////
303 // Private methods from SGPropertyNode (may be inlined for speed).
304 ////////////////////////////////////////////////////////////////////////
307 SGPropertyNode::get_bool () const
310 return _value.bool_val->getValue();
312 return _local_val.bool_val;
316 SGPropertyNode::get_int () const
319 return _value.int_val->getValue();
321 return _local_val.int_val;
325 SGPropertyNode::get_long () const
328 return _value.long_val->getValue();
330 return _local_val.long_val;
334 SGPropertyNode::get_float () const
337 return _value.float_val->getValue();
339 return _local_val.float_val;
343 SGPropertyNode::get_double () const
346 return _value.double_val->getValue();
348 return _local_val.double_val;
352 SGPropertyNode::get_string () const
355 return _value.string_val->getValue();
357 return _local_val.string_val;
361 SGPropertyNode::set_bool (bool val)
364 return _value.bool_val->setValue(val);
366 _local_val.bool_val = val;
372 SGPropertyNode::set_int (int val)
375 return _value.int_val->setValue(val);
377 _local_val.int_val = val;
383 SGPropertyNode::set_long (long val)
386 return _value.long_val->setValue(val);
388 _local_val.long_val = val;
394 SGPropertyNode::set_float (float val)
397 return _value.float_val->setValue(val);
399 _local_val.float_val = val;
405 SGPropertyNode::set_double (double val)
408 return _value.double_val->setValue(val);
410 _local_val.double_val = val;
416 SGPropertyNode::set_string (const char * val)
419 return _value.string_val->setValue(val);
421 delete (char *)_local_val.string_val;
422 _local_val.string_val = copy_string(val);
428 SGPropertyNode::clear_value ()
436 delete _value.bool_val;
438 _local_val.bool_val = SGRawValue<bool>::DefaultValue;
441 delete _value.int_val;
443 _local_val.int_val = SGRawValue<int>::DefaultValue;
446 delete _value.long_val;
447 _value.long_val = 0L;
448 _local_val.long_val = SGRawValue<long>::DefaultValue;
451 delete _value.float_val;
452 _value.float_val = 0;
453 _local_val.float_val = SGRawValue<float>::DefaultValue;
456 delete _value.double_val;
457 _value.double_val = 0;
458 _local_val.double_val = SGRawValue<double>::DefaultValue;
462 delete _value.string_val;
463 _value.string_val = 0;
464 delete (char *)_local_val.string_val;
465 _local_val.string_val = 0;
474 * Get the value as a string.
477 SGPropertyNode::make_string () const
479 if (!getAttribute(READ))
484 return _value.alias->getStringValue();
491 sprintf(_buffer, "%d", get_int());
494 sprintf(_buffer, "%ld", get_long());
497 sprintf(_buffer, "%f", get_float());
500 sprintf(_buffer, "%f", get_double());
512 * Trace a write access for a property.
515 SGPropertyNode::trace_write () const
518 cerr << "TRACE: Write node " << getPath () << ", value\""
519 << make_string() << '"' << endl;
521 SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Write node " << getPath()
522 << ", value\"" << make_string() << '"');
527 * Trace a read access for a property.
530 SGPropertyNode::trace_read () const
533 cerr << "TRACE: Write node " << getPath () << ", value \""
534 << make_string() << '"' << endl;
536 SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Read node " << getPath()
537 << ", value \"" << make_string() << '"');
543 ////////////////////////////////////////////////////////////////////////
544 // Public methods from SGPropertyNode.
545 ////////////////////////////////////////////////////////////////////////
548 * Default constructor: always creates a root node.
550 SGPropertyNode::SGPropertyNode ()
551 : _name(copy_string("")),
559 _local_val.string_val = 0;
566 SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
567 : _index(node._index),
568 _parent(0), // don't copy the parent
574 _name = copy_string(node._name);
575 _local_val.string_val = 0;
580 _value.alias = node._value.alias;
586 _value.bool_val = node._value.bool_val->clone();
589 set_bool(node.get_bool());
595 _value.int_val = node._value.int_val->clone();
598 set_int(node.get_int());
604 _value.long_val = node._value.long_val->clone();
607 set_long(node.get_long());
613 _value.float_val = node._value.float_val->clone();
616 set_float(node.get_float());
622 _value.double_val = node._value.double_val->clone();
625 set_double(node.get_double());
632 _value.string_val = node._value.string_val->clone();
635 set_string(node.get_string());
643 * Convenience constructor.
645 SGPropertyNode::SGPropertyNode (const char * name,
647 SGPropertyNode * parent)
655 _name = copy_string(name);
656 _local_val.string_val = 0;
663 SGPropertyNode::~SGPropertyNode ()
665 delete (char *)_name;
666 for (int i = 0; i < (int)_children.size(); i++) {
669 // delete _path_cache;
675 * Alias to another node.
678 SGPropertyNode::alias (SGPropertyNode * target)
680 if (target == 0 || _type == ALIAS || _tied)
683 _value.alias = target;
690 * Alias to another node by path.
693 SGPropertyNode::alias (const char * path)
695 return alias(getNode(path, true));
703 SGPropertyNode::unalias ()
714 * Get the target of an alias.
717 SGPropertyNode::getAliasTarget ()
719 return (_type == ALIAS ? _value.alias : 0);
723 const SGPropertyNode *
724 SGPropertyNode::getAliasTarget () const
726 return (_type == ALIAS ? _value.alias : 0);
731 * Get a non-const child by index.
734 SGPropertyNode::getChild (int position)
736 if (position >= 0 && position < nChildren())
737 return _children[position];
744 * Get a const child by index.
746 const SGPropertyNode *
747 SGPropertyNode::getChild (int position) const
749 if (position >= 0 && position < nChildren())
750 return _children[position];
757 * Get a non-const child by name and index, creating if necessary.
760 SGPropertyNode::getChild (const char * name, int index, bool create)
762 int pos = find_child(name, index, _children);
764 return _children[pos];
766 _children.push_back(new SGPropertyNode(name, index, this));
767 return _children[_children.size()-1];
775 * Get a const child by name and index.
777 const SGPropertyNode *
778 SGPropertyNode::getChild (const char * name, int index) const
780 int pos = find_child(name, index, _children);
782 return _children[pos];
789 * Get all children with the same name (but different indices).
791 vector<SGPropertyNode *>
792 SGPropertyNode::getChildren (const char * name)
794 vector<SGPropertyNode *> children;
795 int max = _children.size();
797 for (int i = 0; i < max; i++)
798 if (compare_strings(_children[i]->getName(), name))
799 children.push_back(_children[i]);
801 sort(children.begin(), children.end(), CompareIndices());
807 * Get all children const with the same name (but different indices).
809 vector<const SGPropertyNode *>
810 SGPropertyNode::getChildren (const char * name) const
812 vector<const SGPropertyNode *> children;
813 int max = _children.size();
815 for (int i = 0; i < max; i++)
816 if (compare_strings(_children[i]->getName(), name))
817 children.push_back(_children[i]);
819 sort(children.begin(), children.end(), CompareIndices());
825 SGPropertyNode::getPath (bool simplify) const
830 string path = _parent->getPath(simplify);
833 if (_index != 0 || !simplify) {
835 sprintf(buffer, "[%d]", _index);
842 SGPropertyNode::getType () const
845 return _value.alias->getType();
852 SGPropertyNode::getBoolValue () const
854 // Shortcut for common case
855 if (_attr == (READ|WRITE) && _type == BOOL)
858 if (getAttribute(TRACE_READ))
860 if (!getAttribute(READ))
861 return SGRawValue<bool>::DefaultValue;
864 return _value.alias->getBoolValue();
868 return get_int() == 0 ? false : true;
870 return get_long() == 0L ? false : true;
872 return get_float() == 0.0 ? false : true;
874 return get_double() == 0.0L ? false : true;
877 return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L);
880 return SGRawValue<bool>::DefaultValue;
885 SGPropertyNode::getIntValue () const
887 // Shortcut for common case
888 if (_attr == (READ|WRITE) && _type == INT)
891 if (getAttribute(TRACE_READ))
893 if (!getAttribute(READ))
894 return SGRawValue<int>::DefaultValue;
897 return _value.alias->getIntValue();
899 return int(get_bool());
903 return int(get_long());
905 return int(get_float());
907 return int(get_double());
910 return atoi(get_string());
913 return SGRawValue<int>::DefaultValue;
918 SGPropertyNode::getLongValue () const
920 // Shortcut for common case
921 if (_attr == (READ|WRITE) && _type == LONG)
924 if (getAttribute(TRACE_READ))
926 if (!getAttribute(READ))
927 return SGRawValue<long>::DefaultValue;
930 return _value.alias->getLongValue();
932 return long(get_bool());
934 return long(get_int());
938 return long(get_float());
940 return long(get_double());
943 return strtol(get_string(), 0, 0);
946 return SGRawValue<long>::DefaultValue;
951 SGPropertyNode::getFloatValue () const
953 // Shortcut for common case
954 if (_attr == (READ|WRITE) && _type == FLOAT)
957 if (getAttribute(TRACE_READ))
959 if (!getAttribute(READ))
960 return SGRawValue<float>::DefaultValue;
963 return _value.alias->getFloatValue();
965 return float(get_bool());
967 return float(get_int());
969 return float(get_long());
973 return float(get_double());
976 return atof(get_string());
979 return SGRawValue<float>::DefaultValue;
984 SGPropertyNode::getDoubleValue () const
986 // Shortcut for common case
987 if (_attr == (READ|WRITE) && _type == DOUBLE)
990 if (getAttribute(TRACE_READ))
992 if (!getAttribute(READ))
993 return SGRawValue<double>::DefaultValue;
997 return _value.alias->getDoubleValue();
999 return double(get_bool());
1001 return double(get_int());
1003 return double(get_long());
1005 return double(get_float());
1007 return get_double();
1010 return strtod(get_string(), 0);
1013 return SGRawValue<double>::DefaultValue;
1018 SGPropertyNode::getStringValue () const
1020 // Shortcut for common case
1021 if (_attr == (READ|WRITE) && _type == STRING)
1022 return get_string();
1024 if (getAttribute(TRACE_READ))
1026 if (!getAttribute(READ))
1027 return SGRawValue<const char *>::DefaultValue;
1028 return make_string();
1032 SGPropertyNode::setBoolValue (bool value)
1034 // Shortcut for common case
1035 if (_attr == (READ|WRITE) && _type == BOOL)
1036 return set_bool(value);
1038 bool result = false;
1040 if (_type == NONE || _type == UNSPECIFIED) {
1048 result = _value.alias->setBoolValue(value);
1051 result = set_bool(value);
1054 result = set_int(int(value));
1057 result = set_long(long(value));
1060 result = set_float(float(value));
1063 result = set_double(double(value));
1067 result = set_string(value ? "true" : "false");
1074 if (getAttribute(TRACE_WRITE))
1080 SGPropertyNode::setIntValue (int value)
1082 // Shortcut for common case
1083 if (_attr == (READ|WRITE) && _type == INT)
1084 return set_int(value);
1086 bool result = false;
1088 if (_type == NONE || _type == UNSPECIFIED) {
1091 _local_val.int_val = 0;
1096 result = _value.alias->setIntValue(value);
1099 result = set_bool(value == 0 ? false : true);
1102 result = set_int(value);
1105 result = set_long(long(value));
1108 result = set_float(float(value));
1111 result = set_double(double(value));
1116 sprintf(buf, "%d", value);
1117 result = set_string(buf);
1125 if (getAttribute(TRACE_WRITE))
1131 SGPropertyNode::setLongValue (long value)
1133 // Shortcut for common case
1134 if (_attr == (READ|WRITE) && _type == LONG)
1135 return set_long(value);
1137 bool result = false;
1139 if (_type == NONE || _type == UNSPECIFIED) {
1142 _local_val.long_val = 0L;
1147 result = _value.alias->setLongValue(value);
1150 result = set_bool(value == 0L ? false : true);
1153 result = set_int(int(value));
1156 result = set_long(value);
1159 result = set_float(float(value));
1162 result = set_double(double(value));
1167 sprintf(buf, "%ld", value);
1168 result = set_string(buf);
1176 if (getAttribute(TRACE_WRITE))
1182 SGPropertyNode::setFloatValue (float value)
1184 // Shortcut for common case
1185 if (_attr == (READ|WRITE) && _type == FLOAT)
1186 return set_float(value);
1188 bool result = false;
1190 if (_type == NONE || _type == UNSPECIFIED) {
1193 _local_val.float_val = 0;
1198 result = _value.alias->setFloatValue(value);
1201 result = set_bool(value == 0.0 ? false : true);
1204 result = set_int(int(value));
1207 result = set_long(long(value));
1210 result = set_float(value);
1213 result = set_double(double(value));
1218 sprintf(buf, "%f", value);
1219 result = set_string(buf);
1227 if (getAttribute(TRACE_WRITE))
1233 SGPropertyNode::setDoubleValue (double value)
1235 // Shortcut for common case
1236 if (_attr == (READ|WRITE) && _type == DOUBLE)
1237 return set_double(value);
1239 bool result = false;
1241 if (_type == NONE || _type == UNSPECIFIED) {
1243 _local_val.double_val = value;
1249 result = _value.alias->setDoubleValue(value);
1252 result = set_bool(value == 0.0L ? false : true);
1255 result = set_int(int(value));
1258 result = set_long(long(value));
1261 result = set_float(float(value));
1264 result = set_double(value);
1269 sprintf(buf, "%f", value);
1270 result = set_string(buf);
1278 if (getAttribute(TRACE_WRITE))
1284 SGPropertyNode::setStringValue (const char * value)
1286 // Shortcut for common case
1287 if (_attr == (READ|WRITE) && _type == STRING)
1288 return set_string(value);
1290 bool result = false;
1292 if (_type == NONE || _type == UNSPECIFIED) {
1299 result = _value.alias->setStringValue(value);
1302 result = set_bool((compare_strings(value, "true")
1303 || atoi(value)) ? true : false);
1306 result = set_int(atoi(value));
1309 result = set_long(strtol(value, 0, 0));
1312 result = set_float(atof(value));
1315 result = set_double(strtod(value, 0));
1319 result = set_string(value);
1326 if (getAttribute(TRACE_WRITE))
1332 SGPropertyNode::setUnspecifiedValue (const char * value)
1334 bool result = false;
1336 if (_type == NONE) {
1338 _type = UNSPECIFIED;
1343 result = _value.alias->setUnspecifiedValue(value);
1346 result = set_bool((compare_strings(value, "true")
1347 || atoi(value)) ? true : false);
1350 result = set_int(atoi(value));
1353 result = set_long(strtol(value, 0, 0));
1356 result = set_float(atof(value));
1359 result = set_double(strtod(value, 0));
1363 result = set_string(value);
1370 if (getAttribute(TRACE_WRITE))
1376 SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
1378 if (_type == ALIAS || _tied)
1381 useDefault = useDefault && hasValue();
1382 bool old_val = false;
1384 old_val = getBoolValue();
1389 _value.bool_val = rawValue.clone();
1392 setBoolValue(old_val);
1398 SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
1400 if (_type == ALIAS || _tied)
1403 useDefault = useDefault && hasValue();
1406 old_val = getIntValue();
1411 _value.int_val = rawValue.clone();
1414 setIntValue(old_val);
1420 SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
1422 if (_type == ALIAS || _tied)
1425 useDefault = useDefault && hasValue();
1428 old_val = getLongValue();
1433 _value.long_val = rawValue.clone();
1436 setLongValue(old_val);
1442 SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
1444 if (_type == ALIAS || _tied)
1447 useDefault = useDefault && hasValue();
1448 float old_val = 0.0;
1450 old_val = getFloatValue();
1455 _value.float_val = rawValue.clone();
1458 setFloatValue(old_val);
1464 SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
1466 if (_type == ALIAS || _tied)
1469 useDefault = useDefault && hasValue();
1470 double old_val = 0.0;
1472 old_val = getDoubleValue();
1477 _value.double_val = rawValue.clone();
1480 setDoubleValue(old_val);
1487 SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool useDefault)
1489 if (_type == ALIAS || _tied)
1492 useDefault = useDefault && hasValue();
1495 old_val = getStringValue();
1500 _value.string_val = rawValue.clone();
1503 setStringValue(old_val.c_str());
1509 SGPropertyNode::untie ()
1516 bool val = getBoolValue();
1519 _local_val.bool_val = val;
1523 int val = getIntValue();
1526 _local_val.int_val = val;
1530 long val = getLongValue();
1533 _local_val.long_val = val;
1537 float val = getFloatValue();
1540 _local_val.float_val = val;
1544 double val = getDoubleValue();
1547 _local_val.double_val = val;
1552 string val = getStringValue();
1555 _local_val.string_val = copy_string(val.c_str());
1568 SGPropertyNode::getRootNode ()
1573 return _parent->getRootNode();
1576 const SGPropertyNode *
1577 SGPropertyNode::getRootNode () const
1582 return _parent->getRootNode();
1586 SGPropertyNode::getNode (const char * relative_path, bool create)
1588 // if (_path_cache == 0)
1589 // _path_cache = new cache_map;
1591 // SGPropertyNode * result = (*_path_cache)[relative_path];
1592 // if (result == 0) {
1593 // vector<PathComponent> components;
1594 // parse_path(relative_path, components);
1595 // result = find_node(this, components, 0, create);
1597 // (*_path_cache)[relative_path] = result;
1601 vector<PathComponent> components;
1602 parse_path(relative_path, components);
1603 return find_node(this, components, 0, create);
1607 SGPropertyNode::getNode (const char * relative_path, int index, bool create)
1609 vector<PathComponent> components;
1610 parse_path(relative_path, components);
1611 if (components.size() > 0)
1612 components[components.size()-1].index = index;
1613 return find_node(this, components, 0, create);
1616 const SGPropertyNode *
1617 SGPropertyNode::getNode (const char * relative_path) const
1619 return ((SGPropertyNode *)this)->getNode(relative_path, false);
1622 const SGPropertyNode *
1623 SGPropertyNode::getNode (const char * relative_path, int index) const
1625 return ((SGPropertyNode *)this)->getNode(relative_path, index, false);
1629 ////////////////////////////////////////////////////////////////////////
1630 // Convenience methods using relative paths.
1631 ////////////////////////////////////////////////////////////////////////
1635 * Test whether another node has a value attached.
1638 SGPropertyNode::hasValue (const char * relative_path) const
1640 const SGPropertyNode * node = getNode(relative_path);
1641 return (node == 0 ? false : node->hasValue());
1646 * Get the value type for another node.
1648 SGPropertyNode::Type
1649 SGPropertyNode::getType (const char * relative_path) const
1651 const SGPropertyNode * node = getNode(relative_path);
1652 return (node == 0 ? UNSPECIFIED : (Type)(node->getType()));
1657 * Get a bool value for another node.
1660 SGPropertyNode::getBoolValue (const char * relative_path,
1661 bool defaultValue) const
1663 const SGPropertyNode * node = getNode(relative_path);
1664 return (node == 0 ? defaultValue : node->getBoolValue());
1669 * Get an int value for another node.
1672 SGPropertyNode::getIntValue (const char * relative_path,
1673 int defaultValue) const
1675 const SGPropertyNode * node = getNode(relative_path);
1676 return (node == 0 ? defaultValue : node->getIntValue());
1681 * Get a long value for another node.
1684 SGPropertyNode::getLongValue (const char * relative_path,
1685 long defaultValue) const
1687 const SGPropertyNode * node = getNode(relative_path);
1688 return (node == 0 ? defaultValue : node->getLongValue());
1693 * Get a float value for another node.
1696 SGPropertyNode::getFloatValue (const char * relative_path,
1697 float defaultValue) const
1699 const SGPropertyNode * node = getNode(relative_path);
1700 return (node == 0 ? defaultValue : node->getFloatValue());
1705 * Get a double value for another node.
1708 SGPropertyNode::getDoubleValue (const char * relative_path,
1709 double defaultValue) const
1711 const SGPropertyNode * node = getNode(relative_path);
1712 return (node == 0 ? defaultValue : node->getDoubleValue());
1717 * Get a string value for another node.
1720 SGPropertyNode::getStringValue (const char * relative_path,
1721 const char * defaultValue) const
1723 const SGPropertyNode * node = getNode(relative_path);
1724 return (node == 0 ? defaultValue : node->getStringValue());
1729 * Set a bool value for another node.
1732 SGPropertyNode::setBoolValue (const char * relative_path, bool value)
1734 return getNode(relative_path, true)->setBoolValue(value);
1739 * Set an int value for another node.
1742 SGPropertyNode::setIntValue (const char * relative_path, int value)
1744 return getNode(relative_path, true)->setIntValue(value);
1749 * Set a long value for another node.
1752 SGPropertyNode::setLongValue (const char * relative_path, long value)
1754 return getNode(relative_path, true)->setLongValue(value);
1759 * Set a float value for another node.
1762 SGPropertyNode::setFloatValue (const char * relative_path, float value)
1764 return getNode(relative_path, true)->setFloatValue(value);
1769 * Set a double value for another node.
1772 SGPropertyNode::setDoubleValue (const char * relative_path, double value)
1774 return getNode(relative_path, true)->setDoubleValue(value);
1779 * Set a string value for another node.
1782 SGPropertyNode::setStringValue (const char * relative_path, const char * value)
1784 return getNode(relative_path, true)->setStringValue(value);
1789 * Set an unknown value for another node.
1792 SGPropertyNode::setUnspecifiedValue (const char * relative_path,
1795 return getNode(relative_path, true)->setUnspecifiedValue(value);
1800 * Test whether another node is tied.
1803 SGPropertyNode::isTied (const char * relative_path) const
1805 const SGPropertyNode * node = getNode(relative_path);
1806 return (node == 0 ? false : node->isTied());
1811 * Tie a node reached by a relative path, creating it if necessary.
1814 SGPropertyNode::tie (const char * relative_path,
1815 const SGRawValue<bool> &rawValue,
1818 return getNode(relative_path, true)->tie(rawValue, useDefault);
1823 * Tie a node reached by a relative path, creating it if necessary.
1826 SGPropertyNode::tie (const char * relative_path,
1827 const SGRawValue<int> &rawValue,
1830 return getNode(relative_path, true)->tie(rawValue, useDefault);
1835 * Tie a node reached by a relative path, creating it if necessary.
1838 SGPropertyNode::tie (const char * relative_path,
1839 const SGRawValue<long> &rawValue,
1842 return getNode(relative_path, true)->tie(rawValue, useDefault);
1847 * Tie a node reached by a relative path, creating it if necessary.
1850 SGPropertyNode::tie (const char * relative_path,
1851 const SGRawValue<float> &rawValue,
1854 return getNode(relative_path, true)->tie(rawValue, useDefault);
1859 * Tie a node reached by a relative path, creating it if necessary.
1862 SGPropertyNode::tie (const char * relative_path,
1863 const SGRawValue<double> &rawValue,
1866 return getNode(relative_path, true)->tie(rawValue, useDefault);
1871 * Tie a node reached by a relative path, creating it if necessary.
1874 SGPropertyNode::tie (const char * relative_path,
1875 const SGRawValue<const char *> &rawValue,
1878 return getNode(relative_path, true)->tie(rawValue, useDefault);
1883 * Attempt to untie another node reached by a relative path.
1886 SGPropertyNode::untie (const char * relative_path)
1888 SGPropertyNode * node = getNode(relative_path);
1889 return (node == 0 ? false : node->untie());