CCallbackWrapper.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_ring_CCallback_Wrapper_h_
#define polybori_ring_CCallback_Wrapper_h_
// include basic definitions
#include <polybori/pbori_defs.h>
#include "CMemberFunctionTraits.h"
BEGIN_NAMESPACE_PBORI
template <class Type, class ResultType, class ArgType>
class CCallbackFacade {
public:
ResultType operator()(ArgType arg) const {
return (static_cast<const Type&>(*this).object .*
static_cast<const Type&>(*this).function)(arg);
}
};
template <class Type, class ArgType>
class CCallbackFacade<Type, void, ArgType> {
public:
void operator()(ArgType arg) const {
(static_cast<const Type&>(*this).object .*
static_cast<const Type&>(*this).function)(arg);
}
};
template <class MemberFuncPtr>
class CCallbackWrapper:
public CCallbackFacade< CCallbackWrapper<MemberFuncPtr>,
typename CMemberFunctionTraits<MemberFuncPtr>::result_type,
typename CMemberFunctionTraits<MemberFuncPtr>::argument_type> {
typedef CCallbackWrapper self;
public:
typedef CMemberFunctionTraits<MemberFuncPtr> traits;
friend class CCallbackFacade<self, typename traits::result_type,
typename traits::argument_type>;
typedef typename traits::object_reference reference;
CCallbackWrapper(reference value, MemberFuncPtr ptr):
object(value), function(ptr) { }
private:
reference object;
MemberFuncPtr function;
};
END_NAMESPACE_PBORI
#endif