ARTS 2.5.11 (git: 725533f0)
|
#include <algorithm>
#include <array>
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
#include "debug.h"
#include "nonstd.h"
Go to the source code of this file.
Macros | |
#define | ENUMCLASS(ENUMTYPE, TYPE, ...) |
Functions | |
template<typename EnumType > | |
constexpr bool | good_enum (EnumType x) noexcept |
Checks if the enum number is good. | |
template<typename EnumType > | |
constexpr std::array< std::string_view, size_t(EnumType::FINAL)> | enum_strarray (const std::string_view strchars) noexcept |
Internal string view array generator. | |
template<typename EnumType > | |
constexpr std::array< std::string_view, 0 > | enum_strarray () noexcept |
template<typename EnumType > | |
constexpr std::array< EnumType, size_t(EnumType::FINAL)> | enum_typarray () noexcept |
A list of all enum types by index-conversion. | |
template<typename EnumType , typename... Messages> | |
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 input. | |
#define ENUMCLASS | ( | ENUMTYPE, | |
TYPE, | |||
... | |||
) |
Enum style
Generates a "enum class ENUMTYPE : TYPE" with all the following arguments and terminated by FINAL
Additionally, will fill a local namespace "enumstrs" with a std::array<std::string_view, TYPE(ENUMTYPE::FINAL)> with all of the names in the ENUMTYPE enum class (bar FINAL)
Additionally, will fill a local namespace "enumtyps" with a std::array<ENUMTYPE, TYPE(ENUMTYPE::FINAL)> with all of the types in the ENUMTYPE enum class (bar FINAL)
Additionally, will generate a constexpr "toString" function that takes a ENUMTYPE object and returns either its partial name or "BAD ENUMTYPE" as a string_view
Additionally, will generate a constexpr "toENUMTYPE" function that takes a std::string_view and returns a corresponding ENUMTYPE object or ENUMTYPE::FINAL if the object is bad
Additionally, will generate intuitive std::istream& and std::ostream& operators
Use the "good_enum(ENUMTYPE)" template function to check if the enum class object is any good
Use check_enum_error(ENUMTYPE, message...) to throw an error composed by the variadic message if the enum value is bad
// Example: ENUMCLASS(Test, char, Value) // Generates (effectively): enum class Test : char {Value, FINAL}; namespace enumstrs { constexpr std::array<std::string_view, 1> TestNames={"Value"}; } namespace enumtyps { constexpr std::array<Test, 1> TestTypes={Test::Value}; } constexpr std::string_view toString(Test x) noexcept; constexpr Test toTest(const std::string_view& x) noexcept; inline std::ostream &operator<<(std::ostream &os, const Test x); inline std::istream &operator>>(std::istream &is, Test &x); // throws if not good_enum(x) at end
|
constexpr |
Checks if the enum class type is good and otherwise throws an error message composed by variadic input.
[in] | type | The enum class type variable |
[in] | ...args | A list of errors to print if type is bad |
Definition at line 90 of file enums.h.
References ARTS_USER_ERROR_IF, and good_enum().
Referenced by abs_linesLineShapeType(), LineShape::from_linefunctiondata(), and time_stepper_selection().
|
constexprnoexcept |
|
constexprnoexcept |
Internal string view array generator.
Automagically seperates a list by the commas in it, removing spaces before creating the named variable
[in] | strchars | A list of characters |
Definition at line 35 of file enums.h.
References nonstd::isspace().
|
constexprnoexcept |
|
constexprnoexcept |
Checks if the enum number is good.
It is good as long as it is above-equal to 0 and less than FINAL
[in] | x | An enum class defined by ENUMCLASS or similar |
Definition at line 21 of file enums.h.
Referenced by check_enum_error(), ecs_dataAddSpeciesData(), Species::find_species_index(), LineShape::from_linefunctiondata(), ArtsXMLTag::get_attribute_value(), Species::IsotopeRecord::OK(), Absorption::ReadFromArtscat5Stream(), CIARecord::SetMoleculeName(), Species::detail::spec(), Jacobian::Target::Target(), Jacobian::Target::Target(), Jacobian::Target::Target(), Jacobian::Target::TargetSubTypeOK(), Jacobian::Target::TargetTypeOK(), CompileTimeTests::testIsotopologuesAllValid(), CompileTimeTests::testShortNames(), and xml_read_from_stream().