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 INCLUDE_EXADG_UTILITIES_ENUM_PATTERNS_H_
23#define INCLUDE_EXADG_UTILITIES_ENUM_PATTERNS_H_
24
25#include <deal.II/base/patterns.h>
26
27#include <exadg/utilities/enum_utilities.h>
28
29#include <string>
30
31namespace dealii
32{
33namespace Patterns
34{
35namespace Tools
36{
49template<typename T>
50struct Convert<T, typename std::enable_if<ExaDG::Utilities::is_enum<T>()>::type>
51{
55 static std::unique_ptr<Patterns::Selection>
57 {
58 return std::make_unique<Patterns::Selection>(ExaDG::Utilities::serialized_string<T>());
59 }
60
64 static std::string
65 to_string(T const & t, Patterns::PatternBase const & = *Convert<T>::to_pattern())
66 {
68 }
69
73 static T
74 to_value(const std::string & s, Patterns::PatternBase const & = *Convert<T>::to_pattern())
75 {
76 T value;
78 return value;
79 }
80};
81
82} // namespace Tools
83} // namespace Patterns
84} // namespace dealii
85
86
87namespace ExaDG
88{
89namespace Patterns
90{
94template<typename T>
95dealii::Patterns::Selection
96Enum()
97{
98 return *dealii::Patterns::Tools::Convert<T>::to_pattern();
99}
100} // namespace Patterns
101} // namespace ExaDG
102
103#endif /*INCLUDE_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:75
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition enum_utilities.h:67
Definition driver.cpp:33
static std::unique_ptr< Patterns::Selection > to_pattern()
Definition enum_patterns.h:56
static T to_value(const std::string &s, Patterns::PatternBase const &= *Convert< T >::to_pattern())
Definition enum_patterns.h:74
static std::string to_string(T const &t, Patterns::PatternBase const &= *Convert< T >::to_pattern())
Definition enum_patterns.h:65