engine/include/Utils/BindableVar.h

56 lines
720 B
C
Raw Permalink Normal View History

2013-01-19 20:02:34 +00:00
#ifndef BINDABLE_VAR_H_INCLUDED
#define BINDABLE_VAR_H_INCLUDED
2017-02-26 23:26:42 +00:00
#include "boost/signals2.hpp"
2013-01-19 20:02:34 +00:00
#include "boost/variant.hpp"
2017-02-26 23:26:42 +00:00
2013-01-19 20:02:34 +00:00
namespace SE
{
2017-02-26 23:26:42 +00:00
2013-01-19 20:02:34 +00:00
//Must be stored in shared_ptr:
template<typename TYPENAME>
class TBindableVar
{
protected:
TYPENAME Variable;
public:
2017-02-26 23:26:42 +00:00
boost::signals2::signal<void(const TYPENAME&)> OnVarChanged;
2013-01-19 20:02:34 +00:00
TBindableVar()
{
}
TBindableVar(const TYPENAME&& var)
: Variable(var)
{
}
operator TYPENAME()
{
return Variable;
}
TYPENAME operator()()
{
return Variable;
}
TBindableVar<TYPENAME>& operator=(const TYPENAME& var)
{
Variable = var;
OnVarChanged(Variable);
return *this;
}
};
} //namespace SE
#endif