Typetools.hpp
Go to the documentation of this file.
1#ifndef OPM_TYPETOOLS_HPP
2#define OPM_TYPETOOLS_HPP
3#include <string>
4#include <algorithm>
5
7
8namespace Opm {
9
10enum 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
36class RawString : public std::string
37{
38public:
39
40 static std::vector<std::string> strings(const std::vector<RawString>& raw_strings) {
41 std::vector<std::string> std_strings;
42 for (const auto& rstring : raw_strings)
43 std_strings.push_back( rstring );
44 return std_strings;
45 }
46
47};
48
50 switch( x ) {
51 case type_tag::integer: return "int";
52 case type_tag::string: return "std::string";
53 case type_tag::raw_string: return "RawString";
54 case type_tag::fdouble: return "double";
55 case type_tag::uda: return "UDAValue";
56 case type_tag::unknown: return "unknown";
57 }
58 return "unknown";
59}
60
61template< typename T > type_tag get_type();
62
63template<> inline type_tag get_type< int >() {
64 return type_tag::integer;
65}
66
67template<> inline type_tag get_type< double >() {
68 return type_tag::fdouble;
69}
70
71template<> inline type_tag get_type< std::string >() {
72 return type_tag::string;
73}
74
75template<> inline type_tag get_type< RawString >() {
77}
78
79template<> inline type_tag get_type<UDAValue>() {
80 return type_tag::uda;
81}
82
83}
84
85#endif //OPM_TYPETOOLS_HPP
const char *const string
Definition: cJSON.h:170
Definition: Typetools.hpp:37
static std::vector< std::string > strings(const std::vector< RawString > &raw_strings)
Definition: Typetools.hpp:40
Definition: A.hpp:4
type_tag get_type< std::string >()
Definition: Typetools.hpp:71
type_tag
Definition: Typetools.hpp:10
type_tag get_type< double >()
Definition: Typetools.hpp:67
type_tag get_type< UDAValue >()
Definition: Typetools.hpp:79
type_tag get_type()
std::string tag_name(type_tag x)
Definition: Typetools.hpp:49
type_tag get_type< int >()
Definition: Typetools.hpp:63
type_tag get_type< RawString >()
Definition: Typetools.hpp:75
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)