PLCnext API Documentation 25.0.2.69
synced_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
29template<class M, class ...Args>
31{
32private: // usings
33 using delegate_type = delegate<void(Args...)>;
34 using event_handlers = std::vector<delegate_type>;
36 using SyncRoot = M;
37 using SyncGuard = typename M::LockGuard;
38
39public:
41
42public: // add/remove operators
46
47public: // invocation operator, functor
48 void operator()(Args... args)const;
49
50public: // property operations
51 bool is_empty(void)const;
52 size_t count(void)const;
53
54private:
55 event_handlers eventHandlers;
56 mutable SyncRoot syncRoot;
57};
58
59template<class M>
60class synced_event<M>;
61
63// specialized class synced_event<M> implementation
64
76template<class M>
77class synced_event<M, void>
78{
79public: // usings
80 using delegate_type = delegate<void()>;
81 using SyncRoot = M;
82 using SyncGuard = typename M::LockGuard;
83
84private: // usings
85 using event_handlers = std::vector<delegate_type>;
86
87public:
89
90public: // add/remove operators
94
95public: // invocation operator, functor
96 void operator()(void)const;
97
98public: // property operations
99 bool is_empty(void)const;
100 size_t count(void)const;
101
102private: // fields
103 event_handlers eventHandlers;
104 mutable SyncRoot syncRoot;
105};
106
107}}} // end of namespace Arp::Base::Core
108
109namespace Arp {
112}
113#include "Arp/Base/Core/Detail/synced_event.ipp"
This is the base class of all Arp exception classes.
Definition: Exception.hpp:21
Prototyping of delegate template.
Definition: delegate.hxx:14
synced_event(void)
Constructs a synced_event<void> instance.
M SyncRoot
The mutex type used for synchronization.
Definition: synced_event.hxx:81
typename M::LockGuard SyncGuard
The lock guard type used for RAII synchronization provided by Mutex type.
Definition: synced_event.hxx:82
Use this class to register and invoke several delegates (function pointer in OOP design) in synced ma...
Definition: synced_event.hxx:31
synced_event & operator+=(delegate_type &&rhs)
Adds a delegate to this event.
Definition: synced_event.ipp:28
void operator()(Args... args) const
Fires this event instance.
Definition: synced_event.ipp:99
synced_event & operator-=(const delegate_type &rhs)
Removes a delegate from this event.
Definition: synced_event.ipp:76
synced_event(void)
Constructs a synced_event instance.
size_t count(void) const
Gets the number of delegates to be invoked.
Definition: synced_event.ipp:129
bool is_empty(void) const
Checks if this event has any delegates to be invoked.
Definition: synced_event.ipp:117
Root namespace for the PLCnext API