]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/propertyObject.hxx
Fixed a crash: the singleton needs to be instantiated the first time SGCommandMgr...
[simgear.git] / simgear / props / propertyObject.hxx
index 5cc1588ba0514dd8f264b419ace108b6472e6e2c..9e6586594e379473d50dd3a3dd1fc66b52ad315a 100644 (file)
@@ -28,6 +28,8 @@ class PropertyObjectBase
 public:
   static void setDefaultRoot(SGPropertyNode* aRoot);
   
+  PropertyObjectBase();
+  
   PropertyObjectBase(const PropertyObjectBase& aOther);
     
   PropertyObjectBase(const char* aChild);
@@ -57,17 +59,20 @@ template <typename T>
 class PropertyObject : PropertyObjectBase
 {
 public:
+  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)
   {
   
@@ -104,20 +109,41 @@ public:
 // conversion operators
   operator T () const
   {
-    return getOrThrow()->getValue<T>();
+    return getOrThrow()->template getValue<T>();
   }
 
   T operator=(const T& aValue)
   {
     SGPropertyNode* n = PropertyObjectBase::node(true);
-    if (!n) {
+    if( !n )
       return aValue;
-    }
-    
+
     n->setValue<T>(aValue);
     return aValue;
   }
 
+#define SG_DEF_ASSIGN_OP(op)\
+  T operator op##=(const T rhs)\
+  {\
+    SGPropertyNode* n = getOrThrow();\
+    T new_val = n->getValue<T>() op rhs;\
+    n->setValue<T>(new_val);\
+    return new_val;\
+  }
+
+  SG_DEF_ASSIGN_OP(+)
+  SG_DEF_ASSIGN_OP(-)
+  SG_DEF_ASSIGN_OP(*)
+  SG_DEF_ASSIGN_OP(/)
+  SG_DEF_ASSIGN_OP(%)
+  SG_DEF_ASSIGN_OP(>>)
+  SG_DEF_ASSIGN_OP(<<)
+  SG_DEF_ASSIGN_OP(&)
+  SG_DEF_ASSIGN_OP(^)
+  SG_DEF_ASSIGN_OP(|)
+
+#undef SG_DEF_ASSIGN_OP
+
   SGPropertyNode* node() const
   {
     return PropertyObjectBase::node(false);
@@ -131,13 +157,13 @@ template <>
 class PropertyObject<std::string> : 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)
   {
   
@@ -220,11 +246,9 @@ private:
 
 } // of namespace simgear
 
-/*
 typedef simgear::PropertyObject<double> SGPropObjDouble;
 typedef simgear::PropertyObject<bool> SGPropObjBool;
 typedef simgear::PropertyObject<std::string> SGPropObjString;
 typedef simgear::PropertyObject<long> SGPropObjInt;
-*/
 
 #endif