X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmisc%2Fprops.cxx;h=83a2ef320b3a28b509d5f0dba144e3f408f906ed;hb=2d1b2ca93836bbb6498e67445dfbf5d5a3593331;hp=2a66fba57fc0dfa01e00267d5c54fb6b0512eb9b;hpb=6fa9f86d1c0adf7b1257b3873b6842a45948b1fb;p=simgear.git diff --git a/simgear/misc/props.cxx b/simgear/misc/props.cxx index 2a66fba5..83a2ef32 100644 --- a/simgear/misc/props.cxx +++ b/simgear/misc/props.cxx @@ -299,6 +299,7 @@ SGPropertyNode::SGPropertyNode () : _name(""), _index(0), _parent(0), + _path_cache(0), _type(NONE), _tied(false), _attr(READ|WRITE) @@ -313,6 +314,7 @@ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node) : _name(node._name), _index(node._index), _parent(0), // don't copy the parent + _path_cache(0), _type(node._type), _tied(node._tied), _attr(node._attr) @@ -351,8 +353,13 @@ SGPropertyNode::SGPropertyNode (const SGPropertyNode &node) */ SGPropertyNode::SGPropertyNode (const string &name, int index, SGPropertyNode * parent) - : _name(name), _index(index), _parent(parent), _type(NONE), - _tied(false), _attr(READ|WRITE) + : _name(name), + _index(index), + _parent(parent), + _path_cache(0), + _type(NONE), + _tied(false), + _attr(READ|WRITE) { } @@ -365,6 +372,7 @@ SGPropertyNode::~SGPropertyNode () for (int i = 0; i < (int)_children.size(); i++) { delete _children[i]; } + delete _path_cache; clear_value(); } @@ -442,9 +450,10 @@ SGPropertyNode::get_string () const case STRING: case UNSPECIFIED: return GET_STRING; + case NONE: + default: + return ""; } - - return ""; // if NONE } @@ -668,9 +677,10 @@ SGPropertyNode::getBoolValue () const case STRING: case UNSPECIFIED: return (GET_STRING == "true" || getDoubleValue() != 0.0L); + case NONE: + default: + return false; } - - return false; // if NONE } int @@ -694,9 +704,10 @@ SGPropertyNode::getIntValue () const case STRING: case UNSPECIFIED: return atoi(GET_STRING.c_str()); + case NONE: + default: + return 0; } - - return 0; // if NONE } long @@ -720,9 +731,10 @@ SGPropertyNode::getLongValue () const case STRING: case UNSPECIFIED: return strtol(GET_STRING.c_str(), 0, 0); + case NONE: + default: + return 0L; } - - return 0L; // if NONE } float @@ -746,9 +758,10 @@ SGPropertyNode::getFloatValue () const case STRING: case UNSPECIFIED: return atof(GET_STRING.c_str()); + case NONE: + default: + return 0.0; } - - return 0.0; // if NONE } double @@ -772,9 +785,10 @@ SGPropertyNode::getDoubleValue () const case STRING: case UNSPECIFIED: return strtod(GET_STRING.c_str(), 0); + case NONE: + default: + return 0.0L; } - - return 0.0L; // if NONE } string @@ -815,8 +829,12 @@ SGPropertyNode::setBoolValue (bool value) result = SET_DOUBLE(double(value)); break; case STRING: + case UNSPECIFIED: result = SET_STRING(value ? "true" : "false"); break; + case NONE: + default: + break; } DO_TRACE_WRITE(BOOL); @@ -853,12 +871,16 @@ SGPropertyNode::setIntValue (int value) case DOUBLE: result = SET_DOUBLE(double(value)); break; - case STRING: { + case STRING: + case UNSPECIFIED: { char buf[128]; sprintf(buf, "%d", value); result = SET_STRING(buf); break; } + case NONE: + default: + break; } DO_TRACE_WRITE(INT); @@ -895,12 +917,16 @@ SGPropertyNode::setLongValue (long value) case DOUBLE: result = SET_DOUBLE(double(value)); break; - case STRING: { + case STRING: + case UNSPECIFIED: { char buf[128]; - sprintf(buf, "%d", value); + sprintf(buf, "%ld", value); result = SET_STRING(buf); break; } + case NONE: + default: + break; } DO_TRACE_WRITE(LONG); @@ -937,12 +963,16 @@ SGPropertyNode::setFloatValue (float value) case DOUBLE: result = SET_DOUBLE(double(value)); break; - case STRING: { + case STRING: + case UNSPECIFIED: { char buf[128]; sprintf(buf, "%f", value); result = SET_STRING(buf); break; } + case NONE: + default: + break; } DO_TRACE_WRITE(FLOAT); @@ -979,12 +1009,16 @@ SGPropertyNode::setDoubleValue (double value) case DOUBLE: result = SET_DOUBLE(value); break; - case STRING: { + case STRING: + case UNSPECIFIED: { char buf[128]; - sprintf(buf, "%lf", value); + sprintf(buf, "%f", value); result = SET_STRING(buf); break; } + case NONE: + default: + break; } DO_TRACE_WRITE(DOUBLE); @@ -1022,8 +1056,12 @@ SGPropertyNode::setStringValue (string value) result = SET_DOUBLE(strtod(value.c_str(), 0)); break; case STRING: + case UNSPECIFIED: result = SET_STRING(value); break; + case NONE: + default: + break; } DO_TRACE_WRITE(STRING); @@ -1064,6 +1102,9 @@ SGPropertyNode::setUnspecifiedValue (string value) case UNSPECIFIED: result = SET_STRING(value); break; + case NONE: + default: + break; } DO_TRACE_WRITE(UNSPECIFIED); @@ -1244,7 +1285,8 @@ SGPropertyNode::untie () SET_DOUBLE(val); break; } - case STRING: { + case STRING: + case UNSPECIFIED: { string val = getStringValue(); clear_value(); _type = STRING; @@ -1252,6 +1294,9 @@ SGPropertyNode::untie () SET_STRING(val); break; } + case NONE: + default: + break; } _tied = false; @@ -1278,21 +1323,42 @@ SGPropertyNode::getRootNode () const SGPropertyNode * SGPropertyNode::getNode (const string &relative_path, bool create) +{ + if (_path_cache == 0) + _path_cache = new cache_map; + + SGPropertyNode * result = (*_path_cache)[relative_path]; + if (result == 0) { + vector components; + parse_path(relative_path, components); + result = find_node(this, components, 0, create); + (*_path_cache)[relative_path] = result; + } + + return result; +} + +SGPropertyNode * +SGPropertyNode::getNode (const string &relative_path, int index, bool create) { vector components; parse_path(relative_path, components); + if (components.size() > 0) + components[components.size()-1].index = index; return find_node(this, components, 0, create); } const SGPropertyNode * SGPropertyNode::getNode (const string &relative_path) const { - vector components; - parse_path(relative_path, components); - // FIXME: cast away const - return find_node((SGPropertyNode *)this, components, 0, false); + return ((SGPropertyNode *)this)->getNode(relative_path, false); } +const SGPropertyNode * +SGPropertyNode::getNode (const string &relative_path, int index) const +{ + return ((SGPropertyNode *)this)->getNode(relative_path, index, false); +} ////////////////////////////////////////////////////////////////////////