]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/tiedpropertylist.hxx
Fixed a crash: the singleton needs to be instantiated the first time SGCommandMgr...
[simgear.git] / simgear / props / tiedpropertylist.hxx
index 0820d6b6e839024847332341afc7f21325680c4d..39461afd5f836499478f4cd0a8d81cb0b32b3194 100644 (file)
@@ -21,7 +21,7 @@
 #ifndef __TIEDPROPERTYLIST_HXX
 #define  __TIEDPROPERTYLIST_HXX
 #include <simgear/props/props.hxx>
-using simgear::PropertyList;
+#include <assert.h>
 
 namespace simgear {
 
@@ -30,10 +30,20 @@ namespace simgear {
  * This helper class keeps track of tied properties and unties
  * each tied property when this class gets destructed.
 */
-class TiedPropertyList : PropertyList {
+class TiedPropertyList : simgear::PropertyList {
 public:
     TiedPropertyList() {}
     TiedPropertyList( SGPropertyNode_ptr root ) : _root(root) {}
+    virtual ~TiedPropertyList()
+    { 
+        _root = 0;
+        if (! empty())
+        {
+            SG_LOG(SG_GENERAL, SG_ALERT, "Detected properties with dangling ties. Use 'Untie' before removing a TiedPropertyList.");
+            // running debug mode: go, fix it!
+            assert(empty());
+        }
+    }
 
     void setRoot( SGPropertyNode_ptr root ) { _root = root; }
     SGPropertyNode_ptr getRoot() const { return _root; }
@@ -41,7 +51,7 @@ public:
     template<typename T> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, const SGRawValue<T> &rawValue, bool useDefault = true  ) {
         bool success = node->tie( rawValue, useDefault );
         if( success ) {
-            SG_LOG( SG_ALL, SG_INFO, "Tied " << node->getPath() );
+            SG_LOG( SG_GENERAL, SG_DEBUG, "Tied " << node->getPath() );
             push_back( node );
         } else {
 #if PROPS_STANDALONE
@@ -61,12 +71,20 @@ public:
         return Tie( _root->getNode(relative_path,true), SGRawValuePointer<V>(value), useDefault );
     }
 
+    template <class V> SGPropertyNode_ptr Tie( const char * relative_path, int prop_index, V * value, bool useDefault = true ) {
+        return Tie( _root->getNode(relative_path,prop_index,true), SGRawValuePointer<V>(value), useDefault );
+    }
+
     template <class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) {
         return Tie(node, SGRawValueFunctions<V>(getter, setter), useDefault );
     }
 
     template <class V> SGPropertyNode_ptr Tie( const char * relative_path, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) {
-        return Tie(_root->getNode(relative_path, true), SGRawValueFunctions<V>(getter, setter), useDefault );
+        return Tie(_root->getNode(relative_path,true), SGRawValueFunctions<V>(getter, setter), useDefault );
+    }
+
+    template <class V> SGPropertyNode_ptr Tie( const char * relative_path, int prop_index, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) {
+        return Tie(_root->getNode(relative_path,prop_index,true), SGRawValueFunctions<V>(getter, setter), useDefault );
     }
 
     template <class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, int index, V (*getter)(int), void (*setter)(int, V) = 0, bool useDefault = true) {
@@ -77,6 +95,10 @@ public:
         return Tie( _root->getNode( relative_path, true ), SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault );
     }
 
+    template <class V> SGPropertyNode_ptr Tie( const char * relative_path, int prop_index, int index, V (*getter)(int), void (*setter)(int, V) = 0, bool useDefault = true) {
+        return Tie( _root->getNode( relative_path,prop_index,true ), SGRawValueFunctionsIndexed<V>(index, getter, setter), useDefault );
+    }
+
     template <class T, class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true) {
         return Tie( node, SGRawValueMethods<T,V>(*obj, getter, setter), useDefault );
     }
@@ -85,6 +107,10 @@ public:
         return Tie( _root->getNode( relative_path, true), SGRawValueMethods<T,V>(*obj, getter, setter), useDefault );
     }
 
+    template <class T, class V> SGPropertyNode_ptr Tie( const char * relative_path, int prop_index, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true) {
+        return Tie( _root->getNode( relative_path,prop_index,true), SGRawValueMethods<T,V>(*obj, getter, setter), useDefault );
+    }
+
     template <class T, class V> SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, T * obj, int index, V (T::*getter)(int) const, void (T::*setter)(int, V) = 0, bool useDefault = true) {
         return Tie( node, SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault);
     }
@@ -93,13 +119,23 @@ public:
         return Tie( _root->getNode( relative_path, true ), SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault);
     }
 
+    template <class T, class V> SGPropertyNode_ptr Tie( const char * relative_path, int prop_index, T * obj, int index, V (T::*getter)(int) const, void (T::*setter)(int, V) = 0, bool useDefault = true) {
+        return Tie( _root->getNode( relative_path,prop_index,true ), SGRawValueMethodsIndexed<T,V>(*obj, index, getter, setter), useDefault);
+    }
+
     void Untie() {
-        while( size() > 0 ) {
-            SG_LOG( SG_ALL, SG_INFO, "untie of " << back()->getPath() );
+        while( ! empty() ) {
+            SG_LOG( SG_GENERAL, SG_DEBUG, "untie of " << back()->getPath() );
             back()->untie();
             pop_back();
         }
     }
+
+    void setAttribute (SGPropertyNode::Attribute attr, bool state)
+    {
+        for (std::vector<SGPropertyNode_ptr>::iterator it=begin() ; it < end(); it++ )
+           (*it)->setAttribute(attr, state);
+    }
 private:
     SGPropertyNode_ptr _root;
 };