My Project
Typetools.hpp
1 #ifndef OPM_TYPETOOLS_HPP
2 #define OPM_TYPETOOLS_HPP
3 #include <string>
4 #include <algorithm>
5 
6 #include <opm/input/eclipse/Deck/UDAValue.hpp>
7 
8 namespace Opm {
9 
10 enum class type_tag {
11  unknown = 0,
12  integer = 1,
13  string = 2,
14  raw_string = 3,
15  fdouble = 4,
16  uda = 5,
17 };
18 
19 /*
20  The RawString class itself is just a glorified std::string, it does not have
21  any additional data nor behavior which differentiates it from std::string, but
22  the use of a separate string class allows the compiler to differentiate
23  between different behavior for normal strings and raw strings. The special
24  behavior for raw strings is:
25 
26  1. The input data is terminated on the *last* '/' and not the first - to allow
27  '/' as part of the input.
28 
29  2. '* is not treated as a multiplier/default, but rather as a normal token.
30 
31  3. Quotes are not removed from the input, and when writing quotes are not
32  added.
33 
34 */
35 
36 class RawString : public std::string
37 {
38 public:
39 
40  static std::vector<std::string> strings(const std::vector<RawString>& raw_strings) {
41  std::vector<std::string> std_strings;
42  std_strings.reserve(raw_strings.size());
43  std::copy(raw_strings.begin(), raw_strings.end(), std::back_inserter(std_strings));
44  return std_strings;
45  }
46 
47  template<class Serializer>
48  void serializeOp(Serializer& serializer)
49  {
50  serializer(static_cast<std::string&>(*this));
51  }
52 
53 };
54 
55 inline std::string tag_name( type_tag x ) {
56  switch( x ) {
57  case type_tag::integer: return "int";
58  case type_tag::string: return "std::string";
59  case type_tag::raw_string: return "RawString";
60  case type_tag::fdouble: return "double";
61  case type_tag::uda: return "UDAValue";
62  case type_tag::unknown: return "unknown";
63  }
64  return "unknown";
65 }
66 
67 template< typename T > type_tag get_type();
68 
69 template<> inline type_tag get_type< int >() {
70  return type_tag::integer;
71 }
72 
73 template<> inline type_tag get_type< double >() {
74  return type_tag::fdouble;
75 }
76 
77 template<> inline type_tag get_type< std::string >() {
78  return type_tag::string;
79 }
80 
81 template<> inline type_tag get_type< RawString >() {
82  return type_tag::raw_string;
83 }
84 
85 template<> inline type_tag get_type<UDAValue>() {
86  return type_tag::uda;
87 }
88 
89 }
90 
91 #endif //OPM_TYPETOOLS_HPP
Definition: Typetools.hpp:37
Definition: Serializer.hpp:38
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29