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
34namespace dealii
35{
36namespace Patterns
37{
38namespace Tools
39{
52template<typename T>
53struct Convert<T, typename std::enable_if<ExaDG::Utilities::is_enum<T>()>::type>
54{
58 static std::unique_ptr<Patterns::Selection>
60 {
61 return std::make_unique<Patterns::Selection>(ExaDG::Utilities::serialized_string<T>());
62 }
63
67 static std::string
68 to_string(T const & t, Patterns::PatternBase const & = *Convert<T>::to_pattern())
69 {
71 }
72
76 static T
77 to_value(const std::string & s, Patterns::PatternBase const & = *Convert<T>::to_pattern())
78 {
79 T value;
81 return value;
82 }
83};
84
85} // namespace Tools
86} // namespace Patterns
87} // namespace dealii
88
89
90namespace ExaDG
91{
92namespace Patterns
93{
97template<typename T>
98dealii::Patterns::Selection
99Enum()
100{
101 return *dealii::Patterns::Tools::Convert<T>::to_pattern();
102}
103
104} // namespace Patterns
105} // namespace ExaDG
106
107#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:59
static T to_value(const std::string &s, Patterns::PatternBase const &= *Convert< T >::to_pattern())
Definition enum_patterns.h:77
static std::string to_string(T const &t, Patterns::PatternBase const &= *Convert< T >::to_pattern())
Definition enum_patterns.h:68