ExaDG
Loading...
Searching...
No Matches
enum_patterns.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2022 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_PATTERNS_H_
23#define EXADG_UTILITIES_ENUM_PATTERNS_H_
24
25// deal.II
26#include <deal.II/base/patterns.h>
27
28// ExaDG
29#include <exadg/utilities/enum_utilities.h>
30
31// C/C++
32#include <string>
33
34#ifdef DEAL_II_WITH_MAGIC_ENUM
35namespace ExaDG
36{
37namespace Patterns
38{
42template<typename T>
43dealii::Patterns::List
44Enum()
45{
46 return *dealii::Patterns::Tools::Convert<T>::to_pattern();
47}
48
49} // namespace Patterns
50} // namespace ExaDG
51#else
52namespace dealii
53{
54namespace Patterns
55{
56namespace Tools
57{
70template<typename T>
71struct Convert<T, typename std::enable_if<ExaDG::Utilities::is_enum<T>()>::type>
72{
76 static std::unique_ptr<Patterns::Selection>
78 {
79 return std::make_unique<Patterns::Selection>(ExaDG::Utilities::serialized_string<T>());
80 }
81
85 static std::string
86 to_string(T const & t, Patterns::PatternBase const & = *Convert<T>::to_pattern())
87 {
89 }
90
94 static T
95 to_value(const std::string & s, Patterns::PatternBase const & = *Convert<T>::to_pattern())
96 {
97 T value;
99 return value;
100 }
101};
102
103} // namespace Tools
104} // namespace Patterns
105} // namespace dealii
106
107namespace ExaDG
108{
109namespace Patterns
110{
114template<typename T>
115dealii::Patterns::Selection
116Enum()
117{
118 return *dealii::Patterns::Tools::Convert<T>::to_pattern();
119}
120
121} // namespace Patterns
122} // namespace ExaDG
123#endif
124
125#endif /*EXADG_UTILITIES_ENUM_PATTERNS_H_*/
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
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition enum_utilities.h:71
Definition driver.cpp:33
static std::unique_ptr< Patterns::Selection > to_pattern()
Definition enum_patterns.h:77
static T to_value(const std::string &s, Patterns::PatternBase const &= *Convert< T >::to_pattern())
Definition enum_patterns.h:95
static std::string to_string(T const &t, Patterns::PatternBase const &= *Convert< T >::to_pattern())
Definition enum_patterns.h:86