Manual for OpenFLUID 2.1.11

Value.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
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 
44 #include <openfluid/dllexport.hpp>
46 
47 
48 namespace openfluid { namespace core {
49 
50 class NullValue;
51 class BooleanValue;
52 class DoubleValue;
53 class IntegerValue;
54 class StringValue;
55 
56 class VectorValue;
57 class MatrixValue;
58 class MapValue;
59 class 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  */
131  const DoubleValue& asDoubleValue() const;
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  */
138  DoubleValue& asDoubleValue();
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  */
153  const IntegerValue& asIntegerValue() const;
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  */
160  IntegerValue& asIntegerValue();
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  */
175  const BooleanValue& asBooleanValue() const;
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  */
182  BooleanValue& asBooleanValue();
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  */
197  const StringValue& asStringValue() const;
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  */
204  StringValue& asStringValue();
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  */
226  NullValue& asNullValue();
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  */
241  const VectorValue& asVectorValue() const;
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  */
248  VectorValue& asVectorValue();
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  */
263  const MatrixValue& asMatrixValue() const;
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  */
270  MatrixValue& asMatrixValue();
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  */
292  MapValue& asMapValue();
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  */
314  TreeValue& asTreeValue();
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__ */
openfluid::core::VectorValue
Definition: VectorValue.hpp:84
openfluid::core::MatrixValue
Definition: MatrixValue.hpp:84
openfluid::core::Value::convert
virtual bool convert(Value &) const
Definition: Value.hpp:99
openfluid::core::Value::DOUBLE
@ DOUBLE
Definition: Value.hpp:66
FrameworkException.hpp
openfluid::core::Value
Definition: Value.hpp:62
OPENFLUID_API
#define OPENFLUID_API
Definition: dllexport.hpp:86
openfluid::core::Value::isMatrixValue
bool isMatrixValue() const
Definition: Value.hpp:253
openfluid::core::Value::MAP
@ MAP
Definition: Value.hpp:66
openfluid::core::Value::isStringValue
bool isStringValue() const
Definition: Value.hpp:187
openfluid::core::MapValue
Definition: MapValue.hpp:92
openfluid::core::Value::isMapValue
bool isMapValue() const
Definition: Value.hpp:275
openfluid::core::Value::TREE
@ TREE
Definition: Value.hpp:66
openfluid::core::Value::Type
Type
Definition: Value.hpp:66
openfluid::core::Value::operator=
virtual Value & operator=(Value &&)
Definition: Value.hpp:85
openfluid::core::Value::isVectorValue
bool isVectorValue() const
Definition: Value.hpp:231
openfluid::core::IntegerValue
Definition: IntegerValue.hpp:79
openfluid::core::Value::STRING
@ STRING
Definition: Value.hpp:66
openfluid::core::DoubleValue
Definition: DoubleValue.hpp:80
openfluid::core::Value::isNullValue
bool isNullValue() const
Definition: Value.hpp:209
openfluid::core::Value::writeToStream
virtual void writeToStream(std::ostream &OutStm) const =0
openfluid::core::NullValue
Definition: NullValue.hpp:65
openfluid::core::Value::isTreeValue
bool isTreeValue() const
Definition: Value.hpp:297
openfluid
Definition: ApplicationException.hpp:47
openfluid::core::Value::clone
virtual Value * clone() const
Definition: Value.hpp:94
openfluid::core::Value::VECTOR
@ VECTOR
Definition: Value.hpp:66
openfluid::core::Value::INTEGER
@ INTEGER
Definition: Value.hpp:66
openfluid::core::Value::isIntegerValue
bool isIntegerValue() const
Definition: Value.hpp:143
openfluid::core::Value::NULLL
@ NULLL
Definition: Value.hpp:66
openfluid::base::FrameworkException
Definition: FrameworkException.hpp:50
openfluid::core::BooleanValue
Definition: BooleanValue.hpp:80
openfluid::core::TreeValue
Definition: TreeValue.hpp:65
openfluid::core::Value::operator=
virtual Value & operator=(const Value &)
Definition: Value.hpp:77
dllexport.hpp
openfluid::core::Value::MATRIX
@ MATRIX
Definition: Value.hpp:66
openfluid::core::Value::operator<<
friend std::ostream & operator<<(std::ostream &OutStm, const Value &Val)
Definition: Value.hpp:112
openfluid::core::StringValue
Definition: StringValue.hpp:76
openfluid::core::Value::isDoubleValue
bool isDoubleValue() const
Definition: Value.hpp:121
openfluid::core::Value::BOOLEAN
@ BOOLEAN
Definition: Value.hpp:66
openfluid::core::Value::isBooleanValue
bool isBooleanValue() const
Definition: Value.hpp:165