include/meltpooldg/utilities/enum.hpp Source File

Developer Documentation: include/meltpooldg/utilities/enum.hpp Source File
Developer Documentation
enum.hpp
Go to the documentation of this file.
1#pragma once
2#include <deal.II/base/parameter_handler.h>
3#include <deal.II/base/patterns.h>
4
5#include <meltpooldg/utilities/better_enum.hpp>
6
7#include <boost/algorithm/string/join.hpp>
8
9#include <sstream>
10#include <string>
11
13{
17 template <typename T>
19 {
20 private:
21 static void
22 detect(...);
23
24 template <typename U>
25 static decltype(std::declval<U const>()._values())
26 detect(const U &);
27
28 public:
29 static const bool value = !std::is_same<void, decltype(detect(std::declval<T>()))>::value;
30 };
31
35 template <typename T>
37 {
38 private:
39 static void
40 detect(...);
41
42 template <typename U>
43 static decltype(std::declval<U const>()._to_string())
44 detect(const U &);
45
46 public:
47 static const bool value = !std::is_same<void, decltype(detect(std::declval<T>()))>::value;
48 };
49
50
54 template <typename T>
56 {
57 private:
58 static void
59 detect(...);
60
61 template <typename U>
62 static decltype(std::declval<U const>()._from_string(0))
63 detect(const U &);
64
65 public:
66 static const bool value = !std::is_same<void, decltype(detect(std::declval<T>()))>::value;
67 };
68
73 template <typename T>
79
83 template <class T>
84 struct Convert<T, typename std::enable_if<is_convertible<T>::value>::type>
85 {
89 static std::unique_ptr<Patterns::PatternBase>
91 {
92 std::vector<std::string> values;
93
94 for (const auto i : T::_values())
95 values.push_back(i._to_string());
96
97 return std::make_unique<Patterns::Selection>(boost::algorithm::join(values, "|"));
98 }
99
103 static std::string
104 to_string(const T &t, const Patterns::PatternBase & = *Convert<T>::to_pattern())
105 {
106 return t._to_string();
107 }
108
112 static T
113 to_value(const std::string &s, const Patterns::PatternBase & = *Convert<T>::to_pattern())
114 {
115 return T::_from_string(s.c_str());
116 }
117 };
118} // namespace dealii::Patterns::Tools
Definition enum.hpp:13
static T to_value(const std::string &s, const Patterns::PatternBase &= *Convert< T >::to_pattern())
Definition enum.hpp:113
static std::string to_string(const T &t, const Patterns::PatternBase &= *Convert< T >::to_pattern())
Definition enum.hpp:104
static std::unique_ptr< Patterns::PatternBase > to_pattern()
Definition enum.hpp:90
static decltype(std::declval< U const >()._from_string(0)) detect(const U &)
static const bool value
Definition enum.hpp:66
static decltype(std::declval< U const >()._to_string()) detect(const U &)
static const bool value
Definition enum.hpp:47
static decltype(std::declval< U const >()._values()) detect(const U &)
static const bool value
Definition enum.hpp:29
static const bool value
Definition enum.hpp:76