16#ifndef A_UTIL_UTIL_DELEGATE_IMPL_HEADER_INCLUDED
17#define A_UTIL_UTIL_DELEGATE_IMPL_HEADER_INCLUDED
26template <
typename ReturnType>
27inline DelegateInterface<ReturnType>::~DelegateInterface()
31template <
typename ReturnType>
32inline FunctionDelegate<ReturnType>::FunctionDelegate(Function f) : _func(f)
36template <
typename ReturnType>
37inline ReturnType FunctionDelegate<ReturnType>::invoke()
42template <
typename ReturnType>
43inline DelegateInterface<ReturnType>* FunctionDelegate<ReturnType>::clone()
45 return new FunctionDelegate(_func);
48template <
typename ReturnType,
typename Method,
typename Instance>
49inline MethodDelegate<ReturnType, Method, Instance>::MethodDelegate(Method method,
51 : _method(method), _instance(instance)
55template <
typename ReturnType,
typename Method,
typename Instance>
56inline ReturnType MethodDelegate<ReturnType, Method, Instance>::invoke()
58 return (_instance.*_method)();
61template <
typename ReturnType,
typename Method,
typename Instance>
62inline DelegateInterface<ReturnType>* MethodDelegate<ReturnType, Method, Instance>::clone()
64 return new MethodDelegate(_method, _instance);
70template <
typename ReturnType,
typename ParamType>
71DelegateInterface<ReturnType, ParamType>::~DelegateInterface()
75template <
typename ReturnType,
typename ParamType>
76inline FunctionDelegate<ReturnType, ParamType>::FunctionDelegate(Function f) : _func(f)
79template <
typename ReturnType,
typename ParamType>
80inline ReturnType FunctionDelegate<ReturnType, ParamType>::invoke(ParamType param)
85template <
typename ReturnType,
typename ParamType>
86inline DelegateInterface<ReturnType, ParamType>* FunctionDelegate<ReturnType, ParamType>::clone()
88 return new FunctionDelegate(_func);
91template <
typename ReturnType,
typename ParamType,
typename Method,
typename Instance>
92MethodDelegate<ReturnType, ParamType, Method, Instance>::MethodDelegate(Method method,
94 : _method(method), _instance(inst)
98template <
typename ReturnType,
typename ParamType,
typename Method,
typename Instance>
99inline ReturnType MethodDelegate<ReturnType, ParamType, Method, Instance>::invoke(ParamType param)
101 return (_instance.*_method)(param);
104template <
typename ReturnType,
typename ParamType,
typename Method,
typename Instance>
105inline DelegateInterface<ReturnType, ParamType>* MethodDelegate<ReturnType,
110 return new MethodDelegate(_method, _instance);
115template <
typename DelegateType>
116inline DelegateBase<DelegateType>::~DelegateBase()
118 delete _ptr_to_callee;
121template <
typename DelegateType>
122inline DelegateBase<DelegateType>::DelegateBase() : _ptr_to_callee(nullptr)
126template <
typename DelegateType>
127inline DelegateBase<DelegateType>::DelegateBase(
const DelegateBase& other) : _ptr_to_callee(nullptr)
129 if (other._ptr_to_callee) {
130 _ptr_to_callee = other._ptr_to_callee->clone();
134template <
typename DelegateType>
135inline DelegateBase<DelegateType>& DelegateBase<DelegateType>::operator=(
const DelegateBase& other)
137 if (&other !=
this) {
138 delete _ptr_to_callee;
139 _ptr_to_callee =
nullptr;
140 if (other._ptr_to_callee) {
141 _ptr_to_callee = other._ptr_to_callee->clone();
147template <
typename DelegateType>
148inline void DelegateBase<DelegateType>::setDelegate(DelegateType* delegate)
150 _ptr_to_callee = delegate;
153template <
typename DelegateType>
154inline DelegateType* DelegateBase<DelegateType>::getDelegate()
156 return _ptr_to_callee;
159template <
typename DelegateType>
160inline const DelegateType* DelegateBase<DelegateType>::getDelegate()
const
162 return _ptr_to_callee;
165template <
typename DelegateType>
166inline DelegateBase<DelegateType>::operator bool()
const
168 return getDelegate() !=
nullptr;
174template <
typename ReturnType>
177 if (
nullptr != Function) {
178 using namespace detail::delegates;
179 this->setDelegate(
new FunctionDelegate<ReturnType>(Function));
183template <
typename ReturnType>
184template <
typename Method,
typename Instance>
187 if (Method(
nullptr) != method) {
188 using namespace detail::delegates;
189 this->setDelegate(
new MethodDelegate<ReturnType, Method, Instance>(method, instance));
193template <
typename ReturnType>
197 throw std::runtime_error(
"Uninitialized Delegate invoked!");
198 return this->getDelegate()->invoke();
201template <
typename ReturnType,
typename ParamType>
204 if (
nullptr != Function) {
205 using namespace detail::functions;
206 this->setDelegate(
new FunctionDelegate<ReturnType, ParamType>(Function));
210template <
typename ReturnType,
typename ParamType>
211template <
typename Method,
typename Instance>
214 if (Method(
nullptr) != method) {
215 using namespace detail::functions;
217 new MethodDelegate<ReturnType, ParamType, Method, Instance>(method, instance));
221template <
typename ReturnType,
typename ParamType>
225 throw std::runtime_error(
"Uninitialized function invoked!");
227 return this->getDelegate()->invoke(param);
ReturnType operator()()
Definition delegate_impl.h:194
NullaryDelegate(ReturnType(*Function)())
Definition delegate_impl.h:175
ReturnType operator()(ParamType param)
Definition delegate_impl.h:222
UnaryDelegate(ReturnType(*Function)(ParamType))
Definition delegate_impl.h:202
Serves as component for features which are considered experimental.
Definition base.h:26
Serves as the root component, with common functionality documented in core functionality.
Definition base.h:24