00001
00002
00017
00018
00019 #ifndef polybori_ring_CMemberFunctionTraits_h_
00020 #define polybori_ring_CMemberFunctionTraits_h_
00021
00022
00023 #include <polybori/pbori_defs.h>
00024
00025 BEGIN_NAMESPACE_PBORI
00026
00032 template<class MemberFuncPtr>
00033 class CMemberFunctionTraits;
00034
00036 template <class Type, class ResultType, class ArgType, class ObjRef>
00037 class CMemberFunctionTraitsBase {
00038 public:
00039 typedef ResultType result_type;
00040 typedef ArgType argument_type;
00041 typedef Type object_type;
00042 typedef ObjRef object_reference;
00043 };
00044
00045
00046 template <class Type, class ResultType>
00047 class CMemberFunctionTraits<ResultType (Type::*)()>:
00048 public CMemberFunctionTraitsBase<Type, ResultType, void, Type&> { };
00049
00050 template <class Type, class ResultType>
00051 class CMemberFunctionTraits<ResultType (Type::*)() const>:
00052 public CMemberFunctionTraitsBase<Type, ResultType, void, const Type&> { };
00053
00054 template <class Type, class ResultType, class ArgType>
00055 class CMemberFunctionTraits<ResultType (Type::*)(ArgType)>:
00056 public CMemberFunctionTraitsBase<Type, ResultType, ArgType, Type&> { };
00057
00058
00059 template <class Type, class ResultType, class ArgType>
00060 class CMemberFunctionTraits<ResultType (Type::*)(ArgType) const>:
00061 public CMemberFunctionTraitsBase<Type, ResultType, ArgType, const Type&> { };
00062
00063
00064 template <class MemberFct>
00065 class MemberFunctionOperator {
00066 typedef CMemberFunctionTraits<MemberFct> traits;
00067
00068 public:
00069 MemberFunctionOperator(MemberFct func): m_func(func) {}
00070
00071 typename traits::result_type operator()(typename traits::object_reference obj,
00072 typename traits::argument_type arg) {
00073 return (obj .* m_func)(arg);
00074 }
00075
00076 private:
00077 MemberFct m_func;
00078 };
00079
00080
00081 template <class MemberFct>
00082 MemberFunctionOperator<MemberFct>
00083 member_function_operator(MemberFct func) {
00084 return MemberFunctionOperator<MemberFct>(func);
00085 }
00086
00087 END_NAMESPACE_PBORI
00088
00089 #endif