]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/propertyObject.cxx
Merge branch 'next' of git://gitorious.org/fg/simgear into next
[simgear.git] / simgear / props / propertyObject.cxx
index ff90ce77afdd3701630020ee39ad712a7643cf75..df3f81f990004088dbb2d88044cf95b7c2846105 100644 (file)
 
 #include "propertyObject.hxx"
 
+#include <simgear/math/SGMath.hxx>
+
+#include <simgear/structure/exception.hxx>
+
 namespace simgear
 {
 
@@ -31,61 +35,64 @@ void PropertyObjectBase::setDefaultRoot(SGPropertyNode* aRoot)
   static_defaultRoot = aRoot;
 }
 
+PropertyObjectBase::PropertyObjectBase(const PropertyObjectBase& aOther) :
+  _path(aOther._path),
+  _prop(aOther._prop)
+{
+
+}
+
 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);
   
+  if (_prop) {
+    // resolve worked, we will cache from now on, so clear _path
+    _path = NULL;
+  }
+
   return _prop;
 }
 
-} // of namespace simgear
-
-void test()
+SGPropertyNode* PropertyObjectBase::getOrThrow() const
 {
-  SGPropObjDouble foo("/bar/foo");
+  SGPropertyNode* n = node(false);
+  if (!n) {
+    std::string path;
+    if (_prop) {
+      path = _prop->getPath();
+      if (_path) {
+        path += '/';      
+      }
+    }
 
-  SGPropertyNode* zoob;
+    if (_path) {
+      path += _path;
+    }
 
-  SGPropObjDouble foo2 = SGPropObjDouble::create(zoob, "foo2", 42.0);
-  
-  foo = 1123.0;
-  foo2 =  43;
-  
-  std::string s("lalala");
-  
-  foo = "lalal";
-  
-  
-  SGPropObjString sp(zoob);
-  sp = "fooo";
-  s =  sp;
-  
+    throw sg_exception("Unknown property:" + path);
+  }
 
-  SGPropObjBool bp("/some nice big path");
-  bp = false;
-  
-  bp = 456;
-  int i5 = bp;
+  return n;
 }
+
+} // of namespace simgear
+