]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/props.hxx
math: Move lerp function into SGMisc.
[simgear.git] / simgear / props / props.hxx
index a80fc10ae7c9dc8415bcbd3d02de4673cdeb8b18..38c9c0a2e2ea058cdd9eb684b047ef00970e789b 100644 (file)
@@ -760,7 +760,10 @@ public:
     REMOVED = 8,
     TRACE_READ = 16,
     TRACE_WRITE = 32,
-    USERARCHIVE = 64
+    USERARCHIVE = 64,
+    PRESERVE = 128
+    // beware: if you add another attribute here,
+    // also update value of "LAST_USED_ATTRIBUTE".
   };
 
 
@@ -1786,8 +1789,12 @@ bool SGPropertyNode::tie(const SGRawValue<T> &rawValue, bool useDefault)
         _type = EXTENDED;
     _tied = true;
     _value.val = rawValue.clone();
-    if (useDefault)
+    if (useDefault) {
+        int save_attributes = getAttributes();
+        setAttribute( WRITE, true );
         setValue(old_val);
+        setAttributes( save_attributes );
+    }
     return true;
 }
 
@@ -1931,6 +1938,36 @@ struct Hash
 };
 }
 }
+
+/** Convenience class for change listener callbacks without
+ * creating a derived class implementing a "valueChanged" method.
+ * Also removes listener on destruction automatically.
+ */
+template<class T>
+class SGPropertyChangeCallback
+    : public SGPropertyChangeListener
+{
+public:
+    SGPropertyChangeCallback(T* obj, void (T::*method)(SGPropertyNode*),
+                             SGPropertyNode_ptr property,bool initial=false)
+        : _obj(obj), _callback(method), _property(property)
+    {
+        _property->addChangeListener(this,initial);
+    }
+    virtual ~SGPropertyChangeCallback()
+    {
+        _property->removeChangeListener(this);
+    }
+    void valueChanged (SGPropertyNode * node)
+    {
+        (_obj->*_callback)(node);
+    }
+private:
+    T* _obj;
+    void (T::*_callback)(SGPropertyNode*);
+    SGPropertyNode_ptr _property;
+};
+
 #endif // __PROPS_HXX
 
 // end of props.hxx