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].
24 #include <simgear/compiler.h>
25 #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 ()
438 delete _value.bool_val;
441 _local_val.bool_val = SGRawValue<bool>::DefaultValue;
445 delete _value.int_val;
448 _local_val.int_val = SGRawValue<int>::DefaultValue;
452 delete _value.long_val;
453 _value.long_val = 0L;
455 _local_val.long_val = SGRawValue<long>::DefaultValue;
459 delete _value.float_val;
460 _value.float_val = 0;
462 _local_val.float_val = SGRawValue<float>::DefaultValue;
466 delete _value.double_val;
467 _value.double_val = 0;
469 _local_val.double_val = SGRawValue<double>::DefaultValue;
474 delete _value.string_val;
475 _value.string_val = 0;
477 delete [] (char *)_local_val.string_val;
479 _local_val.string_val = 0;
488 * Get the value as a string.
491 SGPropertyNode::make_string () const
493 if (!getAttribute(READ))
498 return _value.alias->getStringValue();
505 sprintf(_buffer, "%d", get_int());
508 sprintf(_buffer, "%ld", get_long());
511 sprintf(_buffer, "%f", get_float());
514 sprintf(_buffer, "%f", get_double());
526 * Trace a write access for a property.
529 SGPropertyNode::trace_write () const
532 cerr << "TRACE: Write node " << getPath () << ", value\""
533 << make_string() << '"' << endl;
535 SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Write node " << getPath()
536 << ", value\"" << make_string() << '"');
541 * Trace a read access for a property.
544 SGPropertyNode::trace_read () const
547 cerr << "TRACE: Write node " << getPath () << ", value \""
548 << make_string() << '"' << endl;
550 SG_LOG(SG_GENERAL, SG_INFO, "TRACE: Read node " << getPath()
551 << ", value \"" << make_string() << '"');
557 ////////////////////////////////////////////////////////////////////////
558 // Public methods from SGPropertyNode.
559 ////////////////////////////////////////////////////////////////////////
562 * Default constructor: always creates a root node.
564 SGPropertyNode::SGPropertyNode ()
565 : _name(copy_string("")),
573 _local_val.string_val = 0;
580 SGPropertyNode::SGPropertyNode (const SGPropertyNode &node)
581 : _index(node._index),
582 _parent(0), // don't copy the parent
588 _name = copy_string(node._name);
589 _local_val.string_val = 0;
594 _value.alias = node._value.alias;
600 _value.bool_val = node._value.bool_val->clone();
603 set_bool(node.get_bool());
609 _value.int_val = node._value.int_val->clone();
612 set_int(node.get_int());
618 _value.long_val = node._value.long_val->clone();
621 set_long(node.get_long());
627 _value.float_val = node._value.float_val->clone();
630 set_float(node.get_float());
636 _value.double_val = node._value.double_val->clone();
639 set_double(node.get_double());
646 _value.string_val = node._value.string_val->clone();
649 set_string(node.get_string());
657 * Convenience constructor.
659 SGPropertyNode::SGPropertyNode (const char * name,
661 SGPropertyNode * parent)
669 _name = copy_string(name);
670 _local_val.string_val = 0;
677 SGPropertyNode::~SGPropertyNode ()
679 delete [] (char *)_name;
680 for (int i = 0; i < (int)_children.size(); i++) {
683 // delete _path_cache;
689 * Alias to another node.
692 SGPropertyNode::alias (SGPropertyNode * target)
694 if (target == 0 || _type == ALIAS || _tied)
697 _value.alias = target;
704 * Alias to another node by path.
707 SGPropertyNode::alias (const char * path)
709 return alias(getNode(path, true));
717 SGPropertyNode::unalias ()
728 * Get the target of an alias.
731 SGPropertyNode::getAliasTarget ()
733 return (_type == ALIAS ? _value.alias : 0);
737 const SGPropertyNode *
738 SGPropertyNode::getAliasTarget () const
740 return (_type == ALIAS ? _value.alias : 0);
745 * Get a non-const child by index.
748 SGPropertyNode::getChild (int position)
750 if (position >= 0 && position < nChildren())
751 return _children[position];
758 * Get a const child by index.
760 const SGPropertyNode *
761 SGPropertyNode::getChild (int position) const
763 if (position >= 0 && position < nChildren())
764 return _children[position];
771 * Get a non-const child by name and index, creating if necessary.
774 SGPropertyNode::getChild (const char * name, int index, bool create)
776 int pos = find_child(name, index, _children);
778 return _children[pos];
780 _children.push_back(new SGPropertyNode(name, index, this));
781 return _children[_children.size()-1];
789 * Get a const child by name and index.
791 const SGPropertyNode *
792 SGPropertyNode::getChild (const char * name, int index) const
794 int pos = find_child(name, index, _children);
796 return _children[pos];
803 * Get all children with the same name (but different indices).
805 vector<SGPropertyNode *>
806 SGPropertyNode::getChildren (const char * name)
808 vector<SGPropertyNode *> children;
809 int max = _children.size();
811 for (int i = 0; i < max; i++)
812 if (compare_strings(_children[i]->getName(), name))
813 children.push_back(_children[i]);
815 sort(children.begin(), children.end(), CompareIndices());
821 * Get all children const with the same name (but different indices).
823 vector<const SGPropertyNode *>
824 SGPropertyNode::getChildren (const char * name) const
826 vector<const SGPropertyNode *> children;
827 int max = _children.size();
829 for (int i = 0; i < max; i++)
830 if (compare_strings(_children[i]->getName(), name))
831 children.push_back(_children[i]);
833 sort(children.begin(), children.end(), CompareIndices());
839 SGPropertyNode::getPath (bool simplify) const
844 string path = _parent->getPath(simplify);
847 if (_index != 0 || !simplify) {
849 sprintf(buffer, "[%d]", _index);
856 SGPropertyNode::getType () const
859 return _value.alias->getType();
866 SGPropertyNode::getBoolValue () const
868 // Shortcut for common case
869 if (_attr == (READ|WRITE) && _type == BOOL)
872 if (getAttribute(TRACE_READ))
874 if (!getAttribute(READ))
875 return SGRawValue<bool>::DefaultValue;
878 return _value.alias->getBoolValue();
882 return get_int() == 0 ? false : true;
884 return get_long() == 0L ? false : true;
886 return get_float() == 0.0 ? false : true;
888 return get_double() == 0.0L ? false : true;
891 return (compare_strings(get_string(), "true") || getDoubleValue() != 0.0L);
894 return SGRawValue<bool>::DefaultValue;
899 SGPropertyNode::getIntValue () const
901 // Shortcut for common case
902 if (_attr == (READ|WRITE) && _type == INT)
905 if (getAttribute(TRACE_READ))
907 if (!getAttribute(READ))
908 return SGRawValue<int>::DefaultValue;
911 return _value.alias->getIntValue();
913 return int(get_bool());
917 return int(get_long());
919 return int(get_float());
921 return int(get_double());
924 return atoi(get_string());
927 return SGRawValue<int>::DefaultValue;
932 SGPropertyNode::getLongValue () const
934 // Shortcut for common case
935 if (_attr == (READ|WRITE) && _type == LONG)
938 if (getAttribute(TRACE_READ))
940 if (!getAttribute(READ))
941 return SGRawValue<long>::DefaultValue;
944 return _value.alias->getLongValue();
946 return long(get_bool());
948 return long(get_int());
952 return long(get_float());
954 return long(get_double());
957 return strtol(get_string(), 0, 0);
960 return SGRawValue<long>::DefaultValue;
965 SGPropertyNode::getFloatValue () const
967 // Shortcut for common case
968 if (_attr == (READ|WRITE) && _type == FLOAT)
971 if (getAttribute(TRACE_READ))
973 if (!getAttribute(READ))
974 return SGRawValue<float>::DefaultValue;
977 return _value.alias->getFloatValue();
979 return float(get_bool());
981 return float(get_int());
983 return float(get_long());
987 return float(get_double());
990 return atof(get_string());
993 return SGRawValue<float>::DefaultValue;
998 SGPropertyNode::getDoubleValue () const
1000 // Shortcut for common case
1001 if (_attr == (READ|WRITE) && _type == DOUBLE)
1002 return get_double();
1004 if (getAttribute(TRACE_READ))
1006 if (!getAttribute(READ))
1007 return SGRawValue<double>::DefaultValue;
1011 return _value.alias->getDoubleValue();
1013 return double(get_bool());
1015 return double(get_int());
1017 return double(get_long());
1019 return double(get_float());
1021 return get_double();
1024 return strtod(get_string(), 0);
1027 return SGRawValue<double>::DefaultValue;
1032 SGPropertyNode::getStringValue () const
1034 // Shortcut for common case
1035 if (_attr == (READ|WRITE) && _type == STRING)
1036 return get_string();
1038 if (getAttribute(TRACE_READ))
1040 if (!getAttribute(READ))
1041 return SGRawValue<const char *>::DefaultValue;
1042 return make_string();
1046 SGPropertyNode::setBoolValue (bool value)
1048 // Shortcut for common case
1049 if (_attr == (READ|WRITE) && _type == BOOL)
1050 return set_bool(value);
1052 bool result = false;
1054 if (_type == NONE || _type == UNSPECIFIED) {
1062 result = _value.alias->setBoolValue(value);
1065 result = set_bool(value);
1068 result = set_int(int(value));
1071 result = set_long(long(value));
1074 result = set_float(float(value));
1077 result = set_double(double(value));
1081 result = set_string(value ? "true" : "false");
1088 if (getAttribute(TRACE_WRITE))
1094 SGPropertyNode::setIntValue (int value)
1096 // Shortcut for common case
1097 if (_attr == (READ|WRITE) && _type == INT)
1098 return set_int(value);
1100 bool result = false;
1102 if (_type == NONE || _type == UNSPECIFIED) {
1105 _local_val.int_val = 0;
1110 result = _value.alias->setIntValue(value);
1113 result = set_bool(value == 0 ? false : true);
1116 result = set_int(value);
1119 result = set_long(long(value));
1122 result = set_float(float(value));
1125 result = set_double(double(value));
1130 sprintf(buf, "%d", value);
1131 result = set_string(buf);
1139 if (getAttribute(TRACE_WRITE))
1145 SGPropertyNode::setLongValue (long value)
1147 // Shortcut for common case
1148 if (_attr == (READ|WRITE) && _type == LONG)
1149 return set_long(value);
1151 bool result = false;
1153 if (_type == NONE || _type == UNSPECIFIED) {
1156 _local_val.long_val = 0L;
1161 result = _value.alias->setLongValue(value);
1164 result = set_bool(value == 0L ? false : true);
1167 result = set_int(int(value));
1170 result = set_long(value);
1173 result = set_float(float(value));
1176 result = set_double(double(value));
1181 sprintf(buf, "%ld", value);
1182 result = set_string(buf);
1190 if (getAttribute(TRACE_WRITE))
1196 SGPropertyNode::setFloatValue (float value)
1198 // Shortcut for common case
1199 if (_attr == (READ|WRITE) && _type == FLOAT)
1200 return set_float(value);
1202 bool result = false;
1204 if (_type == NONE || _type == UNSPECIFIED) {
1207 _local_val.float_val = 0;
1212 result = _value.alias->setFloatValue(value);
1215 result = set_bool(value == 0.0 ? false : true);
1218 result = set_int(int(value));
1221 result = set_long(long(value));
1224 result = set_float(value);
1227 result = set_double(double(value));
1232 sprintf(buf, "%f", value);
1233 result = set_string(buf);
1241 if (getAttribute(TRACE_WRITE))
1247 SGPropertyNode::setDoubleValue (double value)
1249 // Shortcut for common case
1250 if (_attr == (READ|WRITE) && _type == DOUBLE)
1251 return set_double(value);
1253 bool result = false;
1255 if (_type == NONE || _type == UNSPECIFIED) {
1257 _local_val.double_val = value;
1263 result = _value.alias->setDoubleValue(value);
1266 result = set_bool(value == 0.0L ? false : true);
1269 result = set_int(int(value));
1272 result = set_long(long(value));
1275 result = set_float(float(value));
1278 result = set_double(value);
1283 sprintf(buf, "%f", value);
1284 result = set_string(buf);
1292 if (getAttribute(TRACE_WRITE))
1298 SGPropertyNode::setStringValue (const char * value)
1300 // Shortcut for common case
1301 if (_attr == (READ|WRITE) && _type == STRING)
1302 return set_string(value);
1304 bool result = false;
1306 if (_type == NONE || _type == UNSPECIFIED) {
1313 result = _value.alias->setStringValue(value);
1316 result = set_bool((compare_strings(value, "true")
1317 || atoi(value)) ? true : false);
1320 result = set_int(atoi(value));
1323 result = set_long(strtol(value, 0, 0));
1326 result = set_float(atof(value));
1329 result = set_double(strtod(value, 0));
1333 result = set_string(value);
1340 if (getAttribute(TRACE_WRITE))
1346 SGPropertyNode::setUnspecifiedValue (const char * value)
1348 bool result = false;
1350 if (_type == NONE) {
1352 _type = UNSPECIFIED;
1357 result = _value.alias->setUnspecifiedValue(value);
1360 result = set_bool((compare_strings(value, "true")
1361 || atoi(value)) ? true : false);
1364 result = set_int(atoi(value));
1367 result = set_long(strtol(value, 0, 0));
1370 result = set_float(atof(value));
1373 result = set_double(strtod(value, 0));
1377 result = set_string(value);
1384 if (getAttribute(TRACE_WRITE))
1390 SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
1392 if (_type == ALIAS || _tied)
1395 useDefault = useDefault && hasValue();
1396 bool old_val = false;
1398 old_val = getBoolValue();
1403 _value.bool_val = rawValue.clone();
1406 setBoolValue(old_val);
1412 SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
1414 if (_type == ALIAS || _tied)
1417 useDefault = useDefault && hasValue();
1420 old_val = getIntValue();
1425 _value.int_val = rawValue.clone();
1428 setIntValue(old_val);
1434 SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
1436 if (_type == ALIAS || _tied)
1439 useDefault = useDefault && hasValue();
1442 old_val = getLongValue();
1447 _value.long_val = rawValue.clone();
1450 setLongValue(old_val);
1456 SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
1458 if (_type == ALIAS || _tied)
1461 useDefault = useDefault && hasValue();
1462 float old_val = 0.0;
1464 old_val = getFloatValue();
1469 _value.float_val = rawValue.clone();
1472 setFloatValue(old_val);
1478 SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
1480 if (_type == ALIAS || _tied)
1483 useDefault = useDefault && hasValue();
1484 double old_val = 0.0;
1486 old_val = getDoubleValue();
1491 _value.double_val = rawValue.clone();
1494 setDoubleValue(old_val);
1501 SGPropertyNode::tie (const SGRawValue<const char *> &rawValue, bool useDefault)
1503 if (_type == ALIAS || _tied)
1506 useDefault = useDefault && hasValue();
1509 old_val = getStringValue();
1514 _value.string_val = rawValue.clone();
1517 setStringValue(old_val.c_str());
1523 SGPropertyNode::untie ()
1530 bool val = getBoolValue();
1533 _local_val.bool_val = val;
1537 int val = getIntValue();
1540 _local_val.int_val = val;
1544 long val = getLongValue();
1547 _local_val.long_val = val;
1551 float val = getFloatValue();
1554 _local_val.float_val = val;
1558 double val = getDoubleValue();
1561 _local_val.double_val = val;
1566 string val = getStringValue();
1569 _local_val.string_val = copy_string(val.c_str());
1582 SGPropertyNode::getRootNode ()
1587 return _parent->getRootNode();
1590 const SGPropertyNode *
1591 SGPropertyNode::getRootNode () const
1596 return _parent->getRootNode();
1600 SGPropertyNode::getNode (const char * relative_path, bool create)
1602 // if (_path_cache == 0)
1603 // _path_cache = new cache_map;
1605 // SGPropertyNode * result = (*_path_cache)[relative_path];
1606 // if (result == 0) {
1607 // vector<PathComponent> components;
1608 // parse_path(relative_path, components);
1609 // result = find_node(this, components, 0, create);
1611 // (*_path_cache)[relative_path] = result;
1615 vector<PathComponent> components;
1616 parse_path(relative_path, components);
1617 return find_node(this, components, 0, create);
1621 SGPropertyNode::getNode (const char * relative_path, int index, bool create)
1623 vector<PathComponent> components;
1624 parse_path(relative_path, components);
1625 if (components.size() > 0)
1626 components[components.size()-1].index = index;
1627 return find_node(this, components, 0, create);
1630 const SGPropertyNode *
1631 SGPropertyNode::getNode (const char * relative_path) const
1633 return ((SGPropertyNode *)this)->getNode(relative_path, false);
1636 const SGPropertyNode *
1637 SGPropertyNode::getNode (const char * relative_path, int index) const
1639 return ((SGPropertyNode *)this)->getNode(relative_path, index, false);
1643 ////////////////////////////////////////////////////////////////////////
1644 // Convenience methods using relative paths.
1645 ////////////////////////////////////////////////////////////////////////
1649 * Test whether another node has a value attached.
1652 SGPropertyNode::hasValue (const char * relative_path) const
1654 const SGPropertyNode * node = getNode(relative_path);
1655 return (node == 0 ? false : node->hasValue());
1660 * Get the value type for another node.
1662 SGPropertyNode::Type
1663 SGPropertyNode::getType (const char * relative_path) const
1665 const SGPropertyNode * node = getNode(relative_path);
1666 return (node == 0 ? UNSPECIFIED : (Type)(node->getType()));
1671 * Get a bool value for another node.
1674 SGPropertyNode::getBoolValue (const char * relative_path,
1675 bool defaultValue) const
1677 const SGPropertyNode * node = getNode(relative_path);
1678 return (node == 0 ? defaultValue : node->getBoolValue());
1683 * Get an int value for another node.
1686 SGPropertyNode::getIntValue (const char * relative_path,
1687 int defaultValue) const
1689 const SGPropertyNode * node = getNode(relative_path);
1690 return (node == 0 ? defaultValue : node->getIntValue());
1695 * Get a long value for another node.
1698 SGPropertyNode::getLongValue (const char * relative_path,
1699 long defaultValue) const
1701 const SGPropertyNode * node = getNode(relative_path);
1702 return (node == 0 ? defaultValue : node->getLongValue());
1707 * Get a float value for another node.
1710 SGPropertyNode::getFloatValue (const char * relative_path,
1711 float defaultValue) const
1713 const SGPropertyNode * node = getNode(relative_path);
1714 return (node == 0 ? defaultValue : node->getFloatValue());
1719 * Get a double value for another node.
1722 SGPropertyNode::getDoubleValue (const char * relative_path,
1723 double defaultValue) const
1725 const SGPropertyNode * node = getNode(relative_path);
1726 return (node == 0 ? defaultValue : node->getDoubleValue());
1731 * Get a string value for another node.
1734 SGPropertyNode::getStringValue (const char * relative_path,
1735 const char * defaultValue) const
1737 const SGPropertyNode * node = getNode(relative_path);
1738 return (node == 0 ? defaultValue : node->getStringValue());
1743 * Set a bool value for another node.
1746 SGPropertyNode::setBoolValue (const char * relative_path, bool value)
1748 return getNode(relative_path, true)->setBoolValue(value);
1753 * Set an int value for another node.
1756 SGPropertyNode::setIntValue (const char * relative_path, int value)
1758 return getNode(relative_path, true)->setIntValue(value);
1763 * Set a long value for another node.
1766 SGPropertyNode::setLongValue (const char * relative_path, long value)
1768 return getNode(relative_path, true)->setLongValue(value);
1773 * Set a float value for another node.
1776 SGPropertyNode::setFloatValue (const char * relative_path, float value)
1778 return getNode(relative_path, true)->setFloatValue(value);
1783 * Set a double value for another node.
1786 SGPropertyNode::setDoubleValue (const char * relative_path, double value)
1788 return getNode(relative_path, true)->setDoubleValue(value);
1793 * Set a string value for another node.
1796 SGPropertyNode::setStringValue (const char * relative_path, const char * value)
1798 return getNode(relative_path, true)->setStringValue(value);
1803 * Set an unknown value for another node.
1806 SGPropertyNode::setUnspecifiedValue (const char * relative_path,
1809 return getNode(relative_path, true)->setUnspecifiedValue(value);
1814 * Test whether another node is tied.
1817 SGPropertyNode::isTied (const char * relative_path) const
1819 const SGPropertyNode * node = getNode(relative_path);
1820 return (node == 0 ? false : node->isTied());
1825 * Tie a node reached by a relative path, creating it if necessary.
1828 SGPropertyNode::tie (const char * relative_path,
1829 const SGRawValue<bool> &rawValue,
1832 return getNode(relative_path, true)->tie(rawValue, useDefault);
1837 * Tie a node reached by a relative path, creating it if necessary.
1840 SGPropertyNode::tie (const char * relative_path,
1841 const SGRawValue<int> &rawValue,
1844 return getNode(relative_path, true)->tie(rawValue, useDefault);
1849 * Tie a node reached by a relative path, creating it if necessary.
1852 SGPropertyNode::tie (const char * relative_path,
1853 const SGRawValue<long> &rawValue,
1856 return getNode(relative_path, true)->tie(rawValue, useDefault);
1861 * Tie a node reached by a relative path, creating it if necessary.
1864 SGPropertyNode::tie (const char * relative_path,
1865 const SGRawValue<float> &rawValue,
1868 return getNode(relative_path, true)->tie(rawValue, useDefault);
1873 * Tie a node reached by a relative path, creating it if necessary.
1876 SGPropertyNode::tie (const char * relative_path,
1877 const SGRawValue<double> &rawValue,
1880 return getNode(relative_path, true)->tie(rawValue, useDefault);
1885 * Tie a node reached by a relative path, creating it if necessary.
1888 SGPropertyNode::tie (const char * relative_path,
1889 const SGRawValue<const char *> &rawValue,
1892 return getNode(relative_path, true)->tie(rawValue, useDefault);
1897 * Attempt to untie another node reached by a relative path.
1900 SGPropertyNode::untie (const char * relative_path)
1902 SGPropertyNode * node = getNode(relative_path);
1903 return (node == 0 ? false : node->untie());