00001
00002
00015
00016
00017 #ifndef polybori_ring_CCallback_Wrapper_h_
00018 #define polybori_ring_CCallback_Wrapper_h_
00019
00020
00021 #include <polybori/pbori_defs.h>
00022 #include "CMemberFunctionTraits.h"
00023
00024 BEGIN_NAMESPACE_PBORI
00025
00039
00040 template <class Type, class ResultType, class ArgType>
00041 class CCallbackFacade {
00042 public:
00043
00045 ResultType operator()(ArgType arg) const {
00046 return (static_cast<const Type&>(*this).object .*
00047 static_cast<const Type&>(*this).function)(arg);
00048 }
00049 };
00050
00052 template <class Type, class ArgType>
00053 class CCallbackFacade<Type, void, ArgType> {
00054 public:
00055
00057 void operator()(ArgType arg) const {
00058 (static_cast<const Type&>(*this).object .*
00059 static_cast<const Type&>(*this).function)(arg);
00060 }
00061 };
00062
00071 template <class MemberFuncPtr>
00072 class CCallbackWrapper:
00073 public CCallbackFacade< CCallbackWrapper<MemberFuncPtr>,
00074 typename CMemberFunctionTraits<MemberFuncPtr>::result_type,
00075 typename CMemberFunctionTraits<MemberFuncPtr>::argument_type> {
00077 typedef CCallbackWrapper self;
00078
00079 public:
00081 typedef CMemberFunctionTraits<MemberFuncPtr> traits;
00082
00084 friend class CCallbackFacade<self, typename traits::result_type,
00085 typename traits::argument_type>;
00087 typedef typename traits::object_reference reference;
00088
00090 CCallbackWrapper(reference value, MemberFuncPtr ptr):
00091 object(value), function(ptr) { }
00092
00093 private:
00094 reference object;
00095 MemberFuncPtr function;
00096 };
00097
00098 END_NAMESPACE_PBORI
00099
00100 #endif