ExaDG
Toggle main menu visibility
Loading...
Searching...
No Matches
include
exadg
utilities
enum_utilities.h
1
/* ______________________________________________________________________
2
*
3
* ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4
*
5
* Copyright (C) 2021 by the ExaDG authors
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19
* ______________________________________________________________________
20
*/
21
22
#ifndef EXADG_UTILITIES_ENUM_UTILITIES_H_
23
#define EXADG_UTILITIES_ENUM_UTILITIES_H_
24
25
// C/C++
26
#include <vector>
27
28
#include <boost/algorithm/string/join.hpp>
29
#include <magic_enum/magic_enum.hpp>
30
31
// deal.II
32
#include <deal.II/base/exceptions.h>
33
34
namespace
ExaDG
35
{
39
namespace
Utilities
40
{
42
template
<
typename
Type>
43
constexpr
bool
44
is_enum
()
45
{
46
return
(std::is_enum_v<Type> or magic_enum::is_scoped_enum_v<Type>);
47
}
48
50
template
<
typename
EnumType>
51
EnumType
52
default_constructor
()
53
{
54
return
magic_enum::enum_values<EnumType>()[0];
55
}
56
58
template
<
typename
EnumType>
59
std::string
60
serialized_string
()
61
{
62
auto
const
enum_strings = magic_enum::enum_names<EnumType>();
63
64
std::vector<std::string>
const
enums_strings_vec(enum_strings.begin(), enum_strings.end());
65
return
boost::algorithm::join(enums_strings_vec,
"|"
);
66
}
67
69
template
<
typename
EnumType>
70
std::string
71
enum_to_string
(EnumType
const
enum_type)
72
{
73
return
(std::string)magic_enum::enum_name(enum_type);
74
}
75
77
template
<
typename
EnumType>
78
void
79
string_to_enum
(EnumType & enum_type, std::string
const
& enum_name)
80
{
81
auto
casted_enum = magic_enum::enum_cast<EnumType>(enum_name);
82
if
(casted_enum.has_value())
83
enum_type = casted_enum.value();
84
else
85
AssertThrow(
false
, dealii::ExcMessage(
"Could not convert string to enum."
));
86
}
87
88
}
// namespace Utilities
89
}
// namespace ExaDG
90
91
#endif
/* EXADG_UTILITIES_ENUM_UTILITIES_H_ */
ExaDG::Utilities
Definition
interpolate.h:34
ExaDG::Utilities::string_to_enum
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
ExaDG::Utilities::serialized_string
std::string serialized_string()
Returns the names of the enums joined with "|".
Definition
enum_utilities.h:60
ExaDG::Utilities::is_enum
constexpr bool is_enum()
Checks if given type is an enum or enum class.
Definition
enum_utilities.h:44
ExaDG::Utilities::default_constructor
EnumType default_constructor()
Returns the first value of EnumType. This is well-defined as compared to EnumType().
Definition
enum_utilities.h:52
ExaDG::Utilities::enum_to_string
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition
enum_utilities.h:71
ExaDG
Definition
driver.cpp:33
Generated by
1.17.0