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 
40 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