Dependencies:   mbed

Dependents:   HvZ

handler.hpp

Committer:
etherealflaim
Date:
2010-11-30
Revision:
0:86ff0a55c978

File content as of revision 0:86ff0a55c978:

template <class Result>
class handler
{
public:
  virtual inline Result operator() () const {};
};

template <class Result>
class function_handler
: public handler <Result>
{
protected:
  Result (*pfunc)();
public:
  explicit inline function_handler ( Result (*f)() ) : pfunc (f) {}
  virtual inline Result operator() () const { return pfunc(); }
};

template <class Type, class Result>
class member_handler
: public handler <Result>
{
protected:
  Type *inst;
  Result (Type::*pfunc)();
public:
  explicit inline member_handler ( Type *i, Result (Type::*f)() ) : inst(i), pfunc (f) {}
  virtual inline Result operator() () const { return (inst->*pfunc)(); }
};