22#ifndef INCLUDE_EXADG_UTILITIES_ENUM_UTILITIES_H_
23#define INCLUDE_EXADG_UTILITIES_ENUM_UTILITIES_H_
27#include <boost/algorithm/string/join.hpp>
28#include <magic_enum/magic_enum.hpp>
30#include <deal.II/base/exceptions.h>
40template<
typename Type>
44 return (std::is_enum_v<Type> or magic_enum::is_scoped_enum_v<Type>);
48template<
typename EnumType>
52 return magic_enum::enum_values<EnumType>()[0];
56template<
typename EnumType>
60 auto const enum_strings = magic_enum::enum_names<EnumType>();
62 std::vector<std::string>
const enums_strings_vec(enum_strings.begin(), enum_strings.end());
63 return boost::algorithm::join(enums_strings_vec,
"|");
67template<
typename EnumType>
71 return (std::string)magic_enum::enum_name(enum_type);
75template<
typename EnumType>
79 auto casted_enum = magic_enum::enum_cast<EnumType>(enum_name);
80 if(casted_enum.has_value())
81 enum_type = casted_enum.value();
83 AssertThrow(
false, dealii::ExcMessage(
"Could not convert string to enum."));
Definition interpolate.h:32
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:77
std::string serialized_string()
Returns the names of the enums joined with "|".
Definition enum_utilities.h:58
constexpr bool is_enum()
Checks if given type is an enum or enum class.
Definition enum_utilities.h:42
EnumType default_constructor()
Returns the first value of EnumType. This is well-defined as compared to EnumType().
Definition enum_utilities.h:50
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition enum_utilities.h:69