From: Thomas Geymayer Date: Thu, 7 Feb 2013 00:22:09 +0000 (+0100) Subject: Fix PropertyObject bug and interface improvements. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=21e2a769eb73fce9f043277928f8ecf198124e71;p=simgear.git Fix PropertyObject bug and interface improvements. - Fix overwriting of parent node if PropertyObject::node() is called for a non-existing node. - Prevent implicit conversion from const char* and SGPropertyNode* --- diff --git a/simgear/props/propertyObject.cxx b/simgear/props/propertyObject.cxx index f97209af..7a460560 100644 --- a/simgear/props/propertyObject.cxx +++ b/simgear/props/propertyObject.cxx @@ -66,15 +66,17 @@ SGPropertyNode* PropertyObjectBase::node(bool aCreate) const return _prop; } - SGPropertyNode* r = _prop ? _prop : static_defaultRoot; - _prop = r->getNode(_path, aCreate); + SGPropertyNode *r = _prop ? _prop : static_defaultRoot, + *prop = r->getNode(_path, aCreate); - if (_prop) { - // resolve worked, we will cache from now on, so clear _path + if( prop ) + { + // resolve worked, we will cache from now on, so clear _path and cache prop _path = NULL; + _prop = prop; } - return _prop; + return prop; } SGPropertyNode* PropertyObjectBase::getOrThrow() const diff --git a/simgear/props/propertyObject.hxx b/simgear/props/propertyObject.hxx index 753be9f4..ffa4866b 100644 --- a/simgear/props/propertyObject.hxx +++ b/simgear/props/propertyObject.hxx @@ -59,19 +59,20 @@ template class PropertyObject : PropertyObjectBase { public: - PropertyObject(); + PropertyObject() + {} /** * Create from path relative to the default root, and option default value */ - PropertyObject(const char* aChild) : + explicit PropertyObject(const char* aChild) : PropertyObjectBase(aChild) { } /** * Create from a node, with optional relative path */ - PropertyObject(SGPropertyNode* aNode, const char* aChild = NULL) : + explicit PropertyObject(SGPropertyNode* aNode, const char* aChild = NULL) : PropertyObjectBase(aNode, aChild) { @@ -115,6 +116,7 @@ public: { SGPropertyNode* n = PropertyObjectBase::node(true); if (!n) { + std::cout << "no node" << std::endl; return aValue; } @@ -157,13 +159,13 @@ template <> class PropertyObject : PropertyObjectBase { public: - PropertyObject(const char* aChild) : + explicit PropertyObject(const char* aChild) : PropertyObjectBase(aChild) { } - PropertyObject(SGPropertyNode* aNode, const char* aChild = NULL) : + explicit PropertyObject(SGPropertyNode* aNode, const char* aChild = NULL) : PropertyObjectBase(aNode, aChild) {