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