PolyBoRi
CCallbackWrapper.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //*****************************************************************************
15 //*****************************************************************************
16 
17 #ifndef polybori_ring_CCallback_Wrapper_h_
18 #define polybori_ring_CCallback_Wrapper_h_
19 
20 // include basic definitions
21 #include <polybori/pbori_defs.h>
22 #include "CMemberFunctionTraits.h"
23 
25 
39 template <class Type, class ResultType, class ArgType>
42 public:
43 
45  ResultType operator()(ArgType arg) const {
46  return (static_cast<const Type&>(*this).object .*
47  static_cast<const Type&>(*this).function)(arg);
48  }
49 };
50 
52 template <class Type, class ArgType>
53 class CCallbackFacade<Type, void, ArgType> {
54 public:
55 
57  void operator()(ArgType arg) const {
58  (static_cast<const Type&>(*this).object .*
59  static_cast<const Type&>(*this).function)(arg);
60  }
61 };
62 
71 template <class MemberFuncPtr>
73  public CCallbackFacade< CCallbackWrapper<MemberFuncPtr>,
74  typename CMemberFunctionTraits<MemberFuncPtr>::result_type,
75  typename CMemberFunctionTraits<MemberFuncPtr>::argument_type> {
77  typedef CCallbackWrapper self;
78 
79 public:
82 
84  friend class CCallbackFacade<self, typename traits::result_type,
85  typename traits::argument_type>;
87  typedef typename traits::object_reference reference;
88 
90  CCallbackWrapper(reference value, MemberFuncPtr ptr):
91  object(value), function(ptr) { }
92 
93 private:
94  reference object;
95  MemberFuncPtr function;
96 };
97 
99 
100 #endif
#define END_NAMESPACE_PBORI
Finish project's namespace.
Definition: pbori_defs.h:77
#define BEGIN_NAMESPACE_PBORI
Start project's namespace.
Definition: pbori_defs.h:74
traits::object_reference reference
Reference to object.
Definition: CCallbackWrapper.h:87
This template class defines a functional, which wraps operator .*, which is the callback of a dynamic...
Definition: CCallbackWrapper.h:72
void operator()(ArgType arg) const
Apply member function pointer to argument (avoid returning void())
Definition: CCallbackWrapper.h:57
Definition: embed.h:188
Variant for constant non-void member functions.
Definition: CCallbackWrapper.h:41
This template class defines related types for member function pointer.
Definition: CMemberFunctionTraits.h:33
CMemberFunctionTraits< MemberFuncPtr > traits
Related types.
Definition: CCallbackWrapper.h:81
ResultType operator()(ArgType arg) const
Apply member function pointer to argument.
Definition: CCallbackWrapper.h:45