1 #ifndef MSP_GL_BINDABLE_H_
2 #define MSP_GL_BINDABLE_H_
11 static const T *cur_obj;
15 static bool set_current(const T *obj)
25 static const T *current() { return cur_obj; }
29 const T *Bindable<T>::cur_obj;
33 RAII class for binding things. Binds the thing upon construction and unbinds
34 it upon destruction. If a null pointer is given, unbinds upon construction and
35 does nothing upon destruction. Optionally can restore the previous binding.
66 template<typename T, typename U>
72 Binder2(const T *o, const U *l):
95 Bind(const T &o, bool r = false):
96 binder(r ? create(&o, T::current()) : create(&o))
100 Bind(const T *o, bool r = false):
101 binder(r ? create(o, T::current()) : create(o))
105 Bind(T *o, bool r = false):
106 binder(r ? create(o, T::current()) : create(o))
111 Bind &operator=(const Bind &);
114 ~Bind() { delete binder; }
118 Base *create(const T *o)
119 { return new Binder1<T>(o); }
121 template<typename T, typename U>
122 Base *create(const T *o, const U *l)
123 { return new Binder2<T, U>(o, l); }