www.mooseframework.org
Conversion.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #ifndef CONVERSION_H
16 #define CONVERSION_H
17 
18 // MOOSE includes
19 #include "MooseTypes.h"
20 
21 // libMesh
22 #include "libmesh/enum_order.h"
23 #include "libmesh/enum_quadrature_type.h"
24 #include "libmesh/point.h"
25 
26 // Forward declarations
27 class MultiMooseEnum;
28 
29 namespace Moose
30 {
31 // Scalar conversions
32 template <typename T>
33 T stringToEnum(const std::string & s);
34 
35 template <>
36 ExecFlagType stringToEnum<ExecFlagType>(const std::string & s);
37 
38 template <>
39 QuadratureType stringToEnum<QuadratureType>(const std::string & s);
40 
41 template <>
42 Order stringToEnum<Order>(const std::string & s);
43 
44 template <>
46 
47 template <>
48 SolveType stringToEnum<SolveType>(const std::string & s);
49 
50 template <>
51 LineSearchType stringToEnum<LineSearchType>(const std::string & s);
52 
53 template <>
55 
56 // Vector conversions
57 template <typename T>
58 std::vector<T> vectorStringsToEnum(const MultiMooseEnum & v);
59 
60 template <>
61 std::vector<ExecFlagType> vectorStringsToEnum<ExecFlagType>(const MultiMooseEnum & v);
62 
64 template <typename T>
65 std::string
66 stringify(const T & t)
67 {
68  std::ostringstream os;
69  os << t;
70  return os.str();
71 }
72 
74 std::string stringify(const SolveType & t);
75 
77 std::string stringify(const ExecFlagType & t);
78 
80 std::string stringify(const std::string & s);
81 
83 template <typename T, typename U>
84 std::string
85 stringify(const std::pair<T, U> & p)
86 {
87  return stringify(p.first) + ':' + stringify(p.second);
88 }
89 
91 template <template <typename...> class T, typename... U>
92 std::string
93 stringify(const T<U...> & c, const std::string & delim = ",")
94 {
95  std::string str;
96  const auto begin = c.begin(), end = c.end();
97  for (auto i = begin; i != end; ++i)
98  str += (i != begin ? delim : "") + stringify(*i);
99  return str;
100 }
101 
106 std::string stringifyExact(Real);
107 }
108 
114 Point toPoint(const std::vector<Real> & pos);
115 
116 #endif // CONVERSION_H
T stringToEnum(const std::string &s)
Definition: Conversion.C:193
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition: Conversion.C:236
TimeIntegratorType stringToEnum< TimeIntegratorType >(const std::string &s)
Definition: Conversion.C:326
Order stringToEnum< Order >(const std::string &s)
Definition: Conversion.C:223
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips...
Definition: Conversion.C:422
ExecFlagType stringToEnum< ExecFlagType >(const std::string &s)
LineSearchType
Type of the line search.
Definition: MooseTypes.h:326
Point toPoint(const std::vector< Real > &pos)
Convert point represented as std::vector into Point.
Definition: Conversion.C:434
QuadratureType stringToEnum< QuadratureType >(const std::string &s)
Definition: Conversion.C:208
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition: Conversion.C:311
SolveType stringToEnum< SolveType >(const std::string &s)
Definition: Conversion.C:251
CoordinateSystemType
Definition: MooseTypes.h:212
std::vector< T > vectorStringsToEnum(const MultiMooseEnum &v)
TimeIntegratorType
Time integrators.
Definition: MooseTypes.h:304
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
Definition: Moose.h:84
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
SolveType
Type of the solve.
Definition: MooseTypes.h:245
std::vector< ExecFlagType > vectorStringsToEnum< ExecFlagType >(const MultiMooseEnum &v)
Definition: Conversion.C:356