]> git.tdb.fi Git - libs/gl.git/blobdiff - source/bindable.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / bindable.h
diff --git a/source/bindable.h b/source/bindable.h
deleted file mode 100644 (file)
index f534d7a..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-#ifndef MSP_GL_BINDABLE_H_
-#define MSP_GL_BINDABLE_H_
-
-namespace Msp {
-namespace GL {
-
-/**
-A helper class for single-point binding.  Provides tracking of the currently
-bound object.
-*/
-template<typename T>
-class Bindable
-{
-protected:
-       static const T *cur_obj;
-
-       Bindable() { }
-
-       static bool set_current(const T *obj)
-       {
-               if(obj==cur_obj)
-                       return false;
-
-               cur_obj = obj;
-               return true;
-       }
-
-public:
-       static const T *current() { return cur_obj; }
-};
-
-template<typename T>
-const T *Bindable<T>::cur_obj;
-
-
-/**
-A helper class for Bindables that revert to a default object on unbind.
-*/
-template<typename T>
-class BindableWithDefault: protected Bindable<T>
-{
-protected:
-       BindableWithDefault() { }
-
-public:
-       static const T *current()
-       {
-               if(!Bindable<T>::cur_obj)
-                       Bindable<T>::cur_obj = &default_object();
-               return Bindable<T>::cur_obj;
-       }
-
-       static void unbind()
-       {
-               default_object().bind();
-       }
-
-       static const T &default_object()
-       {
-               static T obj;
-               return obj;
-       }
-};
-
-
-/**
-RAII class for binding things.  Binds the thing upon construction and unbinds
-it upon destruction.  If a null pointer is given, unbinds upon construction and
-does nothing upon destruction.
-*/
-class Bind
-{
-private:
-       typedef void CleanupFunc();
-
-       CleanupFunc *cleanup;
-
-public:
-       template<typename T>
-       Bind(T *o) { init(o); }
-
-       template<typename T>
-       Bind(const T *o) { init(o); }
-
-       template<typename T>
-       Bind(const T &o) { init(&o); }
-
-private:
-       template<typename T>
-       void init(const T *o)
-       {
-               cleanup = (o ? &unbind<T> : 0);
-               if(o)
-                       o->bind();
-               else
-                       T::unbind();
-       }
-
-public:
-       ~Bind()
-       { if(cleanup) cleanup(); }
-
-private:
-       template<typename T>
-       static void unbind()
-       { T::unbind(); }
-};
-
-
-/**
-Similar to Bind, but restores previous binding upon destruction.
-*/
-class BindRestore
-{
-private:
-       typedef void CleanupFunc(const void *);
-
-       const void *old;
-       CleanupFunc *cleanup;
-
-public:
-       template<typename T>
-       BindRestore(T *o) { init(o); }
-
-       template<typename T>
-       BindRestore(const T *o) { init(o); }
-
-       template<typename T>
-       BindRestore(const T &o) { init(&o); }
-
-private:
-       template<typename T>
-       void init(T *o)
-       {
-               old = T::current();
-               cleanup = (o!=old ? &restore<T> : 0);
-               if(o)
-                       o->bind();
-               else if(old)
-                       T::unbind();
-       }
-
-public:
-       ~BindRestore()
-       { if(cleanup) cleanup(old); }
-
-private:
-       template<typename T>
-       static void restore(const void *o)
-       {
-               if(o)
-                       reinterpret_cast<const T *>(o)->bind();
-               else
-                       T::unbind();
-       }
-};
-
-} // namespace GL
-} // namespace Msp
-
-#endif