Maki
Loading...
Searching...
No Matches
event_set.hpp
1//Copyright Florian Goujeon 2021 - 2025.
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 "null.hpp"
11#include "event.hpp"
12#include "detail/set.hpp"
13#include "detail/impl.hpp"
14#include "detail/equals.hpp"
15
16namespace maki
17{
18
23template<class Impl>
24class event_set;
25
26namespace detail
27{
28 template<class Impl>
29 constexpr auto make_event_set_from_impl(const Impl& impl)
30 {
31 return event_set<Impl>{impl};
32 }
33}
34
35template<class Impl>
37{
38public:
42 template<class Event>
43 constexpr explicit event_set(event_t<Event> /*evt*/)
44 {
45 }
46
50 template<class Event>
51 [[nodiscard]]
52 constexpr bool contains(event_t<Event> /*ignored*/ = {}) const
53 {
54 return detail::contains(impl_, detail::type<Event>);
55 }
56
57private:
58 using impl_type = Impl;
59
60 template<class Impl2>
61 friend constexpr auto detail::make_event_set_from_impl(const Impl2&);
62
63 constexpr explicit event_set(const Impl& impl):
64 impl_(impl)
65 {
66 }
67
68 MAKI_DETAIL_FRIENDLY_IMPL
69};
70
75template<class Event>
77<
78#ifdef MAKI_DETAIL_DOXYGEN
79 IMPLEMENTATION_DETAIL
80#else
81 decltype(detail::make_set_including_types<Event>())
82#endif
83>;
84
85#ifdef MAKI_DETAIL_DOXYGEN
90inline constexpr auto all_events = IMPLEMENTATION_DETAIL;
91#else
92inline constexpr auto all_events = detail::make_event_set_from_impl
93(
94 detail::make_set_including_all()
95);
96#endif
97
98#ifdef MAKI_DETAIL_DOXYGEN
103inline constexpr auto no_event = IMPLEMENTATION_DETAIL;
104#else
105inline constexpr auto no_event = detail::make_event_set_from_impl
106(
107 detail::make_set_excluding_all()
108);
109#endif
110
116template<class Predicate>
117constexpr auto operator!(const event_set<Predicate>& evt_set)
118{
119 return detail::make_event_set_from_impl
120 (
121 detail::inverse_set(detail::impl_of(evt_set))
122 );
123}
124
130template<class Event>
131constexpr auto operator!(event_t<Event> /*evt*/)
132{
133 return detail::make_event_set_from_impl
134 (
135 detail::make_set_excluding(detail::type<Event>)
136 );
137}
138
144template<class LhsImpl, class RhsImpl>
145constexpr auto operator||
146(
147 const event_set<LhsImpl>& lhs,
148 const event_set<RhsImpl>& rhs
149)
150{
151 return detail::make_event_set_from_impl
152 (
153 detail::make_set_union(detail::impl_of(lhs), detail::impl_of(rhs))
154 );
155}
156
162template<class EventSetPredicate, class Event>
163constexpr auto operator||
164(
165 const event_set<EventSetPredicate>& evt_set,
166 event_t<Event> /*evt*/
167)
168{
169 return detail::make_event_set_from_impl
170 (
171 detail::make_set_union(detail::impl_of(evt_set), detail::type<Event>)
172 );
173}
174
180template<class Event, class EventSetPredicate>
181constexpr auto operator||
182(
183 const event_t<Event> evt,
184 const event_set<EventSetPredicate>& evt_set
185)
186{
187 return evt_set || evt;
188}
189
194template<class LhsEvent, class RhsEvent>
195constexpr auto operator||
196(
197 event_t<LhsEvent> /*lhs*/,
198 event_t<RhsEvent> /*rhs*/
199)
200{
201 return detail::make_event_set_from_impl
202 (
203 detail::make_set_including_types<LhsEvent, RhsEvent>()
204 );
205}
206
212template<class LhsImpl, class RhsImpl>
213constexpr auto operator&&
214(
215 const event_set<LhsImpl>& lhs,
216 const event_set<RhsImpl>& rhs
217)
218{
219 return detail::make_event_set_from_impl
220 (
221 detail::make_set_intersection(detail::impl_of(lhs) && detail::impl_of(rhs))
222 );
223}
224
225namespace detail
226{
227 template<class Event, class Event2>
228 constexpr bool contained_in(const event_t<Event> lhs, const event_t<Event2> rhs)
229 {
230 return equals(lhs, rhs);
231 }
232
233 template<class Event>
234 constexpr bool contained_in(event_t<Event> /*lhs*/, null_t /*rhs*/)
235 {
236 return false;
237 }
238
239 template<class Event, class... Predicates>
240 constexpr bool contained_in(const event_t<Event> evt, const event_set<Predicates>&... evt_sets)
241 {
242 return (evt_sets.contains(evt) || ...);
243 }
244
245 template<class T>
246 struct is_event_set
247 {
248 static constexpr auto value = false;
249 };
250
251 template<class Predicate>
252 struct is_event_set<event_set<Predicate>>
253 {
254 static constexpr auto value = true;
255 };
256
257 template<class T>
258 constexpr auto is_event_set_v = is_event_set<T>::value;
259}
260
261} //namespace
262
263#endif
Represents an event type set.
Definition event_set.hpp:37
constexpr auto no_event
An empty maki::event_set.
Definition event_set.hpp:103
constexpr auto operator!(event_t< Event >)
Creates a maki::event_set that contains all the event types but Event.
Definition event_set.hpp:131
constexpr bool contains(event_t< Event >={}) const
Checks whether the set contains Event.
Definition event_set.hpp:52
event_set(event_t< Event >) -> event_set< IMPLEMENTATION_DETAIL >
Class template argument deduction guide for maki::event_set.
constexpr auto operator!(const event_set< Predicate > &evt_set)
Creates a maki::event_set that contains all the event types that are not contained in evt_set.
Definition event_set.hpp:117
constexpr auto all_events
An infinite maki::event_set that contains all the event types.
Definition event_set.hpp:90
constexpr event_set(event_t< Event >)
Constructs a set that only contains Event.
Definition event_set.hpp:43
The Maki library.
IMPLEMENTATION_DETAIL null_t
The type of maki::null
Definition null.hpp:26
Holds an event type.
Definition event.hpp:20