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].
13 #include <simgear/compiler.h>
25 ////////////////////////////////////////////////////////////////////////
27 ////////////////////////////////////////////////////////////////////////
30 * Comparator class for sorting by index.
35 int operator() (const SGPropertyNode * n1, const SGPropertyNode *n2) const {
36 return (n1->getIndex() < n2->getIndex());
42 ////////////////////////////////////////////////////////////////////////
43 // Convenience macros for value access.
44 ////////////////////////////////////////////////////////////////////////
46 #define GET_BOOL (_value.bool_val->getValue())
47 #define GET_INT (_value.int_val->getValue())
48 #define GET_LONG (_value.long_val->getValue())
49 #define GET_FLOAT (_value.float_val->getValue())
50 #define GET_DOUBLE (_value.double_val->getValue())
51 #define GET_STRING (_value.string_val->getValue())
53 #define SET_BOOL(val) (_value.bool_val->setValue(val))
54 #define SET_INT(val) (_value.int_val->setValue(val))
55 #define SET_LONG(val) (_value.long_val->setValue(val))
56 #define SET_FLOAT(val) (_value.float_val->setValue(val))
57 #define SET_DOUBLE(val) (_value.double_val->setValue(val))
58 #define SET_STRING(val) (_value.string_val->setValue(val))
62 ////////////////////////////////////////////////////////////////////////
63 // Default values for every type.
64 ////////////////////////////////////////////////////////////////////////
66 const bool SGRawValue<bool>::DefaultValue = false;
67 const int SGRawValue<int>::DefaultValue = 0;
68 const long SGRawValue<long>::DefaultValue = 0L;
69 const float SGRawValue<float>::DefaultValue = 0.0;
70 const double SGRawValue<double>::DefaultValue = 0.0L;
71 const string SGRawValue<string>::DefaultValue = "";
75 ////////////////////////////////////////////////////////////////////////
76 // Local path normalization code.
77 ////////////////////////////////////////////////////////////////////////
80 * A component in a path.
89 * Parse the name for a path component.
91 * Name: [_a-zA-Z][-._a-zA-Z0-9]*
94 parse_name (const string &path, int &i)
97 int max = path.size();
101 if (i < max && path[i] == '.') {
107 if (i < max && path[i] != '/')
108 throw string(string("Illegal character after ") + name);
111 else if (isalpha(path[i]) || path[i] == '_') {
115 // The rules inside a name are a little
118 if (isalpha(path[i]) || isdigit(path[i]) || path[i] == '_' ||
119 path[i] == '-' || path[i] == '.') {
121 } else if (path[i] == '[' || path[i] == '/') {
124 throw string("name may contain only ._- and alphanumeric characters");
131 if (name.size() == 0)
132 throw string("name must begin with alpha or '_'");
140 * Parse the optional integer index for a path component.
142 * Index: "[" [0-9]+ "]"
145 parse_index (const string &path, int &i)
154 for (int max = path.size(); i < max; i++) {
155 if (isdigit(path[i])) {
156 index = (index * 10) + (path[i] - '0');
157 } else if (path[i] == ']') {
165 throw string("unterminated index (looking for ']')");
170 * Parse a single path component.
172 * Component: Name Index?
174 static inline PathComponent
175 parse_component (const string &path, int &i)
177 PathComponent component;
178 component.name = parse_name(path, i);
179 if (component.name[0] != '.')
180 component.index = parse_index(path, i);
182 component.index = -1;
188 * Parse a path into its components.
191 parse_path (const string &path, vector<PathComponent> &components)
194 int max = path.size();
196 // Check for initial '/'
197 if (path[pos] == '/') {
201 components.push_back(root);
203 while (pos < max && path[pos] == '/')
208 components.push_back(parse_component(path, pos));
209 while (pos < max && path[pos] == '/')
216 ////////////////////////////////////////////////////////////////////////
217 // Other static utility functions.
218 ////////////////////////////////////////////////////////////////////////
222 * Locate a child node by name and index.
225 find_child (const string &name, int index, vector<SGPropertyNode *> nodes)
227 int nNodes = nodes.size();
228 for (int i = 0; i < nNodes; i++) {
229 SGPropertyNode * node = nodes[i];
230 if (node->getName() == name && node->getIndex() == index)
238 * Locate another node, given a relative path.
240 static SGPropertyNode *
241 find_node (SGPropertyNode * current,
242 const vector<PathComponent> &components,
246 // Run off the end of the list
251 // Success! This is the one we want.
252 else if (position >= (int)components.size()) {
256 // Empty component means root.
257 else if (components[position].name == "") {
258 return find_node(current->getRootNode(), components, position + 1, create);
261 // . means current directory
262 else if (components[position].name == ".") {
263 return find_node(current, components, position + 1, create);
266 // .. means parent directory
267 else if (components[position].name == "..") {
268 SGPropertyNode * parent = current->getParent();
270 throw string("Attempt to move past root with '..'");
272 return find_node(parent, components, position + 1, create);
275 // Otherwise, a child name
277 SGPropertyNode * child =
278 current->getChild(components[position].name,
279 components[position].index,
281 return find_node(child, components, position + 1, create);
287 ////////////////////////////////////////////////////////////////////////
288 // Implementation of SGValue.
289 ////////////////////////////////////////////////////////////////////////
293 * Default constructor.
295 * The type will be UNKNOWN and the raw value will be "".
298 : _type(UNKNOWN), _tied(false)
300 _value.string_val = new SGRawValueInternal<string>;
307 SGValue::SGValue (const SGValue &source)
309 _type = source._type;
310 _tied = source._tied;
311 switch (source._type) {
314 _value.alias = (SGValue *)(source.getAlias());
317 _value.bool_val = source._value.bool_val->clone();
320 _value.int_val = source._value.int_val->clone();
323 _value.long_val = source._value.long_val->clone();
326 _value.float_val = source._value.float_val->clone();
329 _value.double_val = source._value.double_val->clone();
333 _value.string_val = source._value.string_val->clone();
350 * Delete and clear the current value.
353 SGValue::clear_value ()
357 _value.alias->clear_value();
359 delete _value.bool_val;
363 delete _value.int_val;
367 delete _value.long_val;
368 _value.long_val = 0L;
371 delete _value.float_val;
372 _value.float_val = 0;
375 delete _value.double_val;
376 _value.double_val = 0;
380 delete _value.string_val;
381 _value.string_val = 0;
388 * Get the current type.
390 * Does not return a type of ALIAS.
393 SGValue::getType () const
396 return _value.alias->getType();
403 * Get the current aliased value.
408 return (_type == ALIAS ? _value.alias : 0);
413 * Get the current aliased value.
416 SGValue::getAlias () const
418 return (_type == ALIAS ? _value.alias : 0);
423 * Alias to another value.
426 SGValue::alias (SGValue * alias)
428 if (alias == 0 || _type == ALIAS || _tied)
431 _value.alias = alias;
438 * Unalias from another value.
443 // FIXME: keep copy of previous value,
447 _value.string_val = new SGRawValueInternal<string>;
454 * Get a boolean value.
457 SGValue::getBoolValue () const
461 return _value.alias->getBoolValue();
465 return GET_INT == 0 ? false : true;
467 return GET_LONG == 0L ? false : true;
469 return GET_FLOAT == 0.0 ? false : true;
471 return GET_DOUBLE == 0.0L ? false : true;
474 return (GET_STRING == "true" || getDoubleValue() != 0.0L);
482 * Get an integer value.
485 SGValue::getIntValue () const
489 return _value.alias->getIntValue();
491 return int(GET_BOOL);
495 return int(GET_LONG);
497 return int(GET_FLOAT);
499 return int(GET_DOUBLE);
502 return atoi(GET_STRING.c_str());
510 * Get a long integer value.
513 SGValue::getLongValue () const
517 return _value.alias->getLongValue();
519 return long(GET_BOOL);
521 return long(GET_INT);
525 return long(GET_FLOAT);
527 return long(GET_DOUBLE);
530 return strtol(GET_STRING.c_str(), 0, 0);
539 SGValue::getFloatValue () const
543 return _value.alias->getFloatValue();
545 return float(GET_BOOL);
547 return float(GET_INT);
549 return float(GET_LONG);
553 return float(GET_DOUBLE);
556 return atof(GET_STRING.c_str());
564 * Get a double value.
567 SGValue::getDoubleValue () const
571 return _value.alias->getDoubleValue();
573 return double(GET_BOOL);
575 return double(GET_INT);
577 return double(GET_LONG);
579 return double(GET_FLOAT);
584 return strtod(GET_STRING.c_str(), 0);
592 * Get a string value.
595 SGValue::getStringValue () const
601 return _value.alias->getStringValue();
608 sprintf(buf, "%d", GET_INT);
611 sprintf(buf, "%ld", GET_LONG);
614 sprintf(buf, "%f", GET_FLOAT);
617 sprintf(buf, "%f", GET_DOUBLE);
632 SGValue::setBoolValue (bool value)
634 if (_type == UNKNOWN) {
636 _value.bool_val = new SGRawValueInternal<bool>;
642 return _value.alias->setBoolValue(value);
644 return SET_BOOL(value);
646 return SET_INT(int(value));
648 return SET_LONG(long(value));
650 return SET_FLOAT(float(value));
652 return SET_DOUBLE(double(value));
654 return SET_STRING(value ? "true" : "false");
665 SGValue::setIntValue (int value)
667 if (_type == UNKNOWN) {
669 _value.int_val = new SGRawValueInternal<int>;
675 return _value.alias->setIntValue(value);
677 return SET_BOOL(value == 0 ? false : true);
679 return SET_INT(value);
681 return SET_LONG(long(value));
683 return SET_FLOAT(float(value));
685 return SET_DOUBLE(double(value));
688 sprintf(buf, "%d", value);
689 return SET_STRING(buf);
701 SGValue::setLongValue (long value)
703 if (_type == UNKNOWN) {
705 _value.long_val = new SGRawValueInternal<long>;
711 return _value.alias->setLongValue(value);
713 return SET_BOOL(value == 0L ? false : true);
715 return SET_INT(int(value));
717 return SET_LONG(value);
719 return SET_FLOAT(float(value));
721 return SET_DOUBLE(double(value));
724 sprintf(buf, "%d", value);
725 return SET_STRING(buf);
737 SGValue::setFloatValue (float value)
739 if (_type == UNKNOWN) {
741 _value.float_val = new SGRawValueInternal<float>;
747 return _value.alias->setFloatValue(value);
749 return SET_BOOL(value == 0.0 ? false : true);
751 return SET_INT(int(value));
753 return SET_LONG(long(value));
755 return SET_FLOAT(value);
757 return SET_DOUBLE(double(value));
760 sprintf(buf, "%f", value);
761 return SET_STRING(buf);
770 * Set a double value.
773 SGValue::setDoubleValue (double value)
775 if (_type == UNKNOWN) {
777 _value.double_val = new SGRawValueInternal<double>;
783 return _value.alias->setDoubleValue(value);
785 return SET_BOOL(value == 0.0L ? false : true);
787 return SET_INT(int(value));
789 return SET_LONG(long(value));
791 return SET_FLOAT(float(value));
793 return SET_DOUBLE(value);
796 sprintf(buf, "%lf", value);
797 return SET_STRING(buf);
806 * Set a string value.
809 SGValue::setStringValue (string value)
811 if (_type == UNKNOWN) {
813 _value.string_val = new SGRawValueInternal<string>;
819 return _value.alias->setStringValue(value);
821 return SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
823 return SET_INT(atoi(value.c_str()));
825 return SET_LONG(strtol(value.c_str(), 0, 0));
827 return SET_FLOAT(atof(value.c_str()));
829 return SET_DOUBLE(strtod(value.c_str(), 0));
831 return SET_STRING(value);
839 * Set a value of unknown type (stored as a string).
842 SGValue::setUnknownValue (string value)
846 return _value.alias->setUnknownValue(value);
848 return SET_BOOL((value == "true" || atoi(value.c_str())) ? true : false);
850 return SET_INT(atoi(value.c_str()));
852 return SET_LONG(strtol(value.c_str(), 0, 0));
854 return SET_FLOAT(atof(value.c_str()));
856 return SET_DOUBLE(strtod(value.c_str(), 0));
859 return SET_STRING(value);
870 SGValue::tie (const SGRawValue<bool> &value, bool use_default)
873 return _value.alias->tie(value, use_default);
877 bool old_val = false;
879 old_val = getBoolValue();
884 _value.bool_val = value.clone();
887 setBoolValue(old_val);
897 SGValue::tie (const SGRawValue<int> &value, bool use_default)
900 return _value.alias->tie(value, use_default);
906 old_val = getIntValue();
911 _value.int_val = value.clone();
914 setIntValue(old_val);
924 SGValue::tie (const SGRawValue<long> &value, bool use_default)
927 return _value.alias->tie(value, use_default);
933 old_val = getLongValue();
938 _value.long_val = value.clone();
941 setLongValue(old_val);
951 SGValue::tie (const SGRawValue<float> &value, bool use_default)
954 return _value.alias->tie(value, use_default);
960 old_val = getFloatValue();
965 _value.float_val = value.clone();
968 setFloatValue(old_val);
975 * Tie a double value.
978 SGValue::tie (const SGRawValue<double> &value, bool use_default)
981 return _value.alias->tie(value, use_default);
985 double old_val = 0.0;
987 old_val = getDoubleValue();
992 _value.double_val = value.clone();
995 setDoubleValue(old_val);
1002 * Tie a string value.
1005 SGValue::tie (const SGRawValue<string> &value, bool use_default)
1008 return _value.alias->tie(value, use_default);
1014 old_val = getStringValue();
1019 _value.string_val = value.clone();
1022 setStringValue(old_val);
1039 return _value.alias->untie();
1042 bool val = getBoolValue();
1044 _value.bool_val = new SGRawValueInternal<bool>;
1049 int val = getIntValue();
1051 _value.int_val = new SGRawValueInternal<int>;
1056 long val = getLongValue();
1058 _value.long_val = new SGRawValueInternal<long>;
1063 float val = getFloatValue();
1065 _value.float_val = new SGRawValueInternal<float>;
1070 double val = getDoubleValue();
1072 _value.double_val = new SGRawValueInternal<double>;
1077 string val = getStringValue();
1079 _value.string_val = new SGRawValueInternal<string>;
1091 ////////////////////////////////////////////////////////////////////////
1092 // Implementation of SGPropertyNode.
1093 ////////////////////////////////////////////////////////////////////////
1097 * Utility function: given a value, find the property node.
1099 static SGPropertyNode *
1100 find_node_by_value (SGPropertyNode * start_node, const SGValue * value)
1102 if (start_node->getValue() == value) {
1104 } else for (int i = 0; i < start_node->nChildren(); i++) {
1105 SGPropertyNode * child =
1106 find_node_by_value(start_node->getChild(i), value);
1115 * Default constructor: always creates a root node.
1117 SGPropertyNode::SGPropertyNode ()
1118 : _value(0), _name(""), _index(0), _parent(0), _target(0)
1124 * Convenience constructor.
1126 SGPropertyNode::SGPropertyNode (const string &name,
1127 int index, SGPropertyNode * parent)
1128 : _value(0), _name(name), _index(index), _parent(parent), _target(0)
1136 SGPropertyNode::~SGPropertyNode ()
1139 for (int i = 0; i < (int)_children.size(); i++)
1140 delete _children[i];
1145 * Get a value, optionally creating it if not present.
1148 SGPropertyNode::getValue (bool create)
1150 if (_value == 0 && create)
1151 _value = new SGValue();
1157 * Alias to another node.
1160 SGPropertyNode::alias (SGPropertyNode * target)
1163 _value = new SGValue();
1165 return _value->alias(target->getValue(true));
1170 * Alias to another node by path.
1173 SGPropertyNode::alias (const string &path)
1175 return alias(getNode(path, true));
1183 SGPropertyNode::unalias ()
1186 return (_value != 0 ? _value->unalias() : false);
1191 * Test whether this node is aliased.
1194 SGPropertyNode::isAlias () const
1196 return (_value != 0 ? _value->isAlias() : false);
1201 * Get the target of an alias.
1203 * This is tricky, because it is actually the value that is aliased,
1204 * and someone could realias or unalias the value directly without
1205 * going through the property node. The node caches its best guess,
1206 * but it may have to search the whole property tree.
1208 * @return The target node for the alias, or 0 if the node is not aliased.
1211 SGPropertyNode::getAliasTarget ()
1213 if (_value == 0 || !_value->isAlias()) {
1215 } else if (_target != 0 && _target->getValue() == _value->getAlias()) {
1218 _target = find_node_by_value(getRootNode(), _value->getAlias());
1223 const SGPropertyNode *
1224 SGPropertyNode::getAliasTarget () const
1226 if (_value == 0 || !_value->isAlias()) {
1228 } else if (_target != 0 && _target->getValue() == _value->getAlias()) {
1231 // FIXME: const cast
1233 find_node_by_value((SGPropertyNode *)getRootNode(), _value->getAlias());
1239 * Get a non-const child by index.
1242 SGPropertyNode::getChild (int position)
1244 if (position >= 0 && position < nChildren())
1245 return _children[position];
1252 * Get a const child by index.
1254 const SGPropertyNode *
1255 SGPropertyNode::getChild (int position) const
1257 if (position >= 0 && position < nChildren())
1258 return _children[position];
1265 * Get a non-const child by name and index, creating if necessary.
1268 SGPropertyNode::getChild (const string &name, int index, bool create)
1270 int pos = find_child(name, index, _children);
1272 return _children[pos];
1273 } else if (create) {
1274 _children.push_back(new SGPropertyNode(name, index, this));
1275 return _children[_children.size()-1];
1283 * Get a const child by name and index.
1285 const SGPropertyNode *
1286 SGPropertyNode::getChild (const string &name, int index) const
1288 int pos = find_child(name, index, _children);
1290 return _children[pos];
1297 * Get all children with the same name (but different indices).
1299 vector<SGPropertyNode *>
1300 SGPropertyNode::getChildren (const string &name)
1302 vector<SGPropertyNode *> children;
1303 int max = _children.size();
1305 for (int i = 0; i < max; i++)
1306 if (_children[i]->getName() == name)
1307 children.push_back(_children[i]);
1309 sort(children.begin(), children.end(), CompareIndices());
1315 * Get all children const with the same name (but different indices).
1317 vector<const SGPropertyNode *>
1318 SGPropertyNode::getChildren (const string &name) const
1320 vector<const SGPropertyNode *> children;
1321 int max = _children.size();
1323 for (int i = 0; i < max; i++)
1324 if (_children[i]->getName() == name)
1325 children.push_back(_children[i]);
1327 sort(children.begin(), children.end(), CompareIndices());
1333 SGPropertyNode::getPath (bool simplify) const
1338 string path = _parent->getPath(simplify);
1341 if (_index != 0 || !simplify) {
1343 sprintf(buffer, "[%d]", _index);
1350 SGPropertyNode::getType () const
1353 return _value->getType();
1355 return SGValue::UNKNOWN;
1360 SGPropertyNode::getBoolValue () const
1362 return (_value == 0 ? SGRawValue<bool>::DefaultValue
1363 : _value->getBoolValue());
1367 SGPropertyNode::getIntValue () const
1369 return (_value == 0 ? SGRawValue<int>::DefaultValue
1370 : _value->getIntValue());
1374 SGPropertyNode::getLongValue () const
1376 return (_value == 0 ? SGRawValue<long>::DefaultValue
1377 : _value->getLongValue());
1381 SGPropertyNode::getFloatValue () const
1383 return (_value == 0 ? SGRawValue<float>::DefaultValue
1384 : _value->getFloatValue());
1388 SGPropertyNode::getDoubleValue () const
1390 return (_value == 0 ? SGRawValue<double>::DefaultValue
1391 : _value->getDoubleValue());
1395 SGPropertyNode::getStringValue () const
1397 return (_value == 0 ? SGRawValue<string>::DefaultValue
1398 : _value->getStringValue());
1402 SGPropertyNode::setBoolValue (bool val)
1405 _value = new SGValue();
1406 return _value->setBoolValue(val);
1410 SGPropertyNode::setIntValue (int val)
1413 _value = new SGValue();
1414 return _value->setIntValue(val);
1418 SGPropertyNode::setLongValue (long val)
1421 _value = new SGValue();
1422 return _value->setLongValue(val);
1426 SGPropertyNode::setFloatValue (float val)
1429 _value = new SGValue();
1430 return _value->setFloatValue(val);
1434 SGPropertyNode::setDoubleValue (double val)
1437 _value = new SGValue();
1438 return _value->setDoubleValue(val);
1442 SGPropertyNode::setStringValue (string val)
1445 _value = new SGValue();
1446 return _value->setStringValue(val);
1450 SGPropertyNode::setUnknownValue (string val)
1453 _value = new SGValue();
1454 return _value->setUnknownValue(val);
1458 SGPropertyNode::isTied () const
1460 return (_value == 0 ? false : _value->isTied());
1464 SGPropertyNode::tie (const SGRawValue<bool> &rawValue, bool useDefault)
1467 _value = new SGValue();
1468 return _value->tie(rawValue, useDefault);
1472 SGPropertyNode::tie (const SGRawValue<int> &rawValue, bool useDefault)
1475 _value = new SGValue();
1476 return _value->tie(rawValue, useDefault);
1480 SGPropertyNode::tie (const SGRawValue<long> &rawValue, bool useDefault)
1483 _value = new SGValue();
1484 return _value->tie(rawValue, useDefault);
1488 SGPropertyNode::tie (const SGRawValue<float> &rawValue, bool useDefault)
1491 _value = new SGValue();
1492 return _value->tie(rawValue, useDefault);
1496 SGPropertyNode::tie (const SGRawValue<double> &rawValue, bool useDefault)
1499 _value = new SGValue();
1500 return _value->tie(rawValue, useDefault);
1504 SGPropertyNode::tie (const SGRawValue<string> &rawValue, bool useDefault)
1507 _value = new SGValue();
1508 return _value->tie(rawValue, useDefault);
1512 SGPropertyNode::untie ()
1514 return (_value == 0 ? false : _value->untie());
1518 SGPropertyNode::getRootNode ()
1523 return _parent->getRootNode();
1526 const SGPropertyNode *
1527 SGPropertyNode::getRootNode () const
1532 return _parent->getRootNode();
1536 SGPropertyNode::getNode (const string &relative_path, bool create)
1538 vector<PathComponent> components;
1539 parse_path(relative_path, components);
1540 return find_node(this, components, 0, create);
1543 const SGPropertyNode *
1544 SGPropertyNode::getNode (const string &relative_path) const
1546 vector<PathComponent> components;
1547 parse_path(relative_path, components);
1548 // FIXME: cast away const
1549 return find_node((SGPropertyNode *)this, components, 0, false);
1554 ////////////////////////////////////////////////////////////////////////
1555 // Convenience methods using relative paths.
1556 ////////////////////////////////////////////////////////////////////////
1560 * Test whether another node has a value attached.
1563 SGPropertyNode::hasValue (const string &relative_path) const
1565 const SGPropertyNode * node = getNode(relative_path);
1566 return (node == 0 ? false : node->hasValue());
1571 * Get the value for another node.
1574 SGPropertyNode::getValue (const string &relative_path, bool create)
1576 SGPropertyNode * node = getNode(relative_path, create);
1577 if (node != 0 && !node->hasValue())
1578 node->setUnknownValue("");
1579 return (node == 0 ? 0 : node->getValue(create));
1584 * Get the value for another node.
1587 SGPropertyNode::getValue (const string &relative_path) const
1589 const SGPropertyNode * node = getNode(relative_path);
1590 return (node == 0 ? 0 : node->getValue());
1595 * Get the value type for another node.
1598 SGPropertyNode::getType (const string &relative_path) const
1600 const SGPropertyNode * node = getNode(relative_path);
1601 return (node == 0 ? SGValue::UNKNOWN : node->getType());
1606 * Get a bool value for another node.
1609 SGPropertyNode::getBoolValue (const string &relative_path,
1610 bool defaultValue) const
1612 const SGPropertyNode * node = getNode(relative_path);
1613 return (node == 0 ? defaultValue : node->getBoolValue());
1618 * Get an int value for another node.
1621 SGPropertyNode::getIntValue (const string &relative_path,
1622 int defaultValue) const
1624 const SGPropertyNode * node = getNode(relative_path);
1625 return (node == 0 ? defaultValue : node->getIntValue());
1630 * Get a long value for another node.
1633 SGPropertyNode::getLongValue (const string &relative_path,
1634 long defaultValue) const
1636 const SGPropertyNode * node = getNode(relative_path);
1637 return (node == 0 ? defaultValue : node->getLongValue());
1642 * Get a float value for another node.
1645 SGPropertyNode::getFloatValue (const string &relative_path,
1646 float defaultValue) const
1648 const SGPropertyNode * node = getNode(relative_path);
1649 return (node == 0 ? defaultValue : node->getFloatValue());
1654 * Get a double value for another node.
1657 SGPropertyNode::getDoubleValue (const string &relative_path,
1658 double defaultValue) const
1660 const SGPropertyNode * node = getNode(relative_path);
1661 return (node == 0 ? defaultValue : node->getDoubleValue());
1666 * Get a string value for another node.
1669 SGPropertyNode::getStringValue (const string &relative_path,
1670 string defaultValue) const
1672 const SGPropertyNode * node = getNode(relative_path);
1673 return (node == 0 ? defaultValue : node->getStringValue());
1678 * Set a bool value for another node.
1681 SGPropertyNode::setBoolValue (const string &relative_path, bool value)
1683 return getNode(relative_path, true)->setBoolValue(value);
1688 * Set an int value for another node.
1691 SGPropertyNode::setIntValue (const string &relative_path, int value)
1693 return getNode(relative_path, true)->setIntValue(value);
1698 * Set a long value for another node.
1701 SGPropertyNode::setLongValue (const string &relative_path, long value)
1703 return getNode(relative_path, true)->setLongValue(value);
1708 * Set a float value for another node.
1711 SGPropertyNode::setFloatValue (const string &relative_path, float value)
1713 return getNode(relative_path, true)->setFloatValue(value);
1718 * Set a double value for another node.
1721 SGPropertyNode::setDoubleValue (const string &relative_path, double value)
1723 return getNode(relative_path, true)->setDoubleValue(value);
1728 * Set a string value for another node.
1731 SGPropertyNode::setStringValue (const string &relative_path, string value)
1733 return getNode(relative_path, true)->setStringValue(value);
1738 * Set an unknown value for another node.
1741 SGPropertyNode::setUnknownValue (const string &relative_path, string value)
1743 return getNode(relative_path, true)->setUnknownValue(value);
1748 * Test whether another node is tied.
1751 SGPropertyNode::isTied (const string &relative_path) const
1753 const SGPropertyNode * node = getNode(relative_path);
1754 return (node == 0 ? false : node->isTied());
1759 * Tie a node reached by a relative path, creating it if necessary.
1762 SGPropertyNode::tie (const string &relative_path,
1763 const SGRawValue<bool> &rawValue,
1766 return getNode(relative_path, true)->tie(rawValue, useDefault);
1771 * Tie a node reached by a relative path, creating it if necessary.
1774 SGPropertyNode::tie (const string &relative_path,
1775 const SGRawValue<int> &rawValue,
1778 return getNode(relative_path, true)->tie(rawValue, useDefault);
1783 * Tie a node reached by a relative path, creating it if necessary.
1786 SGPropertyNode::tie (const string &relative_path,
1787 const SGRawValue<long> &rawValue,
1790 return getNode(relative_path, true)->tie(rawValue, useDefault);
1795 * Tie a node reached by a relative path, creating it if necessary.
1798 SGPropertyNode::tie (const string &relative_path,
1799 const SGRawValue<float> &rawValue,
1802 return getNode(relative_path, true)->tie(rawValue, useDefault);
1807 * Tie a node reached by a relative path, creating it if necessary.
1810 SGPropertyNode::tie (const string &relative_path,
1811 const SGRawValue<double> &rawValue,
1814 return getNode(relative_path, true)->tie(rawValue, useDefault);
1819 * Tie a node reached by a relative path, creating it if necessary.
1822 SGPropertyNode::tie (const string &relative_path,
1823 const SGRawValue<string> &rawValue,
1826 return getNode(relative_path, true)->tie(rawValue, useDefault);
1831 * Attempt to untie another node reached by a relative path.
1834 SGPropertyNode::untie (const string &relative_path)
1836 SGPropertyNode * node = getNode(relative_path);
1837 return (node == 0 ? false : node->untie());