DeckItem.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Statoil 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 DECKITEM_HPP
21#define DECKITEM_HPP
22
23#include <string>
24#include <vector>
25#include <memory>
26#include <ostream>
27
32
33
34namespace Opm {
35 class DeckOutput;
36
37 class DeckItem {
38 public:
39
40 DeckItem() = default;
41 DeckItem( const std::string&, int);
44 DeckItem( const std::string&, double) = delete;
45 DeckItem( const std::string&, UDAValue) = delete;
46 DeckItem( const std::string&, UDAValue, const std::vector<Dimension>& active_dim, const std::vector<Dimension>& default_dim);
47 DeckItem( const std::string&, double, const std::vector<Dimension>& active_dim, const std::vector<Dimension>& default_dim);
48
50
51 const std::string& name() const;
52
53 // return true if the default value was used for a given data point
54 bool defaultApplied( size_t ) const;
55
56 // Return true if the item has a value for the current index;
57 // does not differentiate between default values from the
58 // config and values which have been set in the deck.
59 bool hasValue( size_t ) const;
60
61 // if the number returned by this method is less than what is semantically
62 // expected (e.g. size() is less than the number of cells in the grid for
63 // keywords like e.g. SGL), then the remaining values are defaulted. The deck
64 // creates the defaulted items if all their sizes are fully specified by the
65 // keyword, though...
66
67 size_t data_size() const;
68
69 template<typename T>
70 T get( size_t index ) const;
71
72
73 double getSIDouble( size_t ) const;
75
76 template< typename T > const std::vector< T >& getData() const;
77 const std::vector< double >& getSIDoubleData() const;
78 const std::vector<value::status>& getValueStatus() const;
79
81 void push_back( int );
82 void push_back( double );
85 void push_back( UDAValue, size_t );
86 void push_back( int, size_t );
87 void push_back( double, size_t );
88 void push_back( std::string, size_t );
90 void push_backDefault( int );
91 void push_backDefault( double );
94 // trying to access the data of a "dummy default item" will raise an exception
95
96 template <typename T>
98
100
101 void write(DeckOutput& writer) const;
102 friend std::ostream& operator<<(std::ostream& os, const DeckItem& item);
103
104
105 /*
106 The comparison can be adjusted with the cmp_default and
107 cmp_numeric flags. If cmp_default is set to true the
108 comparison will take the defaulted status of the items into
109 account, i.e. two items will compare differently if one is
110 defaulted and the other has the default value explicitly
111 set. The default behaviour is cmp_default == false -
112 itrespective of whether they have been set explicitly or
113 have been defaulted.
114 */
115 bool equal(const DeckItem& other, bool cmp_default, bool cmp_numeric) const;
116
117 /*
118 The operator== is implemented based on the equal( ) method,
119 with the arguments cmp_default=false and cmp_numeric=true.
120 */
121 bool operator==(const DeckItem& other) const;
122 bool operator!=(const DeckItem& other) const;
123 static bool to_bool(std::string string_value);
124
125 bool is_uda() { return (type == get_type< UDAValue >()); };
126 bool is_double() { return type == get_type< double >(); };
127 bool is_int() { return type == get_type< int >() ; };
128 bool is_string() { return type == get_type< std::string >(); };
129
130 UDAValue& get_uda() { return uval[0]; };
131
132 template<class Serializer>
133 void serializeOp(Serializer& serializer)
134 {
135 serializer(dval);
136 serializer(ival);
137 serializer(sval);
138 serializer.vector(uval);
139 serializer(type);
140 serializer(item_name);
141 serializer.template vector<value::status, false>(value_status);
142 serializer(raw_data);
143 serializer.vector(active_dimensions);
144 serializer.vector(default_dimensions);
145 }
146
147 private:
148 mutable std::vector< double > dval;
149 std::vector< int > ival;
150 std::vector< std::string > sval;
151 std::vector< RawString > rsval;
152 std::vector< UDAValue > uval;
153
155
156 std::string item_name;
157 std::vector<value::status> value_status;
158 /*
159 To save space we mutate the dval object in place when asking for SI
160 data; the current state of of the dval member is tracked with the
161 raw_data bool member.
162 */
163 mutable bool raw_data = true;
164 std::vector< Dimension > active_dimensions;
165 std::vector< Dimension > default_dimensions;
166
167 template< typename T > std::vector< T >& value_ref();
168 template< typename T > const std::vector< T >& value_ref() const;
169 template< typename T > void push( T );
170 template< typename T > void push( T, size_t );
171 template< typename T > void push_default( T );
172 template< typename T > void write_vector(DeckOutput& writer, const std::vector<T>& data) const;
173 };
174}
175#endif /* DECKITEM_HPP */
176
int index
Definition: cJSON.h:168
cJSON * item
Definition: cJSON.h:218
const char *const string
Definition: cJSON.h:170
Definition: DeckItem.hpp:37
UDAValue & get_uda()
Definition: DeckItem.hpp:130
void push_backDefault(double)
bool operator==(const DeckItem &other) const
static bool to_bool(std::string string_value)
bool is_string()
Definition: DeckItem.hpp:128
void push_back(RawString)
bool operator!=(const DeckItem &other) const
DeckItem(const std::string &, UDAValue, const std::vector< Dimension > &active_dim, const std::vector< Dimension > &default_dim)
void write(DeckOutput &writer) const
void push_back(int)
static DeckItem serializeObject()
size_t data_size() const
void push_backDefault(std::string)
DeckItem(const std::string &, RawString)
void serializeOp(Serializer &serializer)
Definition: DeckItem.hpp:133
void push_back(UDAValue)
void push_back(double)
double getSIDouble(size_t) const
std::string getTrimmedString(size_t) const
const std::vector< double > & getSIDoubleData() const
friend std::ostream & operator<<(std::ostream &os, const DeckItem &item)
bool hasValue(size_t) const
DeckItem(const std::string &, double)=delete
DeckItem(const std::string &, UDAValue)=delete
const std::vector< T > & getData() const
const std::string & name() const
void push_back(int, size_t)
bool is_double()
Definition: DeckItem.hpp:126
void push_back(UDAValue, size_t)
void push_backDummyDefault()
DeckItem()=default
bool defaultApplied(size_t) const
const std::vector< value::status > & getValueStatus() const
bool is_uda()
Definition: DeckItem.hpp:125
DeckItem(const std::string &, int)
T get(size_t index) const
void push_back(std::string)
DeckItem(const std::string &, double, const std::vector< Dimension > &active_dim, const std::vector< Dimension > &default_dim)
bool equal(const DeckItem &other, bool cmp_default, bool cmp_numeric) const
void push_backDefault(RawString)
void push_backDefault(int)
void push_back(std::string, size_t)
DeckItem(const std::string &, std::string)
type_tag getType() const
bool is_int()
Definition: DeckItem.hpp:127
void push_backDefault(UDAValue)
void push_back(double, size_t)
Definition: DeckOutput.hpp:29
Definition: Typetools.hpp:37
Definition: Serializer.hpp:38
Definition: UDAValue.hpp:32
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< int >()
Definition: Typetools.hpp:63
static std::string data()
Definition: exprtk.hpp:40022