X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2FpropertyObject.cxx;h=7a46056080ea67b153c27d53d4628d4c2abbd8cf;hb=2acac617fcf27b49a9396e9c040c8b4b437529f1;hp=0685ae917463802481a8c7ab2f5e7769f4e469af;hpb=ac535de2fa614e7ee18b766874c937ddc6476af6;p=simgear.git diff --git a/simgear/props/propertyObject.cxx b/simgear/props/propertyObject.cxx index 0685ae91..7a460560 100644 --- a/simgear/props/propertyObject.cxx +++ b/simgear/props/propertyObject.cxx @@ -21,6 +21,8 @@ #include "propertyObject.hxx" +#include + namespace simgear { @@ -30,9 +32,15 @@ void PropertyObjectBase::setDefaultRoot(SGPropertyNode* aRoot) { static_defaultRoot = aRoot; } + +PropertyObjectBase::PropertyObjectBase() : + _path(NULL), + _prop(NULL) +{ + +} PropertyObjectBase::PropertyObjectBase(const PropertyObjectBase& aOther) : - _base(aOther._base), _path(aOther._path), _prop(aOther._prop) { @@ -40,32 +48,57 @@ PropertyObjectBase::PropertyObjectBase(const PropertyObjectBase& aOther) : } PropertyObjectBase::PropertyObjectBase(const char* aChild) : - _base(NULL), _path(aChild), _prop(NULL) { } PropertyObjectBase::PropertyObjectBase(SGPropertyNode* aNode, const char* aChild) : - _base(aNode), _path(aChild), - _prop(NULL) + _prop(aNode) { } SGPropertyNode* PropertyObjectBase::node(bool aCreate) const { - if (_prop) { + if (_path == NULL) { // already resolved return _prop; } - _prop = _base ? _base : static_defaultRoot; - if (_path) { - _prop = _prop->getNode(_path, aCreate); - } + SGPropertyNode *r = _prop ? _prop : static_defaultRoot, + *prop = r->getNode(_path, aCreate); - return _prop; + if( prop ) + { + // resolve worked, we will cache from now on, so clear _path and cache prop + _path = NULL; + _prop = prop; + } + + return prop; +} + +SGPropertyNode* PropertyObjectBase::getOrThrow() const +{ + SGPropertyNode* n = node(false); + if (!n) { + std::string path; + if (_prop) { + path = _prop->getPath(); + if (_path) { + path += '/'; + } + } + + if (_path) { + path += _path; + } + + throw sg_exception("Unknown property:" + path); + } + + return n; } } // of namespace simgear