]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/propertyObject.hxx
Fix #1783: repeated error message on console
[simgear.git] / simgear / props / propertyObject.hxx
index a6d357f89d817ea40f07027a23f5d884b5503213..90e0101a95542933c30735ae9d1c625f9f20a1a8 100644 (file)
@@ -59,19 +59,20 @@ template <typename T>
 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)
   {
   
@@ -108,23 +109,44 @@ 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;
   }
 
-  SGPropertyNode* node() const
+#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(bool aCreate = false) const
   {
-    return PropertyObjectBase::node(false);
+    return PropertyObjectBase::node(aCreate);
   }
 }; // of template PropertyObject
 
@@ -135,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)
   {
   
@@ -215,9 +237,9 @@ public:
     return (s == value);    
   }
 
-  SGPropertyNode* node() const
+  SGPropertyNode* node(bool aCreate = false) const
   {
-    return PropertyObjectBase::node(false);
+    return PropertyObjectBase::node(aCreate);
   }
 private:
 };