1 #ifndef SIPLASPLAS_REFLECTION_STATIC_ENUM_HPP     2 #define SIPLASPLAS_REFLECTION_STATIC_ENUM_HPP     4 #include <siplasplas/utility/meta.hpp>    11 namespace static_reflection
    20     typename ConstantsNames
    24 #ifndef SIPLASPLAS_DOXYGEN_RUNNING // Doxygen shit    28     EnumType... Constants,
    29     typename... ConstantsNames
    34     ::cpp::meta::list<std::integral_constant<EnumType, Constants>...>,
    35     ::cpp::meta::list<ConstantsNames...>
    48 #endif // SIPLASPLAS_DOXYGEN_RUNNING    70     using names_array_t  = std::array<
const char*, 
sizeof...(ConstantsNames)>;
    76     constexpr 
Enum() = 
default;
    81     static constexpr std::size_t 
count()
    83         static_assert(
sizeof...(Constants) == 
sizeof...(ConstantsNames), 
"");
    84         return sizeof...(Constants);
   104         return ::cpp::meta::PackToArray<EnumType, Constants...>::get();
   126     static constexpr EnumType 
value(std::size_t i)
   153     static constexpr 
const char* 
name(std::size_t i)
   175         return _toString(value, 0);
   192         return _fromString(name, 0);
   207         return _has(name, 0);
   217         return _has(value, 0);
   221     static constexpr std::array<
const char*, 
sizeof...(ConstantsNames)> _namesArray = {{::cpp::meta::StringToArray<ConstantsNames>::c_str()...}};
   222     static constexpr 
bool streq(
const char* lhs, 
const char* rhs)
   224         return ((*rhs and *lhs) ? (*lhs == *rhs) and streq(lhs + 1, rhs + 1) : (not *lhs and not *rhs));
   227     static constexpr 
const char* _toString(
const EnumType 
value, std::size_t i)
   229         return (i < 
sizeof...(Constants)) ?
   235     static constexpr EnumType _fromString(
const char* 
name, std::size_t i)
   237         return (i < 
sizeof...(ConstantsNames)) ?
   240             static_cast<EnumType>(std::numeric_limits<
typename std::underlying_type<EnumType>::type>::max());
   243     static constexpr 
bool _has(
const char* name, std::size_t i)
   245         return (i < 
sizeof...(ConstantsNames)) && (streq(name, 
Enum::name(i)) || _has(name, i + 1));
   248     static constexpr 
bool _has(
const UnderlyingType value, std::size_t i)
   254 template<
typename SourceInfo, 
typename EnumType, EnumType... Constants, 
typename... ConstantsNames>
   255 constexpr 
typename Enum<
   258     ::cpp::meta::list<std::integral_constant<EnumType, Constants>...>,
   259     ::cpp::meta::list<ConstantsNames...>
   263     ::cpp::meta::list<std::integral_constant<EnumType, Constants>...>,
   264     ::cpp::meta::list<ConstantsNames...>
   272 template<
typename EnumType>
   274     static_reflection::meta::EmptySourceInfo<Enum<EnumType>>,
   277         std::integral_constant<EnumType, static_cast<EnumType>(0)>
   280         ::cpp::meta::string<>
   297 template<
typename EnumType>
   298 class Enum : 
public codegen::Enum<EnumType>
   303 #endif // SIPLASPLAS_REFLECTION_STATIC_ENUM_HPP 
Definition: canary_allocator.hpp:7
 
Returns static reflection information of the given enumeration type. 
Definition: enum.hpp:298