X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2Ftiedpropertylist.hxx;h=f33478ac40768aee0ea60ddd4782cf70a69f5858;hb=04dc28cb3307a2d78b024f533011628dbe5e5a52;hp=0820d6b6e839024847332341afc7f21325680c4d;hpb=2ee87483f958ebf015855202df1dc2e91dd21cc7;p=simgear.git diff --git a/simgear/props/tiedpropertylist.hxx b/simgear/props/tiedpropertylist.hxx index 0820d6b6..f33478ac 100644 --- a/simgear/props/tiedpropertylist.hxx +++ b/simgear/props/tiedpropertylist.hxx @@ -21,7 +21,7 @@ #ifndef __TIEDPROPERTYLIST_HXX #define __TIEDPROPERTYLIST_HXX #include -using simgear::PropertyList; +#include 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 (size()>0) + { + SG_LOG(SG_GENERAL, SG_ALERT, "Detected properties with dangling ties. Use 'Untie' before removing a TiedPropertyList."); + // running debug mode: go, fix it! + assert(size() == 0); + } + } void setRoot( SGPropertyNode_ptr root ) { _root = root; } SGPropertyNode_ptr getRoot() const { return _root; } @@ -61,12 +71,20 @@ public: return Tie( _root->getNode(relative_path,true), SGRawValuePointer(value), useDefault ); } + template 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(value), useDefault ); + } + template SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) { return Tie(node, SGRawValueFunctions(getter, setter), useDefault ); } template SGPropertyNode_ptr Tie( const char * relative_path, V (*getter)(), void (*setter)(V) = 0, bool useDefault = true ) { - return Tie(_root->getNode(relative_path, true), SGRawValueFunctions(getter, setter), useDefault ); + return Tie(_root->getNode(relative_path,true), SGRawValueFunctions(getter, setter), useDefault ); + } + + template 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(getter, setter), useDefault ); } template 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(index, getter, setter), useDefault ); } + template 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(index, getter, setter), useDefault ); + } + template SGPropertyNode_ptr Tie( SGPropertyNode_ptr node, T * obj, V (T::*getter)() const, void (T::*setter)(V) = 0, bool useDefault = true) { return Tie( node, SGRawValueMethods(*obj, getter, setter), useDefault ); } @@ -85,6 +107,10 @@ public: return Tie( _root->getNode( relative_path, true), SGRawValueMethods(*obj, getter, setter), useDefault ); } + template 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(*obj, getter, setter), useDefault ); + } + template 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(*obj, index, getter, setter), useDefault); } @@ -93,6 +119,10 @@ public: return Tie( _root->getNode( relative_path, true ), SGRawValueMethodsIndexed(*obj, index, getter, setter), useDefault); } + template 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(*obj, index, getter, setter), useDefault); + } + void Untie() { while( size() > 0 ) { SG_LOG( SG_ALL, SG_INFO, "untie of " << back()->getPath() );