16 #ifndef A_UTIL_UTIL_DELEGATE_DECL_HEADER_INCLUDED
17 #define A_UTIL_UTIL_DELEGATE_DECL_HEADER_INCLUDED
28 template <
typename ReturnType>
29 class DelegateInterface {
31 virtual ~DelegateInterface();
32 virtual ReturnType invoke() = 0;
33 virtual DelegateInterface<ReturnType>* clone() = 0;
36 template <
typename ReturnType>
37 class FunctionDelegate :
public DelegateInterface<ReturnType> {
38 typedef ReturnType (*Function)();
41 FunctionDelegate(Function f);
42 virtual ReturnType invoke();
43 virtual DelegateInterface<ReturnType>* clone();
49 template <
typename ReturnType,
typename Method,
typename Instance>
50 class MethodDelegate :
public DelegateInterface<ReturnType> {
52 MethodDelegate(Method method, Instance& instance);
53 virtual ReturnType invoke();
54 virtual DelegateInterface<ReturnType>* clone();
64 template <
typename ReturnType,
typename ParamType>
65 class DelegateInterface {
67 virtual ~DelegateInterface();
68 virtual ReturnType invoke(ParamType) = 0;
69 virtual DelegateInterface<ReturnType, ParamType>* clone() = 0;
72 template <
typename ReturnType,
typename ParamType>
73 class FunctionDelegate :
public DelegateInterface<ReturnType, ParamType> {
74 typedef ReturnType (*Function)(ParamType);
77 FunctionDelegate(Function f);
78 virtual ReturnType invoke(ParamType param);
79 virtual DelegateInterface<ReturnType, ParamType>* clone();
85 template <
typename ReturnType,
typename ParamType,
typename Method,
typename Instance>
86 class MethodDelegate :
public DelegateInterface<ReturnType, ParamType> {
88 MethodDelegate(Method method, Instance& inst);
89 virtual ReturnType invoke(ParamType param);
90 virtual DelegateInterface<ReturnType, ParamType>* clone();
100 template <
typename DelegateType>
105 DelegateBase(
const DelegateBase& other);
106 DelegateBase& operator=(
const DelegateBase& other);
108 void setDelegate(DelegateType* delegate);
109 DelegateType* getDelegate();
110 const DelegateType* getDelegate()
const;
113 operator bool()
const;
116 DelegateType* _ptr_to_callee;
122 namespace experimental {
127 template <
typename ReturnType>
129 :
public detail::DelegateBase<detail::delegates::DelegateInterface<ReturnType>> {
143 template <
typename Method,
typename Instance>
153 typedef detail::DelegateBase<detail::delegates::DelegateInterface<ReturnType>> Base;
161 template <
typename ReturnType,
typename ParamType>
163 :
public detail::DelegateBase<detail::functions::DelegateInterface<ReturnType, ParamType>> {
178 template <
typename Method,
typename Instance>
189 typedef detail::DelegateBase<detail::functions::DelegateInterface<ReturnType, ParamType>> Base;
General delegate template: encapsulates a function or a method without a parameter.
NullaryDelegate(ReturnType(*Function)())
CTOR to delegate a function.
ReturnType operator()()
Invocation operator - invokes the delegated method or function.
General function template: encapsulates a function or a method with a single parameter.
ReturnType operator()(ParamType param)
Invocation operator - invokes the delegated method or function.
UnaryDelegate(ReturnType(*Function)(ParamType))
CTOR to delegate an unary function.
Private implementation for NullaryDelegate and UnaryDelegate types.
Serves as the root component, with common functionality documented in core functionality.