static const T *cur_obj;
Bindable() { }
+ ~Bindable() { if(cur_obj==this) T::unbind(); }
static bool set_current(const T *obj)
{
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()
static void unbind()
{
- default_object().bind();
+ if(Bindable<T>::cur_obj)
+ default_object().bind();
}
static const T &default_object()
template<typename T>
void init(const T *o)
{
- cleanup = (o ? &unbind<T> : 0);
+ cleanup = (o ? static_cast<CleanupFunc *>(&unbind<T>) : 0);
slot = 0;
if(o)
o->bind();
template<typename T, typename S>
void init(const T *o, S s)
{
- cleanup = (o ? &unbind_from<T, S> : 0);
+ cleanup = (o ? static_cast<CleanupFunc *>(&unbind_from<T, S>) : 0);
slot = s;
if(o)
o->bind_to(s);
{
old = T::current();
slot = 0;
- cleanup = (o!=old ? &restore<T> : 0);
+ cleanup = (o!=old ? static_cast<CleanupFunc *>(&restore<T>) : 0);
if(o)
o->bind();
else if(old)
{
old = T::current(s);
slot = s;
- cleanup = (o!=old ? &restore_to<T, S> : 0);
+ cleanup = (o!=old ? static_cast<CleanupFunc *>(&restore_to<T, S>) : 0);
if(o)
o->bind_to(s);
else if(old)