Maki
Loading...
Searching...
No Matches
event_set.hpp
1//Copyright Florian Goujeon 2021 - 2026.
2//Distributed under the Boost Software License, Version 1.0.
3//(See accompanying file LICENSE or copy at
4//https://www.boost.org/LICENSE_1_0.txt)
5//Official repository: https://github.com/fgoujeon/maki
6
7#ifndef MAKI_EVENT_SET_HPP
8#define MAKI_EVENT_SET_HPP
9
10#include "event.hpp"
11#include "detail/type_set.hpp"
12#include "detail/friendly_impl.hpp"
13
14namespace maki
15{
16
21template<class Impl>
22class event_set;
23
24namespace detail
25{
26 template<class Impl>
27 constexpr event_set<Impl> make_event_set_from_impl()
28 {
29 return event_set<Impl>{};
30 }
31}
32
33template<class Impl>
35{
36public:
40 template<class Event>
41 constexpr explicit event_set(event_t<Event> /*evt*/)
42 {
43 }
44
48 template<class Event>
49 [[nodiscard]]
50 constexpr bool contains() const
51 {
52 return detail::type_set_contains_v<Impl, Event>;
53 }
54
58 template<class Event>
59 [[nodiscard]]
60 constexpr bool contains(event_t<Event> /*ignored*/) const
61 {
62 return detail::type_set_contains_v<Impl, Event>;
63 }
64
65private:
66 using impl_type = Impl;
67
68 template<class T>
69 friend struct detail::impl_of_t_helper;
70
71 template<class Impl2>
72 friend constexpr event_set<Impl2> detail::make_event_set_from_impl();
73
74 constexpr event_set() = default;
75};
76
81template<class Event>
83<
84#ifdef MAKI_DETAIL_DOXYGEN
85 IMPLEMENTATION_DETAIL
86#else
87 detail::type_set_item<Event>
88#endif
89>;
90
91#ifdef MAKI_DETAIL_DOXYGEN
96inline constexpr auto all_events = IMPLEMENTATION_DETAIL;
97#else
98inline constexpr auto all_events = detail::make_event_set_from_impl
99<
100 detail::universal_type_set_t
101>();
102#endif
103
104#ifdef MAKI_DETAIL_DOXYGEN
109inline constexpr auto no_event = IMPLEMENTATION_DETAIL;
110#else
111inline constexpr auto no_event = detail::make_event_set_from_impl
112<
113 detail::empty_type_set_t
114>();
115#endif
116
122template<class EventSetImpl>
123constexpr auto operator!
124(
125#ifdef MAKI_DETAIL_DOXYGEN
126 const event_set<EventSetImpl>& event_types
127#else
128 const event_set<EventSetImpl>& /*event_types*/
129#endif
130)
131{
132 return detail::make_event_set_from_impl
133 <
134 detail::type_set_inverse_t<EventSetImpl>
135 >();
136}
137
143template<class Event>
144constexpr auto operator!(event_t<Event> /*evt*/)
145{
146 return detail::make_event_set_from_impl
147 <
148 detail::type_set_exclusion_list<Event>
149 >();
150}
151
157template<class LhsImpl, class RhsImpl>
158constexpr auto operator||
159(
160#ifdef MAKI_DETAIL_DOXYGEN
161 const event_set<LhsImpl>& lhs,
162 const event_set<RhsImpl>& rhs
163#else
164 const event_set<LhsImpl>& /*lhs*/,
165 const event_set<RhsImpl>& /*rhs*/
166#endif
167)
168{
169 return detail::make_event_set_from_impl
170 <
171 detail::type_set_union_t<LhsImpl, RhsImpl>
172 >();
173}
174
180template<class LhsImpl, class Event>
181constexpr auto operator||
182(
183#ifdef MAKI_DETAIL_DOXYGEN
184 const event_set<LhsImpl>& lhs,
186#else
187 const event_set<LhsImpl>& /*lhs*/,
188 event_t<Event> /*rhs*/
189#endif
190)
191{
192 return detail::make_event_set_from_impl
193 <
194 detail::type_set_union_t
195 <
196 LhsImpl,
197 detail::type_set_item<Event>
198 >
199 >();
200}
201
207template<class Event, class RhsImpl>
208constexpr auto operator||
209(
210 const event_t<Event> lhs,
211 const event_set<RhsImpl>& rhs
212)
213{
214 return rhs || lhs;
215}
216
221template<class LhsEvent, class RhsEvent>
222constexpr auto operator||
223(
224 event_t<LhsEvent> /*lhs*/,
225 event_t<RhsEvent> /*rhs*/
226)
227{
228 return detail::make_event_set_from_impl
229 <
230 detail::type_set_inclusion_list<LhsEvent, RhsEvent>
231 >();
232}
233
239template<class LhsImpl, class RhsImpl>
240constexpr auto operator&&
241(
242#ifdef MAKI_DETAIL_DOXYGEN
243 const event_set<LhsImpl>& lhs,
244 const event_set<RhsImpl>& rhs
245#else
246 const event_set<LhsImpl>& /*lhs*/,
247 const event_set<RhsImpl>& /*rhs*/
248#endif
249)
250{
251 return detail::make_event_set_from_impl
252 <
253 detail::type_set_intersection_t<LhsImpl, RhsImpl>
254 >();
255}
256
257namespace detail
258{
259 template<class T>
260 struct is_event_set
261 {
262 static constexpr auto value = false;
263 };
264
265 template<class EventSetImpl>
266 struct is_event_set<event_set<EventSetImpl>>
267 {
268 static constexpr auto value = true;
269 };
270
271 template<class T>
272 constexpr auto is_event_set_v = is_event_set<T>::value;
273}
274
275} //namespace
276
277#endif
Represents an event type set.
Definition event_set.hpp:35
constexpr bool contains(event_t< Event >) const
Checks whether the set contains Event.
Definition event_set.hpp:60
constexpr auto no_event
An empty maki::event_set.
Definition event_set.hpp:109
constexpr auto operator!(event_t< Event >)
Creates a maki::event_set that contains all the event types but Event.
Definition event_set.hpp:144
constexpr bool contains() const
Checks whether the set contains Event.
Definition event_set.hpp:50
event_set(event_t< Event >) -> event_set< IMPLEMENTATION_DETAIL >
Class template argument deduction guide for maki::event_set.
constexpr auto all_events
An infinite maki::event_set that contains all the event types.
Definition event_set.hpp:96
constexpr event_set(event_t< Event >)
Constructs a set that only contains Event.
Definition event_set.hpp:41
The Maki library.
Holds an event type.
Definition event.hpp:20