PLCnext API Documentation 25.0.2.69
event.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/delegate.hxx"
9#include "Arp/Base/Core/Exception.hpp"
10#include <vector>
11#include <algorithm>
12namespace Arp { namespace Base { namespace Core
13{
14
16// class event is implemented completely implicit inline to avoid
17// code bloat in commonly used Core classes and therefore reduce compile time
18
30template<class ...Args>
31class event
32{
33private: // usings
34 using delegate_type = delegate<void(Args...)>;
35 using event_handlers = std::vector<delegate_type>;
37
38public:
40 event(void);
41
42public: // add/remove operators
43 event& operator+=(delegate_type&& rhs);
44 event& operator+=(const delegate_type& rhs);
45 event& operator-=(const delegate_type& rhs);
46
47public: // invocation operator, functor
48 void operator()(Args... args)const;
49 bool is_empty(void)const;
50
51private:
52 event_handlers eventHandlers;
53};
54
56// specialized class event<void> implementation
57
69template<>
70class event<void>
71{
72public: // usings
73 using delegate_type = delegate<void()>;
74
75private: // usings
76 using event_handlers = std::vector<delegate_type>;
77
78public:
79 event(void);
80
81public: // add/remove operators
82 event& operator+=(delegate_type&& rhs);
83 event& operator+=(const delegate_type& rhs);
84 event& operator-=(const delegate_type& rhs);
85
86public: // invocation operator, functor
87 void operator()(void)const;
88
89public: // property operations
90 bool is_empty(void)const;
91
92private: // fields
93 event_handlers eventHandlers;
94};
95
96}}} // end of namespace Arp::Base::Core
97
98namespace Arp {
101}
102#include "Arp/Base/Core/Detail/event.ipp"
This is the base class of all Arp exception classes.
Definition: Exception.hpp:21
Prototyping of delegate template.
Definition: delegate.hxx:14
event(void)
Constructs a event<void> instance.
Use this class to register and invoke several delegates (function pointer in OOP design).
Definition: event.hxx:32
event & operator+=(delegate_type &&rhs)
Adds a delegate to this event.
Definition: event.ipp:22
void operator()(Args... args) const
Fires this event instance.
Definition: event.ipp:80
bool is_empty(void) const
Checks if this event has any delegates to be invoked.
Definition: event.ipp:93
event & operator-=(const delegate_type &rhs)
Removes a delegate from this event.
Definition: event.ipp:62
event(void)
Constructs a event instance.
Root namespace for the PLCnext API