Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
Value.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
5
6
7 == GNU General Public License Usage ==
8
9 OpenFLUID is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OpenFLUID is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23 == Other Usage ==
24
25 Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26 license, and requires a written agreement between You and INRA.
27 Licensees for Other Usage of OpenFLUID may use this file in accordance
28 with the terms contained in the written agreement between You and INRA.
29
30*/
31
32
33/**
34 @file Value.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38
39
40#ifndef __OPENFLUID_CORE_VALUE_HPP__
41#define __OPENFLUID_CORE_VALUE_HPP__
42
43
46
47
48namespace openfluid { namespace core {
49
50class NullValue;
51class BooleanValue;
52class DoubleValue;
53class IntegerValue;
54class StringValue;
55
56class VectorValue;
57class MatrixValue;
58class MapValue;
59class TreeValue;
60
61
63{
64 public:
65
66 enum Type { NONE, BOOLEAN, INTEGER, DOUBLE, STRING, VECTOR, MATRIX, MAP, TREE, NULLL };
67
68 Value() = default;
69
70 Value(const Value&) = default;
71
72 Value(Value&&) = default;
73
74 /**
75 Assignment operator
76 */
77 virtual Value& operator=(const Value&)
78 {
79 return *this;
80 }
81
82 /**
83 Move operator
84 */
85 virtual Value& operator=(Value&&)
86 {
87 return *this;
88 }
89
90 virtual ~Value() = default;
91
92 virtual Type getType() const = 0;
93
94 virtual Value* clone() const
95 {
96 throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Value is not cloneable");
97 }
98
99 virtual bool convert(Value&) const
100 {
101 return false;
102 }
103
104 virtual bool isSimple() const = 0;
105
106 virtual bool isCompound() const = 0;
107
108 virtual void writeToStream(std::ostream& OutStm) const = 0;
109
110 virtual void writeQuotedToStream(std::ostream& OutStm) const = 0;
111
112 friend std::ostream& operator<<(std::ostream& OutStm, const Value& Val)
113 {
114 Val.writeToStream(OutStm);
115 return OutStm;
116 }
117
118 /**
119 Returns true if the Value is a DoubleValue
120 */
121 inline bool isDoubleValue() const
122 {
123 return getType() == Value::DOUBLE;
124 }
125
126 /**
127 Returns the value as a constant DoubleValue if the value is of the DoubleValue type
128 @return the value as a constant DoubleValue
129 @throw openfluid::base::FrameworkException if the value is not of the DoubleValue type
130 */
132
133 /**
134 Returns the value as a DoubleValue if the value is of the DoubleValue type
135 @return the value as a DoubleValue
136 @throw openfluid::base::FrameworkException if the value is not of the DoubleValue type
137 */
139
140 /**
141 Returns true if the value is an IntegerValue
142 */
143 inline bool isIntegerValue() const
144 {
145 return getType() == Value::INTEGER;
146 }
147
148 /**
149 Returns the value as a constant IntegerValue if the value is of the IntegerValue type
150 @return the value as a constant IntegerValue
151 @throw openfluid::base::FrameworkException if the value is not of the IntegerValue type
152 */
154
155 /**
156 Returns the value as a IntegerValue if the value is of the IntegerValue type
157 @return the value as a IntegerValue
158 @throw openfluid::base::FrameworkException if the value is not of the IntegerValue type
159 */
161
162 /**
163 Returns true if the value is a BooleanValue
164 */
165 inline bool isBooleanValue() const
166 {
167 return getType() == Value::BOOLEAN;
168 }
169
170 /**
171 Returns the value as a constant BooleanValue if the value is of the BooleanValue type
172 @return the value as a constant BooleanValue
173 @throw openfluid::base::FrameworkException if the value is not of the BooleanValue type
174 */
176
177 /**
178 Returns the value as a BooleanValue if the value is of the BooleanValue type
179 @return the value as a BooleanValue
180 @throw openfluid::base::FrameworkException if the value is not of the BooleanValue type
181 */
183
184 /**
185 Returns true if the value is a StringValue
186 */
187 inline bool isStringValue() const
188 {
189 return getType() == Value::STRING;
190 }
191
192 /**
193 Returns the value as a constant StringValue if the value is of the StringValue type
194 @return the value as a constant StringValue
195 @throw openfluid::base::FrameworkException if the value is not of the StringValue type
196 */
198
199 /**
200 Returns the value as a StringValue if the value is of the StringValue type
201 @return the value as a StringValue
202 @throw openfluid::base::FrameworkException if the value is not of the StringValue type
203 */
205
206 /**
207 Returns true if the value is a NullValue
208 */
209 inline bool isNullValue() const
210 {
211 return getType() == Value::NULLL;
212 }
213
214 /**
215 Returns the value as a constant NullValue if the value is of the NullValue type
216 @return the value as a constant NullValue
217 @throw openfluid::base::FrameworkException if the value is not of the NullValue type
218 */
219 const NullValue& asNullValue() const;
220
221 /**
222 Returns the value as a NullValue if the value is of the NullValue type
223 @return the value as a NullValue
224 @throw openfluid::base::FrameworkException if the value is not of the NullValue type
225 */
227
228 /**
229 Returns true if the value is a VectorValue
230 */
231 inline bool isVectorValue() const
232 {
233 return getType() == Value::VECTOR;
234 }
235
236 /**
237 Returns the value as a constant VectorValue if the value is of the VectorValue type
238 @return the value as a constant VectorValue
239 @throw openfluid::base::FrameworkException if the value is not of the VectorValue type
240 */
242
243 /**
244 Returns the value as a VectorValue if the value is of the VectorValue type
245 @return the value as a VectorValue
246 @throw openfluid::base::FrameworkException if the value is not of the VectorValue type
247 */
249
250 /**
251 Returns true if the value is a MatrixValue
252 */
253 inline bool isMatrixValue() const
254 {
255 return getType() == Value::MATRIX;
256 }
257
258 /**
259 Returns the value as a constant MatrixValue if the value is of the MatrixValue type
260 @return the value as a constant MatrixValue
261 @throw openfluid::base::FrameworkException if the value is not of the MatrixValue type
262 */
264
265 /**
266 Returns the value as a MatrixValue if the value is of the MatrixValue type
267 @return the value as a MatrixValue
268 @throw openfluid::base::FrameworkException if the value is not of the MatrixValue type
269 */
271
272 /**
273 Returns true if the value is a MapValue
274 */
275 inline bool isMapValue() const
276 {
277 return getType() == Value::MAP;
278 }
279
280 /**
281 Returns the value as a constant MapValue if the value is of the MapValue type
282 @return the value as a constant MapValue
283 @throw openfluid::base::FrameworkException if the value is not of the MapValue type
284 */
285 const MapValue& asMapValue() const;
286
287 /**
288 Returns the value as a MapValue if the value is of the MapValue type
289 @return the value as a MapValue
290 @throw openfluid::base::FrameworkException if the value is not of the MapValue type
291 */
293
294 /**
295 Returns true if the value is a TreeValue
296 */
297 inline bool isTreeValue() const
298 {
299 return getType() == Value::TREE;
300 }
301
302 /**
303 Returns the value as a constant TreeValue if the value is of the TreeValue type
304 @return the value as a constant TreeValue
305 @throw openfluid::base::FrameworkException if the value is not of the TreeValue type
306 */
307 const TreeValue& asTreeValue() const;
308
309 /**
310 Returns the value as a TreeValue if the value is of the TreeValue type
311 @return the value as a TreeValue
312 @throw openfluid::base::FrameworkException if the value is not of the TreeValue type
313 */
315
316 /**
317 Returns the value as a string
318 */
319 std::string toString() const;
320
321 /**
322 Gets the value type ciorresponding to the name of the type
323 @param[in] ValueTypeString The type name as a string
324 @param[out] ValueType The value type
325 @return false if the type name does not exist or is misspelled, true otherwise
326 */
327 static bool getValueTypeFromString(const std::string& ValueTypeString, Value::Type& ValueType);
328
329 /**
330 Returns the name of the type corresponding to the given type
331 @param[in] ValueType The value type
332 @return the type name
333 */
334 static std::string getStringFromValueType(const Value::Type ValueType);
335
336};
337
338
339} } // namespaces
340
341
342#endif /* __OPENFLUID_CORE_VALUE_HPP__ */
Definition FrameworkException.hpp:51
Definition BooleanValue.hpp:81
Definition DoubleValue.hpp:81
Definition IntegerValue.hpp:80
Definition MapValue.hpp:93
Definition MatrixValue.hpp:85
Definition NullValue.hpp:66
Definition StringValue.hpp:83
Definition TreeValue.hpp:66
Definition Value.hpp:63
virtual bool isCompound() const =0
virtual bool convert(Value &) const
Definition Value.hpp:99
IntegerValue & asIntegerValue()
bool isMapValue() const
Definition Value.hpp:275
virtual Value * clone() const
Definition Value.hpp:94
virtual void writeToStream(std::ostream &OutStm) const =0
const MapValue & asMapValue() const
bool isDoubleValue() const
Definition Value.hpp:121
const IntegerValue & asIntegerValue() const
MatrixValue & asMatrixValue()
const TreeValue & asTreeValue() const
bool isVectorValue() const
Definition Value.hpp:231
virtual Type getType() const =0
bool isIntegerValue() const
Definition Value.hpp:143
bool isBooleanValue() const
Definition Value.hpp:165
const NullValue & asNullValue() const
virtual Value & operator=(const Value &)
Definition Value.hpp:77
bool isStringValue() const
Definition Value.hpp:187
const BooleanValue & asBooleanValue() const
virtual Value & operator=(Value &&)
Definition Value.hpp:85
static bool getValueTypeFromString(const std::string &ValueTypeString, Value::Type &ValueType)
bool isMatrixValue() const
Definition Value.hpp:253
const MatrixValue & asMatrixValue() const
virtual ~Value()=default
Value(Value &&)=default
friend std::ostream & operator<<(std::ostream &OutStm, const Value &Val)
Definition Value.hpp:112
DoubleValue & asDoubleValue()
StringValue & asStringValue()
Value(const Value &)=default
const StringValue & asStringValue() const
MapValue & asMapValue()
BooleanValue & asBooleanValue()
bool isTreeValue() const
Definition Value.hpp:297
VectorValue & asVectorValue()
Type
Definition Value.hpp:66
@ BOOLEAN
Definition Value.hpp:66
virtual bool isSimple() const =0
NullValue & asNullValue()
bool isNullValue() const
Definition Value.hpp:209
static std::string getStringFromValueType(const Value::Type ValueType)
virtual void writeQuotedToStream(std::ostream &OutStm) const =0
TreeValue & asTreeValue()
std::string toString() const
const VectorValue & asVectorValue() const
const DoubleValue & asDoubleValue() const
Definition VectorValue.hpp:85
#define OPENFLUID_API
Definition dllexport.hpp:86
Definition ApplicationException.hpp:47