8 #ifndef LLUVIA_CORE_ENUMS_H_
9 #define LLUVIA_CORE_ENUMS_H_
26 template <
typename BitType,
typename MaskType = enum_t>
34 constexpr
Flags(BitType bit) noexcept
35 : m_mask {
static_cast<MaskType
>(bit)}
39 constexpr
explicit Flags(MaskType mask)
49 return m_mask < rhs.m_mask;
54 return m_mask <= rhs.m_mask;
59 return m_mask > rhs.m_mask;
64 return m_mask >= rhs.m_mask;
69 return m_mask == rhs.m_mask;
74 return m_mask != rhs.m_mask;
112 m_mask |= rhs.m_mask;
118 m_mask &= rhs.m_mask;
124 m_mask ^= rhs.m_mask;
129 explicit constexpr
operator bool() const noexcept
134 explicit constexpr
operator MaskType() const noexcept
145 template <
typename E, std::
size_t N, const std::array<std::tuple<const
char*, E>, N>& values>
149 auto compare = [&value](
const std::tuple<const char*, E>& e) {
150 return std::get<1>(e) == value;
153 auto it = std::find_if(values.cbegin(), values.cend(), compare);
155 return std::get<0>(*it);
158 template <
typename E, std::
size_t N, const std::array<std::tuple<const
char*, E>, N>& values>
162 auto compare = [&value](
const std::tuple<const char*, E>& e) {
163 return std::get<1>(e) == value;
166 auto it = std::find_if(values.cbegin(), values.cend(), compare);
168 return std::get<0>(*it);
171 template <
typename E,
typename T, std::
size_t N, const std::array<std::tuple<const
char*, E>, N>& values>
175 static_assert(std::is_convertible<T, std::string>(),
"T must be a string-like type");
177 auto compare = [&stringValue](
const std::tuple<const char*, E>& e) {
178 return std::get<0>(e) == stringValue;
181 auto it = std::find_if(values.cbegin(), values.cend(), compare);
183 if (it == values.cend()) {
184 throw std::out_of_range(
"invalid string value [" + stringValue +
"] for enum type " +
typeid(E).name());
187 return std::get<1>(*it);
190 template <
typename E,
typename Ebits, std::
size_t N, const std::array<std::tuple<const
char*, Ebits>, N>& values>
196 for (
const auto& strFlag : flagsVector) {
198 for (
const auto& flagPair : values) {
200 if (std::get<0>(flagPair) == strFlag) {
201 flags |= std::get<1>(flagPair);
210 template <
typename E,
typename Ebits, std::
size_t N, const std::array<std::tuple<const
char*, Ebits>, N>& values>
214 auto flagsVector = std::vector<std::string> {};
216 for (
const auto& flagPair : values) {
218 const auto& vFlags = std::get<1>(flagPair);
220 if ((flags & vFlags) == vFlags) {
221 flagsVector.push_back(std::get<0>(flagPair));
Flags< BitType, MaskType > & operator&=(Flags< BitType, MaskType > const &rhs) noexcept
Definition: enums.h:116
constexpr bool operator!=(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:72
constexpr bool operator>=(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:62
constexpr bool operator<=(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:52
constexpr Flags< BitType, MaskType > operator&(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:84
Flags< BitType, MaskType > & operator=(Flags< BitType, MaskType > const &rhs) noexcept
Definition: enums.h:104
Flags(Flags< BitType, MaskType > &&f)=default
Flags< BitType, MaskType > & operator|=(Flags< BitType, MaskType > const &rhs) noexcept
Definition: enums.h:110
constexpr bool operator!() const noexcept
Definition: enums.h:78
constexpr Flags< BitType, MaskType > operator^(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:94
constexpr Flags< BitType, MaskType > operator|(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:89
constexpr bool operator<(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:47
Flags(const Flags< BitType, MaskType > &f)=default
constexpr bool operator==(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:67
constexpr Flags(MaskType mask)
Definition: enums.h:39
Flags< BitType, MaskType > & operator^=(Flags< BitType, MaskType > const &rhs) noexcept
Definition: enums.h:122
constexpr bool operator>(Flags< BitType, MaskType > const &rhs) const noexcept
Definition: enums.h:57
constexpr Flags(BitType bit) noexcept
Definition: enums.h:34
E stringToEnum(T &&stringValue)
Definition: enums.h:172
std::string enumToString(E &&value) noexcept
Definition: enums.h:146
E vectorStringToFlags(const std::vector< std::string > &flagsVector) noexcept
Definition: enums.h:191
std::vector< std::string > flagsToVectorString(E flags) noexcept
Definition: enums.h:211
uint32_t enum_t
Definition: enums.h:23