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