Go to the documentation of this file.
9 #ifndef EAGINE_ENUM_CLASS_HPP
10 #define EAGINE_ENUM_CLASS_HPP
20 #include <type_traits>
34 template <
typename T,
typename ClassList,
typename Tag = nothing_t>
43 template <
typename T,
typename... Classes,
typename Tag>
61 explicit constexpr
operator value_type() const noexcept {
66 explicit constexpr
operator bool() const noexcept {
71 template <
typename... Classes,
typename Tag>
72 struct enum_value<bool, mp_list<Classes...>, Tag> {
73 using type = enum_value;
78 const bool value{
false};
80 constexpr enum_value(
bool val) noexcept
83 explicit constexpr
operator bool() const noexcept {
98 template <
typename T,
typename ClassList,
typename Tag = nothing_t>
107 template <
typename T,
typename... Classes,
typename Tag>
121 const bool is_valid{
false};
130 : value{std::get<0>(init)}
131 , is_valid{std::get<1>(init)} {}
140 explicit constexpr
operator bool() const noexcept {
145 template <
typename... Classes,
typename Tag>
146 struct opt_enum_value<bool, mp_list<Classes...>, Tag> {
147 using type = opt_enum_value;
150 using tag_type = Tag;
153 const bool is_valid{
false};
155 constexpr opt_enum_value(
bool val,
bool valid) noexcept
159 constexpr opt_enum_value(std::tuple<bool, bool> init) noexcept
160 : value(std::get<0>(init))
161 , is_valid{std::get<1>(init)} {}
163 explicit constexpr
operator bool() const noexcept {
164 return is_valid && value;
176 template <
typename T,
typename Tag = nothing_t>
189 explicit constexpr
operator T() const noexcept {
194 explicit constexpr
operator bool() const noexcept {
199 template <
typename Tag>
200 struct no_enum_value<bool, Tag> {
201 using type = no_enum_value;
206 explicit constexpr
operator bool() const noexcept {
211 template <
identifier_t LibId>
236 template <
typename Self,
typename T,
identifier_t LibId,
identifier_t Id>
255 typename = std::enable_if_t<mp_contains_v<Classes, Self>>>
257 : _value{ev.value} {}
263 typename = std::enable_if_t<mp_contains_v<Classes, Self>>>
266 EAGINE_ASSERT(ev.is_valid);
271 EAGINE_UNREACHABLE();
276 : _value{
static_cast<T
>(aev._value)} {
277 EAGINE_ASSERT(aev._type_id == Id);
284 constexpr
operator Self() const noexcept {
295 return a._value == b._value;
300 return a._value != b._value;
304 constexpr
auto operator()(T value) noexcept {
312 template <
typename T>
319 template <
typename T>
322 template <
typename Self,
typename T,
identifier_t LibId,
identifier_t Id>
329 template <
typename Class,
typename Value>
338 template <
typename C,
typename V>
360 struct is_enum_class_value<
361 enum_class<Self, T, LibId, Id>,
362 enum_value<T, Classes, Tag>> : mp_contains<Classes, Self> {
363 static_assert(std::is_base_of_v<enum_class<Self, T, LibId, Id>, Self>);
373 struct is_enum_class_value<
374 enum_class<Self, T, LibId, Id>,
375 opt_enum_value<T, Classes, Tag>> : mp_contains<Classes, Self> {
376 static_assert(std::is_base_of_v<enum_class<Self, T, LibId, Id>, Self>);
384 template <
identifier_t LibId>
393 template <
typename Self,
typename T,
identifier_t Id>
401 : _type_id{aev._type_id} {}
404 explicit constexpr
operator bool() const noexcept {
411 return a._type_id == b._type_id;
417 return a._type_id != b._type_id;
426 template <
identifier_t LibId>
427 struct any_enum_value {
437 : _value{long(v._value)}
439 static_assert(std::is_base_of_v<enum_class<Self, T, LibId, Id>, Self>);
443 explicit constexpr
operator bool() const noexcept {
450 return (a._value == b._value) && (a._type_id == b._type_id);
456 return (a._value != b._value) || (a._type_id != b._type_id);
463 template <
identifier_t LibId>
464 static constexpr
auto
466 return a._type_id == b._type_id;
475 template <
typename EnumClass,
typename Container>
480 typename EnumClass::value_type> {
489 constexpr
auto raw_enums() noexcept {
493 constexpr
auto raw_enums()
const noexcept {
502 template <
typename EnumClass>
510 template <
typename EnumClass>
518 template <
typename EnumClass, std::
size_t N>
524 #endif // EAGINE_ENUM_CLASS_HPP
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
Class holding optional value of a (typically C-API) symbolic constant.
Definition: enum_class.hpp:99
Enum class for constants or enumerators (typically from a C-API).
Definition: enum_class.hpp:237
constexpr enum_value(value_type val) noexcept
Initialization from the specified value.
Definition: enum_class.hpp:57
Common code is placed in this namespace.
Definition: eagine.hpp:21
constexpr bool is_enum_class_v
Trait indicating if type T is an enum_class.
Definition: enum_class.hpp:320
Class representing "none" / "nothing" values.
Definition: nothing.hpp:17
friend auto operator!=(const any_enum_value &a, const any_enum_value &b) noexcept
Nonequality comparison.
Definition: enum_class.hpp:455
Class representing undefined value of a (typically C-API) symbolic constant.
Definition: enum_class.hpp:177
Implementation of is_enum_class_value trait.
Definition: enum_class.hpp:330
constexpr any_enum_class() noexcept=default
Default constructor.
constexpr auto is_enum_class_value_v
Trait indicating if type T is an enum_value, opt_enum_value or no_enum_value.
Definition: enum_class.hpp:339
constexpr enum_class(value_type value) noexcept
Explicit initialization from argument of value type.
Definition: enum_class.hpp:281
constexpr enum_class(no_enum_value< T >) noexcept
Construction from a no_enum_value.
Definition: enum_class.hpp:270
T value_type
The constant or enumerator value type.
Definition: enum_class.hpp:181
constexpr friend auto operator!=(enum_class a, enum_class b) noexcept
Nonequality comparison.
Definition: enum_class.hpp:299
constexpr any_enum_class(const any_enum_value< LibId > &aev) noexcept
Construction from any_enum_value from the same "library" or API.
Definition: enum_class.hpp:400
constexpr friend auto operator==(enum_class a, enum_class b) noexcept
Equality comparison.
Definition: enum_class.hpp:294
T value_type
The constant or enumerator value type.
Definition: enum_class.hpp:241
constexpr opt_enum_value(std::tuple< value_type, bool > init) noexcept
Initialization from the specified value and validity indicator.
Definition: enum_class.hpp:129
constexpr enum_class(opt_enum_value< T, Classes, Tag > ev) noexcept
Construction from a related opt_enum_value.
Definition: enum_class.hpp:264
friend auto operator==(const any_enum_class &a, const any_enum_class &b) noexcept
Equality comparison.
Definition: enum_class.hpp:410
constexpr any_enum_value() noexcept=default
Default constructor.
constexpr enum_class(enum_value< T, Classes, Tag > ev) noexcept
Construction from a related enum_value.
Definition: enum_class.hpp:256
friend auto operator!=(const any_enum_class &a, const any_enum_class &b) noexcept
Nonequality comparison.
Definition: enum_class.hpp:416
constexpr enum_class(const any_enum_value< LibId > &aev) noexcept
Construction from an any_enum_value.
Definition: enum_class.hpp:275
constexpr any_enum_class(const enum_class< Self, T, LibId, Id > &) noexcept
Construction from enum_class from the same "library" or API.
Definition: enum_class.hpp:394
static auto transform(basic_span< T, P, S > spn, Transform function) -> basic_span< T, P, S >
Transforms the elements of a span with a function.
Definition: span_algo.hpp:572
Tag tag_type
The tag type specified as template argument.
Definition: enum_class.hpp:184
Type erasure for instantiations of enum_value from a specified library.
Definition: enum_class.hpp:212
static constexpr auto same_enum_class(any_enum_class< LibId > a, any_enum_class< LibId > b) noexcept
Tests if two instances of any_enum_class belong to the same enum class.
Definition: enum_class.hpp:465
Template for containers of enum_class.
Definition: enum_class.hpp:476
Implementation of is_enum_class trait.
Definition: enum_class.hpp:313
constexpr auto raw_items() noexcept
Returns view of the elements as they are stored, without transfomation.
Definition: wrapping_container.hpp:127
Compile-time type list template.
Definition: mp_list.hpp:20
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
Tag tag_type
The tag type specified as template argument.
Definition: enum_class.hpp:115
constexpr opt_enum_value(T val, bool valid) noexcept
Initialization from the specified value and validity indicator.
Definition: enum_class.hpp:124
Tag tag_type
The tag type specified as template argument.
Definition: enum_class.hpp:51
T value_type
The constant or enumerator value type.
Definition: enum_class.hpp:112
enum_class()=default
Default constructor.
Type erasure for instantiations of enum_class from a specified library.
Definition: enum_class.hpp:385
Template used in implementation of containers with wrapped elements.
Definition: wrapping_container.hpp:26
T value_type
The constant or enumerator value type.
Definition: enum_class.hpp:48
friend auto operator==(const any_enum_value &a, const any_enum_value &b) noexcept
Equality comparison.
Definition: enum_class.hpp:449
Class holding the value of a (typically C-API) symbolic constant.
Definition: enum_class.hpp:35