CMemberFunctionTraits.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_ring_CMemberFunctionTraits_h_
#define polybori_ring_CMemberFunctionTraits_h_
// include basic definitions
#include <polybori/pbori_defs.h>
BEGIN_NAMESPACE_PBORI
template<class MemberFuncPtr>
class CMemberFunctionTraits;
template <class Type, class ResultType, class ArgType, class ObjRef>
class CMemberFunctionTraitsBase {
public:
typedef ResultType result_type;
typedef ArgType argument_type;
typedef Type object_type;
typedef ObjRef object_reference;
};
template <class Type, class ResultType>
class CMemberFunctionTraits<ResultType (Type::*)()>:
public CMemberFunctionTraitsBase<Type, ResultType, void, Type&> { };
template <class Type, class ResultType>
class CMemberFunctionTraits<ResultType (Type::*)() const>:
public CMemberFunctionTraitsBase<Type, ResultType, void, const Type&> { };
template <class Type, class ResultType, class ArgType>
class CMemberFunctionTraits<ResultType (Type::*)(ArgType)>:
public CMemberFunctionTraitsBase<Type, ResultType, ArgType, Type&> { };
template <class Type, class ResultType, class ArgType>
class CMemberFunctionTraits<ResultType (Type::*)(ArgType) const>:
public CMemberFunctionTraitsBase<Type, ResultType, ArgType, const Type&> { };
template <class MemberFct>
class MemberFunctionOperator {
typedef CMemberFunctionTraits<MemberFct> traits;
public:
MemberFunctionOperator(MemberFct func): m_func(func) {}
typename traits::result_type operator()(typename traits::object_reference obj,
typename traits::argument_type arg) {
return (obj .* m_func)(arg);
}
private:
MemberFct m_func;
};
template <class MemberFct>
MemberFunctionOperator<MemberFct>
member_function_operator(MemberFct func) {
return MemberFunctionOperator<MemberFct>(func);
}
END_NAMESPACE_PBORI
#endif
polybori::CMemberFunctionTraitsBase
Axuiliary class.
Definition: CMemberFunctionTraits.h:37
END_NAMESPACE_PBORI
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
BEGIN_NAMESPACE_PBORI
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
polybori::CMemberFunctionTraitsBase::argument_type
ArgType argument_type
Definition: CMemberFunctionTraits.h:40
polybori::CMemberFunctionTraitsBase::object_type
Type object_type
Definition: CMemberFunctionTraits.h:41
pbori_defs.h
polybori::MemberFunctionOperator::operator()
traits::result_type operator()(typename traits::object_reference obj, typename traits::argument_type arg)
Definition: CMemberFunctionTraits.h:71
polybori::CMemberFunctionTraits
This template class defines related types for member function pointer.
Definition: CMemberFunctionTraits.h:33
polybori::CMemberFunctionTraitsBase::object_reference
ObjRef object_reference
Definition: CMemberFunctionTraits.h:42
polybori::member_function_operator
MemberFunctionOperator< MemberFct > member_function_operator(MemberFct func)
Definition: CMemberFunctionTraits.h:83
polybori::MemberFunctionOperator
Definition: CMemberFunctionTraits.h:65
polybori::MemberFunctionOperator::MemberFunctionOperator
MemberFunctionOperator(MemberFct func)
Definition: CMemberFunctionTraits.h:69
polybori::CMemberFunctionTraitsBase::result_type
ResultType result_type
Definition: CMemberFunctionTraits.h:39