8#ifndef ARP_USE_ARP_SYSTEM_CORE
10#include "Arp/Base/Core/delegate.hxx"
15#include "Arp/System/Core/Impl/StaticFunctor.hxx"
16#include "Arp/System/Core/Impl/MethodFunctor.hxx"
17#include "Arp/System/Core/Impl/ConstMethodFunctor.hxx"
18#include "Arp/System/Core/Impl/LambdaFunctor.hxx"
24using namespace Arp::System::Core;
53template<
class R,
class ...A>
57 using InvokerPtr = R(*)(
void*, A && ...);
58 using FunctorPtr = std::shared_ptr<Impl::IDelegateFunctor>;
62 template<
class Lambda>
63 delegate(Lambda f) :
delegate(new Impl::LambdaFunctor<R(A...)>(
std::function<R(A...)>(f)), &Impl::LambdaFunctor<R(A...)>::Invoke) {}
85 static delegate create(R(*
const pFunction)(A...))
87 return{
new Impl::StaticFunctor<R(A...)>(pFunction), &Impl::StaticFunctor<R(A...)>::Invoke };
95 static delegate create(C* pObject, R(C::*pMethod)(A...))noexcept
97 return{
new Impl::MethodFunctor<R(C::*)(A...)>(pObject, pMethod), &Impl::MethodFunctor<R(C::*)(A...)>::Invoke };
105 static delegate create(C&
object, R(C::*pMethod)(A...))noexcept
107 return{
new Impl::MethodFunctor<R(C::*)(A...)>(object, pMethod), &Impl::MethodFunctor<R(C::*)(A...)>::Invoke };
115 static delegate create(
const C* pObject, R(C::*pMethod)(A...)const)noexcept
117 return{
new Impl::ConstMethodFunctor<R(C::*)(A...)
const>(pObject, pMethod), &Impl::ConstMethodFunctor<R(C::*)(A...)
const>::Invoke };
125 static delegate create(
const C&
object, R(C::*pMethod)(A...)const)noexcept
127 return{
new Impl::ConstMethodFunctor<R(C::*)(A...)
const>(object, pMethod), &Impl::ConstMethodFunctor<R(C::*)(A...)
const>::Invoke };
133 static delegate create(std::function<R(A...)>&& f)
135 return{
new Impl::LambdaFunctor<R(A...)>(std::move(f)), &Impl::LambdaFunctor<R(A...)>::Invoke };
141 static delegate create(
const std::function<R(A...)>& f)
143 return{
new Impl::LambdaFunctor<R(A...)>(f), &Impl::LambdaFunctor<R(A...)>::Invoke };
150 bool operator==(
const delegate& rhs)
const noexcept
152 return *this->functorPtr == *rhs.functorPtr;
158 bool operator!=(
const delegate& rhs)
const noexcept
160 return !(this->operator==(rhs));
169 bool operator==(std::nullptr_t
const)
const noexcept
171 return this->functorPtr ==
nullptr;
176 bool operator!=(std::nullptr_t
const)
const noexcept
178 return this->functorPtr !=
nullptr;
183 explicit operator bool()const noexcept
185 return (
bool)this->functorPtr;
191 bool is_lambda(
void)
const
193 return (
bool)(*this) &&
dynamic_cast<Impl::LambdaFunctor<R(A...)
>*>(this->functorPtr.get()) !=
nullptr;
200 R operator()(A... args)
const
202 return this->pInvoker(this->functorPtr.get(), std::forward<A>(args)...);
210 this->pInvoker =
nullptr;
211 this->functorPtr =
nullptr;
215 delegate(Impl::IDelegateFunctor* pFunctor, InvokerPtr pInvokerArg)noexcept
216 : pInvoker(pInvokerArg)
217 , functorPtr(pFunctor)
223 FunctorPtr functorPtr;
231template<
class R,
class ...A>
232inline delegate<R(A...)> make_delegate(R(*
const function_ptr)(A...))noexcept
234 return delegate<R(A...)>::create(function_ptr);
241template<
class C,
class R,
class ...A>
242inline delegate<R(A...)> make_delegate(C*
const pObject, R(C::*
const pMethod)(A...))noexcept
244 return delegate<R(A...)>::create(pObject, pMethod);
251template<
class C,
class R,
class ...A>
252inline delegate<R(A...)> make_delegate(C
const*
const pObject, R(C::*
const pMethod)(A...)const)noexcept
254 return delegate<R(A...)>::create(pObject, pMethod);
261template<
class C,
class R,
class ...A>
262inline delegate<R(A...)> make_delegate(C&
object, R(C::*
const pMethod)(A...))noexcept
264 return delegate<R(A...)>::create(
object, pMethod);
271template<
class C,
class R,
class ...A>
272inline delegate<R(A...)> make_delegate(
const C&
object, R(C::*
const pMethod)(A...)const)noexcept
274 return delegate<R(A...)>::create(
object, pMethod);
280template<
class R,
class ...A>
281inline delegate<R(A...)> make_delegate(std::function<R(A...)>&& f)
noexcept
283 return delegate<R(A...)>::create(std::move(f));
289template<
class R,
class ...A>
290inline delegate<R(A...)> make_delegate(
const std::function<R(A...)>& f)
noexcept
292 return delegate<R(A...)>::create(f);
Prototyping of delegate template.
Definition: delegate.hxx:14
Root namespace for the PLCnext API
Namespace of the C++ standard library