1 #ifndef MSP_GL_BINDABLE_H_
2 #define MSP_GL_BINDABLE_H_
8 A helper class for single-point binding. Provides tracking of the currently
15 static const T *cur_obj;
19 static bool set_current(const T *obj)
29 static const T *current() { return cur_obj; }
33 const T *Bindable<T>::cur_obj;
37 RAII class for binding things. Binds the thing upon construction and unbinds
38 it upon destruction. If a null pointer is given, unbinds upon construction and
39 does nothing upon destruction. Optionally can restore the previous binding.
70 template<typename T, typename U>
76 Binder2(const T *o, const U *l):
99 Bind(const T &o, bool r = false):
100 binder(r ? create(&o, T::current()) : create(&o))
104 Bind(const T *o, bool r = false):
105 binder(r ? create(o, T::current()) : create(o))
109 Bind(T *o, bool r = false):
110 binder(r ? create(o, T::current()) : create(o))
115 Bind &operator=(const Bind &);
118 ~Bind() { delete binder; }
122 Base *create(const T *o)
123 { return new Binder1<T>(o); }
125 template<typename T, typename U>
126 Base *create(const T *o, const U *l)
127 { return new Binder2<T, U>(o, l); }