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