EasyDelegate  2.0
Delegate and deferred callers for C++11.
deferredcallers.hpp
Go to the documentation of this file.
1 
13 #ifndef EASYDELEGATE_NO_DEFERRED_CALLING
14 #ifndef _INCLUDE_EASYDELEGATE_DEFERREDCALLERS_HPP_
15 #define _INCLUDE_EASYDELEGATE_DEFERREDCALLERS_HPP_
16 
17 #include <assert.h> // assert(expr)
18 #include <tuple> // std::tuple
19 
20 namespace EasyDelegate
21 {
29  {
30  // Public Methods
31  public:
35  EASYDELEGATE_INLINE virtual void genericDispatch(void) const = 0;
36 
44  EASYDELEGATE_INLINE virtual bool hasThisPointer(const void* thisPointer) const noexcept { return false; }
45  };
46 
52  template <typename returnType>
54  {
55  // Public Methods
56  public:
62  EASYDELEGATE_INLINE virtual returnType dispatch(void) const = 0;
63  };
64 
65  template <typename className, typename returnType, typename... parameters>
67 
75  template <typename returnType, typename... parameters>
76  class DeferredStaticCaller : public ITypedDeferredCaller<returnType>
77  {
78  // Public Methods
79  public:
81  typedef returnType(*StaticDelegateMethodPointer)(parameters...);
82 
88  DeferredStaticCaller(const StaticDelegateMethodPointer methodPointer, parameters... params) :
89  mParameters(params...), mMethodPointer(methodPointer) { }
90 
99  EASYDELEGATE_INLINE returnType dispatch(void) const
100  {
101  assert(mMethodPointer);
102 
103  if (!mMethodPointer)
105 
106  return performCachedCall(typename gens<sizeof...(parameters)>::type());
107  }
108 
116 
123  EASYDELEGATE_INLINE bool callsMethod(const StaticDelegateMethodPointer methodPointer) const noexcept { return mMethodPointer == methodPointer; }
124 
132  template <typename otherReturn, typename... otherParams>
133  EASYDELEGATE_INLINE bool callsMethod(const StaticMethodPointer<otherReturn, otherParams...> methodPointer) const noexcept { return false; }
134 
142  template <typename otherClass, typename otherReturn, typename... otherParams>
143  EASYDELEGATE_INLINE bool callsMethod(const MemberMethodPointer<otherClass, otherReturn, otherParams...> methodPointer) const noexcept { return false; }
144 
152  EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredStaticCaller<returnType, parameters...>* other) const noexcept { return mMethodPointer == other->mMethodPointer; }
153 
161  template <typename otherClass, typename otherReturn, typename... otherParams>
163 
171  template <typename otherReturn, typename... otherParams>
173 
181  EASYDELEGATE_INLINE bool hasThisPointer(const void* thisPointer) const noexcept { return false; }
182 
191  template <typename otherClass, typename otherReturn, typename... otherParams>
192  EASYDELEGATE_INLINE bool hasSameThisPointerAs(const IDeferredCaller* other) const noexcept { return false; }
193 
194  // Private Methods
195  private:
197  template<int ...S>
198  EASYDELEGATE_INLINE EASYDELEGATE_CONSTEXPR returnType performCachedCall(seq<S...>) const
199  {
200  return (mMethodPointer)(std::get<S>(mParameters) ...);
201  }
202 
204  const StaticDelegateMethodPointer mMethodPointer;
206  const NoReferenceTuple<parameters...> mParameters;
207  };
208 
218  template <typename classType, typename returnType, typename... parameters>
219  class DeferredMemberCaller : public ITypedDeferredCaller<returnType>
220  {
221  // Public Methods
222  public:
224  typedef MemberMethodPointer<classType, returnType, parameters...> MemberDelegateMethodPointer;
225 
237  DeferredMemberCaller(const MemberDelegateMethodPointer methodPointer, classType* thisPointer, parameters... params) :
238  mThisPointer(thisPointer), mParameters(params...), mMethodPointer(methodPointer) { }
239 
248  EASYDELEGATE_INLINE returnType dispatch(void) const
249  {
250  assert(mThisPointer);
251  assert(mMethodPointer);
252 
253  if (!mThisPointer)
255 
256  if (!mMethodPointer)
258 
259  return performCachedCall(typename gens<sizeof...(parameters)>::type());
260  }
261 
269 
275  EASYDELEGATE_INLINE bool callsMethod(const MemberDelegateMethodPointer methodPointer) const noexcept { return methodPointer == mMethodPointer; }
276 
285  template <typename otherClass, typename otherReturn, typename... otherParams>
286  EASYDELEGATE_INLINE bool callsMethod(const MemberMethodPointer<otherClass, otherReturn, otherParams...> methodPointer) const noexcept { return false; }
287 
294  template <typename otherReturn, typename... otherParams>
295  EASYDELEGATE_INLINE bool callsMethod(const StaticMethodPointer<otherReturn, otherParams...> methodPointer) const noexcept { return false; }
296 
304  EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredMemberCaller<classType, returnType, parameters...>* other) const noexcept { return mMethodPointer == other->mMethodPointer; }
305 
315  template <typename otherClass, typename otherReturn, typename... otherParams>
317 
325  template <typename otherReturn, typename... otherParams>
327 
333  template <typename otherClass, typename otherReturn, typename... otherParams>
334  EASYDELEGATE_INLINE bool hasSameThisPointerAs(const DeferredMemberCaller<otherClass, otherReturn, otherParams...>* other) const noexcept { return reinterpret_cast<void*>(mThisPointer) == reinterpret_cast<void*>(other->mThisPointer); }
335 
343  template <typename otherReturn, typename... otherParams>
345 
352  EASYDELEGATE_INLINE bool hasThisPointer(const void* thisPointer) const noexcept { return reinterpret_cast<const void*>(mThisPointer) == reinterpret_cast<const void*>(thisPointer); }
353 
354  // Public Members
355  public:
357  classType* mThisPointer;
358 
359  // Private Methods
360  private:
362  template<int ...S>
363  EASYDELEGATE_INLINE EASYDELEGATE_CONSTEXPR returnType performCachedCall(seq<S...>) const
364  {
365  assert(mThisPointer);
366 
367  if (!mThisPointer)
369 
370  return (mThisPointer->*mMethodPointer)(std::get<S>(mParameters) ...);
371  }
372 
373  // Private Members
374  private:
376  const MemberDelegateMethodPointer mMethodPointer;
377 
379  const NoReferenceTuple<parameters...> mParameters;
380  };
381 } // End NameSpace EasyDelegate
382 #endif // _INCLUDE_EASYDELEGATE_DEFERREDCALLERS_HPP_
383 #endif // EASYDELEGATE_NO_DEFERRED_CALLING
EASYDELEGATE_INLINE bool callsMethod(const StaticDelegateMethodPointer methodPointer) const noexcept
Returns whether or not this DeferredStaticCaller calls the given static method address.
Definition: deferredcallers.hpp:123
returnType(* StaticDelegateMethodPointer)(parameters...)
Helper typedef referring to a static function pointer.
Definition: deferredcallers.hpp:81
returnType(className::*)(parameters...) MemberMethodPointer
Helper typedef to a pointer of a class member method with the given signature.
Definition: types.hpp:69
#define EASYDELEGATE_CONSTEXPR
A macro that is used to declare constexpr to something that is compatible with the compiler...
Definition: easydelegate.hpp:25
EASYDELEGATE_INLINE returnType dispatch(void) const
Dispatches the DeferredStaticCaller.
Definition: deferredcallers.hpp:99
EASYDELEGATE_INLINE bool callsMethod(const MemberMethodPointer< otherClass, otherReturn, otherParams...> methodPointer) const noexcept
Returns whether or not this DeferredStaticCaller calls the given class member method address...
Definition: deferredcallers.hpp:143
returnType(*)(parameters...) StaticMethodPointer
Helper typedef to a pointer of a static method with the given signature.
Definition: types.hpp:65
An exception type that is thrown by the EasyDelegate library when any delegate type has attempted to ...
Definition: exceptions.hpp:51
virtual EASYDELEGATE_INLINE void genericDispatch(void) const =0
Invoke the deferred caller and ignore the return value.
classType * mThisPointer
A pointer to the this object to invoke against.
Definition: deferredcallers.hpp:357
EASYDELEGATE_INLINE bool hasThisPointer(const void *thisPointer) const noexcept
Returns whether or not this DeferredStaticCaller calls against the given this pointer.
Definition: deferredcallers.hpp:181
MemberMethodPointer< classType, returnType, parameters...> MemberDelegateMethodPointer
Helper typedef referring to a class member method pointer.
Definition: deferredcallers.hpp:224
Namespace containing all EasyDelegate functionality.
Definition: deferredcallers.hpp:20
DeferredStaticCaller(const StaticDelegateMethodPointer methodPointer, parameters...params)
Constructor accepting a pointer to a static method.
Definition: deferredcallers.hpp:88
DeferredMemberCaller(const MemberDelegateMethodPointer methodPointer, classType *thisPointer, parameters...params)
Constructor accepting a this pointer and a member method.
Definition: deferredcallers.hpp:237
#define EASYDELEGATE_INLINE
A preprocessor definition for a keyword that forces the inlining of a given method.
Definition: easydelegate.hpp:33
EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredStaticCaller< returnType, parameters...> *other) const noexcept
Returns whether or not this DeferredStaticCaller calls the same method as the specified DeferredStati...
Definition: deferredcallers.hpp:152
EASYDELEGATE_INLINE void genericDispatch(void) const
Dispatches the DeferredMemberCaller, ignoring the return value.
Definition: deferredcallers.hpp:268
EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredStaticCaller< otherReturn, otherParams...> *other) const noexcept
Returns whether or not this DeferredMemberCaller calls the same method as DeferredStaticCaller.
Definition: deferredcallers.hpp:326
EASYDELEGATE_INLINE bool callsMethod(const StaticMethodPointer< otherReturn, otherParams...> methodPointer) const noexcept
Returns whether or not this DeferredStaticCaller calls the given static method address of a differing...
Definition: deferredcallers.hpp:133
std::tuple< typename std::remove_reference< typenames >::type...> NoReferenceTuple
A helper typedef for an std::tuple that removes the reference from referenced types.
Definition: types.hpp:60
EASYDELEGATE_INLINE bool callsMethod(const MemberMethodPointer< otherClass, otherReturn, otherParams...> methodPointer) const noexcept
Returns whether or not this DeferredMemberCaller calls the given class member method of a differing s...
Definition: deferredcallers.hpp:286
EASYDELEGATE_INLINE bool hasSameThisPointerAs(const DeferredStaticCaller< otherReturn, otherParams...> *other) const noexcept
Returns whether or not this DeferredMemberCaller calls against the same this pointer of the DeferredS...
Definition: deferredcallers.hpp:344
The most generic of the deferred caller types. All deferred callers eventually trace back to this cla...
Definition: deferredcallers.hpp:28
EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredMemberCaller< otherClass, otherReturn, otherParams...> *other) const noexcept
Returns whether or not this DeferredMemberCaller calls the same method as another DeferredMemberCalle...
Definition: deferredcallers.hpp:316
EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredMemberCaller< otherClass, otherReturn, otherParams...> *other) const noexcept
Returns whether or not this DeferredStaticCaller calls the same method as the specified DeferredMembe...
Definition: deferredcallers.hpp:162
A deferred caller type for class member methods.
Definition: deferredcallers.hpp:66
EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredStaticCaller< otherReturn, otherParams...> *other) const noexcept
Returns whether or not this DeferredStaticCaller calls the same of the given DeferredStaticCaller of ...
Definition: deferredcallers.hpp:172
EASYDELEGATE_INLINE bool callsMethod(const StaticMethodPointer< otherReturn, otherParams...> methodPointer) const noexcept
Returns whether or not this DeferredMemberCaller calls the given static method.
Definition: deferredcallers.hpp:295
EASYDELEGATE_INLINE returnType dispatch(void) const
Dispatches the DeferredMemberCaller.
Definition: deferredcallers.hpp:248
EASYDELEGATE_INLINE bool callsMethod(const MemberDelegateMethodPointer methodPointer) const noexcept
Returns whether or not this DeferredMemberCaller calls the given class member method.
Definition: deferredcallers.hpp:275
virtual EASYDELEGATE_INLINE bool hasThisPointer(const void *thisPointer) const noexcept
Returns whether or not this deferred caller calls against the given this pointer. ...
Definition: deferredcallers.hpp:44
EASYDELEGATE_INLINE bool hasSameThisPointerAs(const IDeferredCaller *other) const noexcept
Returns whether or not this DeferredStaticCaller shares the same this pointer as the given IDeferredC...
Definition: deferredcallers.hpp:192
An exception type that is thrown by the EasyDelegate library when a member delegate type has attempte...
Definition: exceptions.hpp:31
EASYDELEGATE_INLINE void genericDispatch(void) const
Dispatches the DeferredStaticCaller, ignoring the return value.
Definition: deferredcallers.hpp:115
A less generic deferred caller type that retains return type information. Use this if you don't care ...
Definition: deferredcallers.hpp:53
EASYDELEGATE_INLINE bool hasThisPointer(const void *thisPointer) const noexcept
Returns whether or not this DeferredMemberCaller calls against the given this pointer.
Definition: deferredcallers.hpp:352
virtual EASYDELEGATE_INLINE returnType dispatch(void) const =0
Invoke the deferred caller and return the result to the calling method.
A deferred caller type for static methods.
Definition: deferredcallers.hpp:76
EASYDELEGATE_INLINE bool hasSameMethodAs(const DeferredMemberCaller< classType, returnType, parameters...> *other) const noexcept
Returns whether or not this DeferredMemberCaller calls the same method as another DeferredMemberCalle...
Definition: deferredcallers.hpp:304
EASYDELEGATE_INLINE bool hasSameThisPointerAs(const DeferredMemberCaller< otherClass, otherReturn, otherParams...> *other) const noexcept
Returns whether or not this DeferredMemberCaller calls against the same this pointer as another...
Definition: deferredcallers.hpp:334