core/Value.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 
00033 
00034 /**
00035   \file Value.hpp
00036   \brief Header of ...
00037 
00038   \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
00039  */
00040 
00041 
00042 #ifndef __VALUE_HPP___
00043 #define __VALUE_HPP___
00044 
00045 #include <iostream>
00046 
00047 #include <openfluid/dllexport.hpp>
00048 #include <openfluid/base/FrameworkException.hpp>
00049 
00050 
00051 namespace openfluid { namespace core {
00052 
00053 class NullValue;
00054 class BooleanValue;
00055 class DoubleValue;
00056 class IntegerValue;
00057 class StringValue;
00058 
00059 class VectorValue;
00060 class MatrixValue;
00061 class MapValue;
00062 
00063 
00064 class DLLEXPORT Value
00065 {
00066   public:
00067 
00068     enum Type { NONE, BOOLEAN, INTEGER, DOUBLE, STRING, VECTOR, MATRIX, MAP, NULLL };
00069 
00070     /**
00071       Default constructor
00072     */
00073     Value() {};
00074 
00075     /**
00076       Copy constructor
00077     */
00078     Value(const Value& /*Val*/) {};
00079 
00080     /**
00081      * Assignment operator
00082      */
00083     virtual Value& operator =(const Value& /*Other*/) { return *this; }
00084 
00085     virtual ~Value() {};
00086 
00087     virtual Type getType() const = 0;
00088 
00089     virtual Value* clone() const { throw openfluid::base::FrameworkException("Value::clone","Value is not cloneable"); };
00090 
00091     inline virtual bool isSimple() const = 0;
00092 
00093     inline virtual bool isCompound() const = 0;
00094 
00095     virtual void writeToStream(std::ostream& OutStm) const = 0;
00096 
00097     friend std::ostream& operator<<(std::ostream& OutStm, const Value& Val)
00098       { Val.writeToStream(OutStm); return OutStm; };
00099 
00100     /**
00101       Returns true if the Value is a DoubleValue
00102     */
00103     inline bool isDoubleValue() const { return getType() == Value::DOUBLE; };
00104 
00105     const DoubleValue& asDoubleValue() const;
00106 
00107     DoubleValue& asDoubleValue();
00108 
00109     /**
00110       Returns true if the Value is an IntegerValue
00111     */
00112     inline bool isIntegerValue() const { return getType() == Value::INTEGER; };
00113 
00114     const IntegerValue& asIntegerValue() const;
00115 
00116     IntegerValue& asIntegerValue();
00117 
00118     /**
00119       Returns true if the Value is a BooleanValue
00120     */
00121     inline bool isBooleanValue() const { return getType() == Value::BOOLEAN; };
00122 
00123     const BooleanValue& asBooleanValue() const;
00124 
00125     BooleanValue& asBooleanValue();
00126 
00127     /**
00128       Returns true if the Value is a StringValue
00129     */
00130     inline bool isStringValue() const { return getType() == Value::STRING; };
00131 
00132     const StringValue& asStringValue() const;
00133 
00134     StringValue& asStringValue();
00135 
00136     /**
00137       Returns true if the Value is a NullValue
00138     */
00139     inline bool isNullValue() const { return getType() == Value::NULLL; };
00140 
00141     const NullValue& asNullValue() const;
00142 
00143     NullValue& asNullValue();
00144 
00145     /**
00146       Returns true if the Value is a VectorValue
00147     */
00148     inline bool isVectorValue() const { return getType() == Value::VECTOR; };
00149 
00150     const VectorValue& asVectorValue() const;
00151 
00152     VectorValue& asVectorValue();
00153 
00154     /**
00155       Returns true if the Value is a MatrixValue
00156     */
00157     inline bool isMatrixValue() const { return getType() == Value::MATRIX; };
00158 
00159     const MatrixValue& asMatrixValue() const;
00160 
00161     MatrixValue& asMatrixValue();
00162 
00163     /**
00164       Returns true if the Value is a MapValue
00165     */
00166     inline bool isMapValue() const { return getType() == Value::MAP; };
00167 
00168     const MapValue& asMapValue() const;
00169 
00170     MapValue& asMapValue();
00171 
00172     /**
00173       Returns the contained value as a string
00174     */
00175     std::string toString() const;
00176 
00177     static bool getValueTypeFromString(const std::string ValueTypeString, Value::Type& ValueType);
00178 
00179     static std::string getStringFromValueType(const Value::Type ValueType);
00180 
00181 };
00182 
00183 
00184 } }  // namespaces
00185 
00186 
00187 #endif /* __VALUE_HPP___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines