All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 /**
35  @file Value.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_CORE_VALUE_HPP__
42 #define __OPENFLUID_CORE_VALUE_HPP__
43 
44 #include <iostream>
45 
46 #include <openfluid/dllexport.hpp>
48 
49 
50 namespace openfluid { namespace core {
51 
52 class NullValue;
53 class BooleanValue;
54 class DoubleValue;
55 class IntegerValue;
56 class StringValue;
57 
58 class VectorValue;
59 class MatrixValue;
60 class MapValue;
61 class TreeValue;
62 
63 
65 {
66  public:
67 
68  enum Type { NONE, BOOLEAN, INTEGER, DOUBLE, STRING, VECTOR, MATRIX, MAP, TREE, NULLL };
69 
70  /**
71  Default constructor
72  */
73  Value() {};
74 
75  /**
76  Copy constructor
77  */
78  Value(const Value& /*Val*/) {};
79 
80  /**
81  Assignment operator
82  */
83  virtual Value& operator =(const Value& /*Other*/)
84  { return *this; }
85 
86  virtual ~Value()
87  { };
88 
89  virtual Type getType() const = 0;
90 
91  virtual Value* clone() const
92  { throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Value is not cloneable"); };
93 
94  virtual bool convert(Value& /*Val*/) const
95  { return false; };
96 
97  virtual bool isSimple() const = 0;
98 
99  virtual bool isCompound() const = 0;
100 
101  virtual void writeToStream(std::ostream& OutStm) const = 0;
102 
103  virtual void writeQuotedToStream(std::ostream& OutStm) const = 0;
104 
105  friend std::ostream& operator<<(std::ostream& OutStm, const Value& Val)
106  { Val.writeToStream(OutStm); return OutStm; };
107 
108  /**
109  Returns true if the Value is a DoubleValue
110  */
111  inline bool isDoubleValue() const
112  { return getType() == Value::DOUBLE; };
113 
114  /**
115  Returns the value as a constant DoubleValue if the value is of the DoubleValue type
116  @return the value as a constant DoubleValue
117  @throw openfluid::base::FrameworkException if the value is not of the DoubleValue type
118  */
119  const DoubleValue& asDoubleValue() const;
120 
121  /**
122  Returns the value as a DoubleValue if the value is of the DoubleValue type
123  @return the value as a DoubleValue
124  @throw openfluid::base::FrameworkException if the value is not of the DoubleValue type
125  */
126  DoubleValue& asDoubleValue();
127 
128  /**
129  Returns true if the value is an IntegerValue
130  */
131  inline bool isIntegerValue() const
132  { return getType() == Value::INTEGER; };
133 
134  /**
135  Returns the value as a constant IntegerValue if the value is of the IntegerValue type
136  @return the value as a constant IntegerValue
137  @throw openfluid::base::FrameworkException if the value is not of the IntegerValue type
138  */
139  const IntegerValue& asIntegerValue() const;
140 
141  /**
142  Returns the value as a IntegerValue if the value is of the IntegerValue type
143  @return the value as a IntegerValue
144  @throw openfluid::base::FrameworkException if the value is not of the IntegerValue type
145  */
146  IntegerValue& asIntegerValue();
147 
148  /**
149  Returns true if the value is a BooleanValue
150  */
151  inline bool isBooleanValue() const
152  { return getType() == Value::BOOLEAN; };
153 
154  /**
155  Returns the value as a constant BooleanValue if the value is of the BooleanValue type
156  @return the value as a constant BooleanValue
157  @throw openfluid::base::FrameworkException if the value is not of the BooleanValue type
158  */
159  const BooleanValue& asBooleanValue() const;
160 
161  /**
162  Returns the value as a BooleanValue if the value is of the BooleanValue type
163  @return the value as a BooleanValue
164  @throw openfluid::base::FrameworkException if the value is not of the BooleanValue type
165  */
166  BooleanValue& asBooleanValue();
167 
168  /**
169  Returns true if the value is a StringValue
170  */
171  inline bool isStringValue() const
172  { return getType() == Value::STRING; };
173 
174  /**
175  Returns the value as a constant StringValue if the value is of the StringValue type
176  @return the value as a constant StringValue
177  @throw openfluid::base::FrameworkException if the value is not of the StringValue type
178  */
179  const StringValue& asStringValue() const;
180 
181  /**
182  Returns the value as a StringValue if the value is of the StringValue type
183  @return the value as a StringValue
184  @throw openfluid::base::FrameworkException if the value is not of the StringValue type
185  */
186  StringValue& asStringValue();
187 
188  /**
189  Returns true if the value is a NullValue
190  */
191  inline bool isNullValue() const
192  { return getType() == Value::NULLL; };
193 
194  /**
195  Returns the value as a constant NullValue if the value is of the NullValue type
196  @return the value as a constant NullValue
197  @throw openfluid::base::FrameworkException if the value is not of the NullValue type
198  */
199  const NullValue& asNullValue() const;
200 
201  /**
202  Returns the value as a NullValue if the value is of the NullValue type
203  @return the value as a NullValue
204  @throw openfluid::base::FrameworkException if the value is not of the NullValue type
205  */
206  NullValue& asNullValue();
207 
208  /**
209  Returns true if the value is a VectorValue
210  */
211  inline bool isVectorValue() const
212  { return getType() == Value::VECTOR; };
213 
214  /**
215  Returns the value as a constant VectorValue if the value is of the VectorValue type
216  @return the value as a constant VectorValue
217  @throw openfluid::base::FrameworkException if the value is not of the VectorValue type
218  */
219  const VectorValue& asVectorValue() const;
220 
221  /**
222  Returns the value as a VectorValue if the value is of the VectorValue type
223  @return the value as a VectorValue
224  @throw openfluid::base::FrameworkException if the value is not of the VectorValue type
225  */
226  VectorValue& asVectorValue();
227 
228  /**
229  Returns true if the value is a MatrixValue
230  */
231  inline bool isMatrixValue() const
232  { return getType() == Value::MATRIX; };
233 
234  /**
235  Returns the value as a constant MatrixValue if the value is of the MatrixValue type
236  @return the value as a constant MatrixValue
237  @throw openfluid::base::FrameworkException if the value is not of the MatrixValue type
238  */
239  const MatrixValue& asMatrixValue() const;
240 
241  /**
242  Returns the value as a MatrixValue if the value is of the MatrixValue type
243  @return the value as a MatrixValue
244  @throw openfluid::base::FrameworkException if the value is not of the MatrixValue type
245  */
246  MatrixValue& asMatrixValue();
247 
248  /**
249  Returns true if the value is a MapValue
250  */
251  inline bool isMapValue() const
252  { return getType() == Value::MAP; };
253 
254  /**
255  Returns the value as a constant MapValue if the value is of the MapValue type
256  @return the value as a constant MapValue
257  @throw openfluid::base::FrameworkException if the value is not of the MapValue type
258  */
259  const MapValue& asMapValue() const;
260 
261  /**
262  Returns the value as a MapValue if the value is of the MapValue type
263  @return the value as a MapValue
264  @throw openfluid::base::FrameworkException if the value is not of the MapValue type
265  */
266  MapValue& asMapValue();
267 
268  /**
269  Returns true if the value is a TreeValue
270  */
271  inline bool isTreeValue() const
272  { return getType() == Value::TREE; };
273 
274  /**
275  Returns the value as a constant TreeValue if the value is of the TreeValue type
276  @return the value as a constant TreeValue
277  @throw openfluid::base::FrameworkException if the value is not of the TreeValue type
278  */
279  const TreeValue& asTreeValue() const;
280 
281  /**
282  Returns the value as a TreeValue if the value is of the TreeValue type
283  @return the value as a TreeValue
284  @throw openfluid::base::FrameworkException if the value is not of the TreeValue type
285  */
286  TreeValue& asTreeValue();
287 
288  /**
289  Returns the value as a string
290  */
291  std::string toString() const;
292 
293  /**
294  Gets the value type ciorresponding to the name of the type
295  @param[in] ValueTypeString The type name as a string
296  @param[out] ValueType The value type
297  @return false if the type name does not exist or is misspelled, true otherwise
298  */
299  static bool getValueTypeFromString(const std::string& ValueTypeString, Value::Type& ValueType);
300 
301  /**
302  Returns the name of the type corresponding to the given type
303  @param[in] ValueType The value type
304  @return the type name
305  */
306  static std::string getStringFromValueType(const Value::Type ValueType);
307 
308 };
309 
310 
311 } } // namespaces
312 
313 
314 #endif /* __OPENFLUID_CORE_VALUE_HPP__ */
Value(const Value &)
Definition: Value.hpp:78
Definition: VectorValue.hpp:118
bool isMatrixValue() const
Definition: Value.hpp:231
friend std::ostream & operator<<(std::ostream &OutStm, const Value &Val)
Definition: Value.hpp:105
Definition: NullValue.hpp:58
Definition: TreeValue.hpp:52
virtual bool convert(Value &) const
Definition: Value.hpp:94
Definition: Value.hpp:68
Definition: Value.hpp:68
Definition: Value.hpp:68
bool isBooleanValue() const
Definition: Value.hpp:151
virtual Value * clone() const
Definition: Value.hpp:91
Definition: Value.hpp:68
Definition: Value.hpp:64
Definition: Value.hpp:68
Definition: Value.hpp:68
Definition: MapValue.hpp:134
Definition: DoubleValue.hpp:102
bool isStringValue() const
Definition: Value.hpp:171
Definition: FrameworkException.hpp:50
bool isNullValue() const
Definition: Value.hpp:191
bool isIntegerValue() const
Definition: Value.hpp:131
Value()
Definition: Value.hpp:73
Definition: BooleanValue.hpp:103
Definition: Value.hpp:68
bool isMapValue() const
Definition: Value.hpp:251
virtual void writeToStream(std::ostream &OutStm) const =0
Definition: Value.hpp:68
Definition: StringValue.hpp:91
Definition: Value.hpp:68
bool isTreeValue() const
Definition: Value.hpp:271
Type
Definition: Value.hpp:68
virtual ~Value()
Definition: Value.hpp:86
Definition: MatrixValue.hpp:114
#define OPENFLUID_API
Definition: dllexport.hpp:87
bool isDoubleValue() const
Definition: Value.hpp:111
Definition: IntegerValue.hpp:105
bool isVectorValue() const
Definition: Value.hpp:211