X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbindable.h;h=b2634ea92bd4b1b43bb1f88b502af230f1e3c4bd;hp=cd012fbbcef3d50b984a6dafbace86f49ce7f433;hb=HEAD;hpb=f17794d55923d4fb4f63e9d082d8d84a735a04e8 diff --git a/source/bindable.h b/source/bindable.h deleted file mode 100644 index cd012fbb..00000000 --- a/source/bindable.h +++ /dev/null @@ -1,81 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2010 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifndef MSP_GL_BINDABLE_H_ -#define MSP_GL_BINDABLE_H_ - -namespace Msp { -namespace GL { - -template -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: - const T *current() const { return cur_obj; } -}; - -template -const T *Bindable::cur_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: - struct Base - { - virtual ~Base() { } - }; - - template - struct Binder: Base - { - const T &obj; - - Binder(const T &o): obj(o) { obj.bind(); } - ~Binder() { obj.unbind(); } - }; - - Base *binder; - -public: - template - Bind(const T &o): binder(new Binder(o)) { } - - template - Bind(const T *o): binder(o ? new Binder(*o) : 0) { if(!o) T::unbind(); } - -private: - Bind(const Bind &); - Bind &operator=(const Bind &); - -public: - ~Bind() { delete binder; } -}; - -} // namespace GL -} // namespace Msp - -#endif