PLCnext API Documentation 25.0.2.69
delegate.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/Detail/IDelegateFunctor.hpp"
9#include <memory>
10namespace Arp { namespace Base { namespace Core
11{
12
14template<typename T> class delegate;
15
32template<class R, class ...A>
33class delegate<R(A...)>
34{
35private: // usings
36 using IDelegateFunctor = Arp::Base::Core::IDelegateFunctor;
37 using FunctorPtr = std::shared_ptr<IDelegateFunctor>;
38 using InvokerPtr = R(*)(IDelegateFunctor*, A...);
39
40public: // construction
41 delegate(std::nullptr_t)noexcept;
42 template<class Lambda> delegate(Lambda f);
43
44public: // canonical construction/destruction/assignment
45 delegate(void);
46
47public: // static factory operations
48 static delegate create(R(* const pFunction)(A...));
49 static delegate create(std::function<R(A...)>&& f);
50 static delegate create(const std::function<R(A...)>& f);
51
52 template <class C> static delegate create(C* pObject, R(C::* pMethod)(A...))noexcept;
53 template <class C> static delegate create(C& object, R(C::* pMethod)(A...))noexcept;
54 template <class C> static delegate create(const C* pObject, R(C::* pMethod)(A...)const)noexcept;
55 template <class C> static delegate create(const C& object, R(C::* pMethod)(A...)const)noexcept;
56
57public: // operators
58 bool operator==(const delegate& rhs)const noexcept;
59 bool operator!=(const delegate& rhs)const noexcept;
60 bool operator==(std::nullptr_t const)const noexcept;
61 bool operator!=(std::nullptr_t const)const noexcept;
62 operator bool()const noexcept;
63
64public: // getter/setter
65 bool is_lambda(void)const;
66
67public: // functor operator()
68 R operator()(A... args)const;
69
70public: // management operations
71 void reset(void);
72
73private: // construction
74 delegate(FunctorPtr&& pFunctor, InvokerPtr pInvoker)noexcept;
75
76private: // fields
77 InvokerPtr pInvoker = nullptr;
78 FunctorPtr functorPtr = nullptr;
79};
80
82// prototypes of factory function make_delegate
83
84template<class R, class ...A>
85delegate<R(A...)> make_delegate(R(* const function_ptr)(A...))noexcept;
86
87template<class C, class R, class ...A>
88delegate<R(A...)> make_delegate(C* const pObject, R(C::* const pMethod)(A...))noexcept;
89
90template<class C, class R, class ...A>
91delegate<R(A...)> make_delegate(C const* const pObject, R(C::* const pMethod)(A...)const)noexcept;
92
93template<class C, class R, class ...A>
94delegate<R(A...)> make_delegate(C& object, R(C::* const pMethod)(A...))noexcept;
95
96template<class C, class R, class ...A>
97delegate<R(A...)> make_delegate(const C& object, R(C::* const pMethod)(A...)const)noexcept;
98
99template<class R, class ...A>
100delegate<R(A...)> make_delegate(std::function<R(A...)>&& f)noexcept;
101
102template<class R, class ...A>
103delegate<R(A...)> make_delegate(const std::function<R(A...)>& f)noexcept;
104
105}}} // end of namespace Arp::Base::Core
106
107namespace Arp {
111using Arp::Base::Core::make_delegate;
112}
113#include "Arp/Base/Core/Detail/delegate.ipp"
delegate(void)
The default constructor.
Prototyping of delegate template.
Definition: delegate.hxx:14
Root namespace for the PLCnext API
Namespace of the C++ standard library