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  \brief Header of ...
37 
38  \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
39  */
40 
41 
42 #ifndef __VALUE_HPP___
43 #define __VALUE_HPP___
44 
45 #include <iostream>
46 
47 #include <openfluid/dllexport.hpp>
49 
50 
51 namespace openfluid { namespace core {
52 
53 class NullValue;
54 class BooleanValue;
55 class DoubleValue;
56 class IntegerValue;
57 class StringValue;
58 
59 class VectorValue;
60 class MatrixValue;
61 class MapValue;
62 
63 
65 {
66  public:
67 
68  enum Type { NONE, BOOLEAN, INTEGER, DOUBLE, STRING, VECTOR, MATRIX, MAP, 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*/) { return *this; }
84 
85  virtual ~Value() {};
86 
87  virtual Type getType() const = 0;
88 
89  virtual Value* clone() const { throw openfluid::base::FrameworkException("Value::clone","Value is not cloneable"); };
90 
91  inline virtual bool isSimple() const = 0;
92 
93  inline virtual bool isCompound() const = 0;
94 
95  virtual void writeToStream(std::ostream& OutStm) const = 0;
96 
97  friend std::ostream& operator<<(std::ostream& OutStm, const Value& Val)
98  { Val.writeToStream(OutStm); return OutStm; };
99 
100  /**
101  Returns true if the Value is a DoubleValue
102  */
103  inline bool isDoubleValue() const { return getType() == Value::DOUBLE; };
104 
105  const DoubleValue& asDoubleValue() const;
106 
107  DoubleValue& asDoubleValue();
108 
109  /**
110  Returns true if the Value is an IntegerValue
111  */
112  inline bool isIntegerValue() const { return getType() == Value::INTEGER; };
113 
114  const IntegerValue& asIntegerValue() const;
115 
116  IntegerValue& asIntegerValue();
117 
118  /**
119  Returns true if the Value is a BooleanValue
120  */
121  inline bool isBooleanValue() const { return getType() == Value::BOOLEAN; };
122 
123  const BooleanValue& asBooleanValue() const;
124 
125  BooleanValue& asBooleanValue();
126 
127  /**
128  Returns true if the Value is a StringValue
129  */
130  inline bool isStringValue() const { return getType() == Value::STRING; };
131 
132  const StringValue& asStringValue() const;
133 
134  StringValue& asStringValue();
135 
136  /**
137  Returns true if the Value is a NullValue
138  */
139  inline bool isNullValue() const { return getType() == Value::NULLL; };
140 
141  const NullValue& asNullValue() const;
142 
143  NullValue& asNullValue();
144 
145  /**
146  Returns true if the Value is a VectorValue
147  */
148  inline bool isVectorValue() const { return getType() == Value::VECTOR; };
149 
150  const VectorValue& asVectorValue() const;
151 
152  VectorValue& asVectorValue();
153 
154  /**
155  Returns true if the Value is a MatrixValue
156  */
157  inline bool isMatrixValue() const { return getType() == Value::MATRIX; };
158 
159  const MatrixValue& asMatrixValue() const;
160 
161  MatrixValue& asMatrixValue();
162 
163  /**
164  Returns true if the Value is a MapValue
165  */
166  inline bool isMapValue() const { return getType() == Value::MAP; };
167 
168  const MapValue& asMapValue() const;
169 
170  MapValue& asMapValue();
171 
172  /**
173  Returns the contained value as a string
174  */
175  std::string toString() const;
176 
177  static bool getValueTypeFromString(const std::string ValueTypeString, Value::Type& ValueType);
178 
179  static std::string getStringFromValueType(const Value::Type ValueType);
180 
181 };
182 
183 
184 } } // namespaces
185 
186 
187 #endif /* __VALUE_HPP___ */
Definition: Value.hpp:68
Definition: Value.hpp:68
bool isStringValue() const
Definition: Value.hpp:130
Definition: StringValue.hpp:91
Definition: Value.hpp:68
Definition: Value.hpp:68
virtual void writeToStream(std::ostream &OutStm) const =0
bool isVectorValue() const
Definition: Value.hpp:148
Definition: Value.hpp:68
Definition: IntegerValue.hpp:106
Definition: DoubleValue.hpp:103
bool isNullValue() const
Definition: Value.hpp:139
Definition: Value.hpp:68
Definition: FrameworkException.hpp:49
Definition: Value.hpp:68
Definition: MapValue.hpp:134
bool isIntegerValue() const
Definition: Value.hpp:112
virtual ~Value()
Definition: Value.hpp:85
bool isMatrixValue() const
Definition: Value.hpp:157
Definition: Value.hpp:68
Value(const Value &)
Definition: Value.hpp:78
bool isDoubleValue() const
Definition: Value.hpp:103
Definition: NullValue.hpp:59
Type
Definition: Value.hpp:68
bool isMapValue() const
Definition: Value.hpp:166
friend std::ostream & operator<<(std::ostream &OutStm, const Value &Val)
Definition: Value.hpp:97
Definition: MatrixValue.hpp:115
Definition: Value.hpp:64
bool isBooleanValue() const
Definition: Value.hpp:121
Value()
Definition: Value.hpp:73
Definition: VectorValue.hpp:119
Definition: BooleanValue.hpp:104
virtual Value * clone() const
Definition: Value.hpp:89
#define DLLEXPORT
Definition: dllexport.hpp:51