22#ifndef EXADG_UTILITIES_ENUM_UTILITIES_H_
23#define EXADG_UTILITIES_ENUM_UTILITIES_H_
28#include <boost/algorithm/string/join.hpp>
29#include <magic_enum/magic_enum.hpp>
32#include <deal.II/base/exceptions.h>
42template<
typename Type>
46 return (std::is_enum_v<Type> or magic_enum::is_scoped_enum_v<Type>);
50template<
typename EnumType>
54 return magic_enum::enum_values<EnumType>()[0];
58template<
typename EnumType>
62 auto const enum_strings = magic_enum::enum_names<EnumType>();
64 std::vector<std::string>
const enums_strings_vec(enum_strings.begin(), enum_strings.end());
65 return boost::algorithm::join(enums_strings_vec,
"|");
69template<
typename EnumType>
73 return (std::string)magic_enum::enum_name(enum_type);
77template<
typename EnumType>
81 auto casted_enum = magic_enum::enum_cast<EnumType>(enum_name);
82 if(casted_enum.has_value())
83 enum_type = casted_enum.value();
85 AssertThrow(
false, dealii::ExcMessage(
"Could not convert string to enum."));
Definition interpolate.h:34
void string_to_enum(EnumType &enum_type, std::string const &enum_name)
Converts a string to an enum, which is provided as first function argument.
Definition enum_utilities.h:79
std::string serialized_string()
Returns the names of the enums joined with "|".
Definition enum_utilities.h:60
constexpr bool is_enum()
Checks if given type is an enum or enum class.
Definition enum_utilities.h:44
EnumType default_constructor()
Returns the first value of EnumType. This is well-defined as compared to EnumType().
Definition enum_utilities.h:52
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition enum_utilities.h:71