UDAValue.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef UDA_VALUE_HPP
21#define UDA_VALUE_HPP
22
23#include <stdexcept>
24#include <vector>
25#include <string>
26#include <iosfwd>
27
29
30namespace Opm {
31
32class UDAValue {
33public:
35 explicit UDAValue(double);
36 explicit UDAValue(const std::string&);
37 explicit UDAValue(const Dimension& dim);
38 UDAValue(double data, const Dimension& dim);
39 UDAValue(const std::string& data, const Dimension& dim);
40
42
43 /*
44 The get<double>() and get<std::string>() methods will throw an
45 exception if the internal type and the template parameter disagree.
46 */
47
48 template<typename T>
49 T get() const;
50
51 /*
52 The getSI() can only be called for numerical values.
53 */
54 double getSI() const;
55 bool zero() const;
56
57 template<typename T>
58 bool is() const;
59
60 void assert_numeric() const;
61 void assert_numeric(const std::string& error_msg) const;
62 const Dimension& get_dim() const;
63
64 bool operator==(const UDAValue& other) const;
65 bool operator!=(const UDAValue& other) const;
68
69 bool is_numeric() { return numeric_value; }
70
71 template<class Serializer>
72 void serializeOp(Serializer& serializer)
73 {
74 serializer(numeric_value);
75 serializer(double_value);
76 serializer(string_value);
77 dim.serializeOp(serializer);
78 }
79
80private:
81 bool numeric_value;
82 double double_value;
83 std::string string_value;
84
85 Dimension dim;
86};
87
88std::ostream& operator<<( std::ostream& stream, const UDAValue& uda_value );
89}
90
91
92
93#endif
const char *const string
Definition: cJSON.h:170
Definition: Dimension.hpp:27
void serializeOp(Serializer &serializer)
Definition: Dimension.hpp:48
Definition: Serializer.hpp:38
Definition: UDAValue.hpp:32
void assert_numeric() const
T get() const
UDAValue(const std::string &data, const Dimension &dim)
static UDAValue serializeObject()
UDAValue(const std::string &)
const Dimension & get_dim() const
UDAValue & operator=(const std::string &value)
bool is() const
void assert_numeric(const std::string &error_msg) const
bool operator!=(const UDAValue &other) const
bool zero() const
UDAValue(double data, const Dimension &dim)
bool is_numeric()
Definition: UDAValue.hpp:69
void serializeOp(Serializer &serializer)
Definition: UDAValue.hpp:72
UDAValue(const Dimension &dim)
UDAValue(double)
UDAValue & operator=(double value)
bool operator==(const UDAValue &other) const
double getSI() const
Definition: A.hpp:4
std::ostream & operator<<(std::ostream &os, const UniformTableLinear< T > &t)
Definition: UniformTableLinear.hpp:249
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
static std::string data()
Definition: exprtk.hpp:40022