core/MapValue.hpp
Go to the documentation of this file.
00001 /*
00002   This file is part of OpenFLUID software
00003   Copyright (c) 2007-2010 INRA-Montpellier SupAgro
00004 
00005 
00006  == GNU General Public License Usage ==
00007 
00008   OpenFLUID is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   OpenFLUID is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with OpenFLUID.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021   In addition, as a special exception, INRA gives You the additional right
00022   to dynamically link the code of OpenFLUID with code not covered
00023   under the GNU General Public License ("Non-GPL Code") and to distribute
00024   linked combinations including the two, subject to the limitations in this
00025   paragraph. Non-GPL Code permitted under this exception must only link to
00026   the code of OpenFLUID dynamically through the OpenFLUID libraries
00027   interfaces, and only for building OpenFLUID plugins. The files of
00028   Non-GPL Code may be link to the OpenFLUID libraries without causing the
00029   resulting work to be covered by the GNU General Public License. You must
00030   obey the GNU General Public License in all respects for all of the
00031   OpenFLUID code and other code used in conjunction with OpenFLUID
00032   except the Non-GPL Code covered by this exception. If you modify
00033   this OpenFLUID, you may extend this exception to your version of the file,
00034   but you are not obligated to do so. If you do not wish to provide this
00035   exception without modification, you must delete this exception statement
00036   from your version and license this OpenFLUID solely under the GPL without
00037   exception.
00038 
00039 
00040  == Other Usage ==
00041 
00042   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00043   license, and requires a written agreement between You and INRA.
00044   Licensees for Other Usage of OpenFLUID may use this file in accordance
00045   with the terms contained in the written agreement between You and INRA.
00046 */
00047 
00056 #ifndef __MAPVALUE_HPP__
00057 #define __MAPVALUE_HPP__
00058 
00059 
00060 #include <map>
00061 #include <boost/shared_ptr.hpp>
00062 
00063 #include <openfluid/core/CompoundValue.hpp>
00064 #include <openfluid/core/DoubleValue.hpp>
00065 #include <openfluid/core/IntegerValue.hpp>
00066 #include <openfluid/core/BooleanValue.hpp>
00067 #include <openfluid/core/StringValue.hpp>
00068 #include <openfluid/core/MatrixValue.hpp>
00069 #include <openfluid/core/VectorValue.hpp>
00070 #include <openfluid/dllexport.hpp>
00071 
00072 
00073 namespace openfluid { namespace core {
00074 
00149 class DLLEXPORT MapValue : public CompoundValue
00150 {
00151   public:
00152     typedef std::map<std::string,boost::shared_ptr<Value> > Map_t;
00153 
00154 
00155   private:
00156 
00157     Map_t m_Value;
00158 
00159   public:
00160 
00164     MapValue() : CompoundValue() {};
00165 
00169     MapValue(const MapValue& Val);
00170 
00171     MapValue(const Map_t& Val) : CompoundValue(), m_Value(Val) {};
00172 
00173     Value& operator =(const Value& Other);
00174 
00175     ~MapValue();
00176 
00177     inline Type getType() const { return Value::MAP; };
00178 
00179     Value* clone() const { return new MapValue(*this); };
00180 
00181     void writeToStream(std::ostream& OutStm) const;
00182 
00188     void set(const std::string& Key, Value* Element);
00189 
00195     inline void setDouble(const std::string& Key, const double& Val)
00196       { set(Key,new DoubleValue(Val)); };
00197 
00204     inline void setInteger(const std::string& Key, const long& Val)
00205       { set(Key,new IntegerValue(Val)); };
00206 
00212     inline void setBoolean(const std::string& Key, const bool& Val)
00213       { set(Key,new BooleanValue(Val)); };
00214 
00220     inline void setString(const std::string& Key, const std::string& Val)
00221       { set(Key,new StringValue(Val)); };
00222 
00228     inline void setVectorValue(const std::string& Key, const VectorValue& Val)
00229       { set(Key,new VectorValue(Val)); };
00230 
00236     inline void setMatrixValue(const std::string& Key, const MatrixValue& Val)
00237       { set(Key,new MatrixValue(Val)); };
00238 
00243     Value& operator[](const std::string& Key);
00244 
00250     Value& get(const std::string& Key);
00251 
00257     inline double getDouble(const std::string& Key) { return get(Key).asDoubleValue().get(); };
00258 
00264     inline long getInteger(const std::string& Key) { return get(Key).asIntegerValue().get(); };
00265 
00271     inline bool getBoolean(const std::string& Key) { return get(Key).asBooleanValue().get(); };
00272 
00278     inline std::string getString(const std::string& Key) { return get(Key).asStringValue().get(); };
00279 
00285     inline VectorValue getVectorValue(const std::string& Key) { return get(Key).asVectorValue(); };
00286 
00292     inline MatrixValue getMatrixValue(const std::string& Key) { return get(Key).asMatrixValue(); };
00293 
00298     bool remove(const std::string& Key);
00299 
00304     inline unsigned long getSize() const { return m_Value.size(); };
00305 
00310     unsigned long size() const { return m_Value.size(); };
00311 
00317     inline bool isKeyExist(const std::string& Key) const { return (m_Value.find(Key) != m_Value.end()); };
00318 
00322     void clear();
00323 
00324 };
00325 
00326 
00327 } }  // namespaces
00328 
00329 
00330 // =====================================================================
00331 // =====================================================================
00332 
00333 
00334 #endif /* __MAPVALUE_HPP__ */

Generated using Doxygen 1.7.6.1
Creative Commons License Creative Commons By-NC-ND license