Maki
Loading...
Searching...
No Matches
state_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_STATE_SET_HPP
8#define MAKI_STATE_SET_HPP
9
10#include "detail/state_builder_fwd.hpp"
11#include "detail/impl.hpp"
12#include "detail/set.hpp"
13
14namespace maki
15{
16
21template<class Impl>
22class state_set;
23
24namespace detail
25{
26 template<class Impl>
27 constexpr auto make_state_set_from_impl(const Impl& impl)
28 {
29 return state_set<Impl>{impl};
30 }
31}
32
33template<class Impl>
34class state_set
35{
36public:
37 constexpr state_set(const state_set& other) = default;
38 constexpr state_set(state_set&& other) = default;
39
40 ~state_set() = default;
41
42 constexpr state_set& operator=(const state_set& other) = default;
43 constexpr state_set& operator=(state_set&& other) = default;
44
45private:
46 using impl_type = Impl;
47
48 template<class Impl2>
49 friend constexpr auto detail::make_state_set_from_impl(const Impl2&);
50
51 explicit constexpr state_set(const Impl& impl):
52 impl_(impl)
53 {
54 }
55
56 MAKI_DETAIL_FRIENDLY_IMPL
57};
58
59#ifdef MAKI_DETAIL_DOXYGEN
64inline constexpr auto all_states = IMPLEMENTATION_DETAIL;
65#else
66inline constexpr auto all_states = detail::make_state_set_from_impl
67(
68 detail::make_set_including_all()
69);
70#endif
71
72#ifdef MAKI_DETAIL_DOXYGEN
77inline constexpr auto no_state = IMPLEMENTATION_DETAIL;
78#else
79inline constexpr auto no_state = detail::make_state_set_from_impl
80(
81 detail::make_set_excluding_all()
82);
83#endif
84
90template<class Impl>
91constexpr auto operator!(const state_set<Impl>& stt_set)
92{
93 return detail::make_state_set_from_impl
94 (
95 detail::inverse_set(detail::impl_of(stt_set))
96 );
97}
98
104template<class StateBuilderImpl>
105constexpr auto operator!(const state_builder<StateBuilderImpl>& stt_builder)
106{
107 return detail::make_state_set_from_impl
108 (
109 detail::make_set_excluding(&stt_builder)
110 );
111}
112
118template<class LhsImpl, class RhsImpl>
119constexpr auto operator||
120(
121 const state_set<LhsImpl>& lhs,
122 const state_set<RhsImpl>& rhs
123)
124{
125 return detail::make_state_set_from_impl
126 (
127 detail::make_set_union(detail::impl_of(lhs), detail::impl_of(rhs))
128 );
129}
130
136template<class StateSetImpl, class StateBuilderImpl>
137constexpr auto operator||
138(
139 const state_set<StateSetImpl>& stt_set,
140 const state_builder<StateBuilderImpl>& stt_builder
141)
142{
143 return detail::make_state_set_from_impl
144 (
145 detail::make_set_union(detail::impl_of(stt_set), &stt_builder)
146 );
147}
148
154template<class StateBuilderImpl, class StateSetImpl>
155constexpr auto operator||
156(
157 const state_builder<StateBuilderImpl>& stt_builder,
158 const state_set<StateSetImpl>& stt_set
159)
160{
161 return stt_set || stt_builder;
162}
163
169template<class LhsStateBuilderImpl, class RhsStateBuilderImpl>
170constexpr auto operator||
171(
174)
175{
176 return detail::make_state_set_from_impl
177 (
178 detail::make_set_including(&lhs, &rhs)
179 );
180}
181
187template<class LhsImpl, class RhsImpl>
188constexpr auto operator&&
189(
190 const state_set<LhsImpl>& lhs,
191 const state_set<RhsImpl>& rhs
192)
193{
194 return detail::make_state_set_from_impl
195 (
196 detail::make_set_intersection(detail::impl_of(lhs) && detail::impl_of(rhs))
197 );
198}
199
200namespace detail
201{
202 template<class StateBuilderImpl, class StateBuilderImpl2>
203 constexpr bool contained_in(const state_builder<StateBuilderImpl>& lhs, const state_builder<StateBuilderImpl2>* rhs)
204 {
205 return equals(&lhs, rhs);
206 }
207
208 template<class StateBuilderImpl, class... Predicates>
209 constexpr bool contained_in(const state_builder<StateBuilderImpl>& stt_builder, const state_set<Predicates>&... state_sets)
210 {
211 return (contains(impl_of(state_sets), &stt_builder) || ...);
212 }
213
214 template<class T>
215 struct is_state_set
216 {
217 static constexpr auto value = false;
218 };
219
220 template<class Predicate>
221 struct is_state_set<state_set<Predicate>>
222 {
223 static constexpr auto value = true;
224 };
225
226 template<class T>
227 constexpr auto is_state_set_v = is_state_set<T>::value;
228}
229
230} //namespace
231
232#endif
State builder.
Definition state_builder.hpp:42
Represents a state set.
Definition state_set.hpp:35
constexpr auto no_state
An empty maki::state_set.
Definition state_set.hpp:77
constexpr auto operator!(const state_builder< StateBuilderImpl > &stt_builder)
Creates a maki::state_set that contains all the states but the ones created by stt_builder.
Definition state_set.hpp:105
constexpr auto all_states
An infinite maki::state_set that contains all the states.
Definition state_set.hpp:64
constexpr auto operator!(const state_set< Impl > &stt_set)
Creates a maki::state_set that contains all the states that are not contained in stt_set.
Definition state_set.hpp:91
The Maki library.