21template <
typename EnumType>
23 return std::size_t(x) < std::size_t(EnumType::FINAL);
34template <
typename EnumType>
constexpr
36 const std::string_view strchars)
noexcept {
37 std::array<std::string_view, size_t(EnumType::FINAL)> out;
40 std::string_view::size_type N0 = 0;
43 for (
auto& str: out) {
45 const std::string_view::size_type
N1 =
46 std::min(strchars.find(
',', N0), strchars.size());
49 str = strchars.substr(N0,
N1 - N0);
68template <
typename EnumType>
constexpr
70 std::array<EnumType, size_t(EnumType::FINAL)> out{};
71 for (
size_t i = 0; i < size_t(EnumType::FINAL); i++)
82template <
typename EnumType,
typename ... Messages>
constexpr
135#define ENUMCLASS(ENUMTYPE, TYPE, ...) \
136 enum class ENUMTYPE : TYPE { __VA_ARGS__, FINAL }; \
138 namespace enumstrs { \
139 constexpr auto ENUMTYPE##Names = enum_strarray<ENUMTYPE>(#__VA_ARGS__); \
142 namespace enumtyps { \
144 constexpr auto ENUMTYPE##Types = enum_typarray<ENUMTYPE>(); \
147 constexpr std::string_view toString(ENUMTYPE x) noexcept { \
149 return enumstrs::ENUMTYPE##Names[(TYPE)x]; \
150 return "BAD " #ENUMTYPE; \
153 constexpr ENUMTYPE to##ENUMTYPE(const std::string_view x) noexcept { \
154 for (TYPE i = 0; i < (TYPE)ENUMTYPE::FINAL; i++) \
155 if (enumstrs::ENUMTYPE##Names[i] == x) return ENUMTYPE(i); \
156 return ENUMTYPE::FINAL; \
159 constexpr ENUMTYPE to##ENUMTYPE##OrThrow(const std::string_view x) { \
160 ENUMTYPE out = to##ENUMTYPE(x); \
161 check_enum_error(out, "Cannot understand argument: \"", x, "\"\n" \
162 "Valid " #ENUMTYPE " options are: [" \
167 inline std::ostream &operator<<(std::ostream &os, const ENUMTYPE x) { \
168 return os << toString(x); \
171 inline std::istream &operator>>(std::istream &is, ENUMTYPE &x) { \
174 x = to##ENUMTYPE##OrThrow(val); \
Helper macros for debugging.
#define ARTS_USER_ERROR_IF(condition,...)
constexpr std::array< EnumType, size_t(EnumType::FINAL)> enum_typarray() noexcept
A list of all enum types by index-conversion.
constexpr void check_enum_error(EnumType type, Messages ... args)
Checks if the enum class type is good and otherwise throws an error message composed by variadic inpu...
constexpr std::array< std::string_view, size_t(EnumType::FINAL)> enum_strarray(const std::string_view strchars) noexcept
Internal string view array generator.
constexpr bool good_enum(EnumType x) noexcept
Checks if the enum number is good.
constexpr int isspace(int ch) noexcept
Returns 1 if x is a standard space-character.