1 #ifndef SIPLASPLAS_REFLECTION_STATIC_ENUM_HPP 2 #define SIPLASPLAS_REFLECTION_STATIC_ENUM_HPP 4 #include <siplasplas/utility/meta.hpp> 5 #include <siplasplas/constexpr/arrayview.hpp> 6 #include <siplasplas/constexpr/meta.hpp> 13 namespace static_reflection
22 typename ConstantsNames
26 #ifndef SIPLASPLAS_DOXYGEN_RUNNING // Doxygen shit 30 EnumType... Constants,
31 typename... ConstantsNames
36 ::cpp::meta::list<std::integral_constant<EnumType, Constants>...>,
37 ::cpp::meta::list<ConstantsNames...>
50 #endif // SIPLASPLAS_DOXYGEN_RUNNING 72 using names_array_t = std::array<
const char*,
sizeof...(ConstantsNames)>;
78 constexpr
Enum() =
default;
83 static constexpr std::size_t
count()
85 static_assert(
sizeof...(Constants) ==
sizeof...(ConstantsNames),
"");
86 return sizeof...(Constants);
106 return ::cpp::constexp::PackToArray<EnumType, Constants...>::get();
128 static constexpr EnumType
value(std::size_t i)
155 static constexpr
const char*
name(std::size_t i)
177 return _toString(value, 0);
194 return _fromString(name, 0);
209 return _has(name, 0);
219 return _has(value, 0);
223 static constexpr std::array<
const char*,
sizeof...(ConstantsNames)> _namesArray = {{
224 ::cpp::constexp::SequenceToString<ConstantsNames>::c_str()...
227 static constexpr
bool streq(
const char* lhs,
const char* rhs)
229 return ((*rhs and *lhs) ? (*lhs == *rhs) and streq(lhs + 1, rhs + 1) : (not *lhs and not *rhs));
232 static constexpr
const char* _toString(
const EnumType
value, std::size_t i)
234 return (i <
sizeof...(Constants)) ?
240 static constexpr EnumType _fromString(
const char*
name, std::size_t i)
242 return (i <
sizeof...(ConstantsNames)) ?
245 static_cast<EnumType>(std::numeric_limits<
typename std::underlying_type<EnumType>::type>::
max());
248 static constexpr
bool _has(
const char* name, std::size_t i)
250 return (i <
sizeof...(ConstantsNames)) && (streq(name,
Enum::name(i)) || _has(name, i + 1));
253 static constexpr
bool _has(
const UnderlyingType value, std::size_t i)
259 template<
typename SourceInfo,
typename EnumType, EnumType... Constants,
typename... ConstantsNames>
260 constexpr
typename Enum<
263 ::cpp::meta::list<std::integral_constant<EnumType, Constants>...>,
264 ::cpp::meta::list<ConstantsNames...>
268 ::cpp::meta::list<std::integral_constant<EnumType, Constants>...>,
269 ::cpp::meta::list<ConstantsNames...>
277 template<
typename EnumType>
279 static_reflection::meta::EmptySourceInfo<Enum<EnumType>>,
282 std::integral_constant<EnumType, static_cast<EnumType>(0)>
285 ::cpp::meta::string<>
302 template<
typename EnumType>
303 class Enum :
public codegen::Enum<EnumType>
308 #endif // SIPLASPLAS_REFLECTION_STATIC_ENUM_HPP
Definition: canary_allocator.hpp:7
constexpr const T & max(const T &lhs, const T &rhs)
Returns the greatest value of the two given.
Definition: algorithm.hpp:212
Returns static reflection information of the given enumeration type.
Definition: enum.hpp:303