]> git.tdb.fi Git - libs/gl.git/blobdiff - source/bindable.h
Make Animation::Iterator assignable
[libs/gl.git] / source / bindable.h
index 8a5821b957cf4dd1569e3e840d6ad2ee8207e5ed..b2634ea92bd4b1b43bb1f88b502af230f1e3c4bd 100644 (file)
@@ -15,6 +15,7 @@ protected:
        static const T *cur_obj;
 
        Bindable() { }
+       ~Bindable() { if(cur_obj==this) T::unbind(); }
 
        static bool set_current(const T *obj)
        {
@@ -39,8 +40,11 @@ A helper class for Bindables that revert to a default object on unbind.
 template<typename T>
 class BindableWithDefault: protected Bindable<T>
 {
+       friend class Bindable<T>;
+
 protected:
        BindableWithDefault() { }
+       ~BindableWithDefault() { if(this==&default_object()) Bindable<T>::set_current(0); }
 
 public:
        static const T *current()
@@ -52,7 +56,8 @@ public:
 
        static void unbind()
        {
-               default_object().bind();
+               if(Bindable<T>::cur_obj)
+                       default_object().bind();
        }
 
        static const T &default_object()