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 StringValue.hpp 00036 \brief Header of ... 00037 00038 \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr> 00039 */ 00040 00041 00042 #ifndef __STRINGVALUE_HPP___ 00043 #define __STRINGVALUE_HPP___ 00044 00045 00046 #include <string> 00047 #include <vector> 00048 00049 #include <openfluid/core/SimpleValue.hpp> 00050 00051 #include <openfluid/dllexport.hpp> 00052 00053 00054 00055 namespace openfluid { namespace core { 00056 /** 00057 StringValue is a container for a std::string value, with methods for conversion to other containers derived from Value.\n 00058 00059 \see Value 00060 00061 \n 00062 00063 <I>Example : declaration</I> 00064 @code 00065 // declaration of a StringValue, initialized to an empty string by default 00066 openfluid::core::StringValue Val1; 00067 00068 // declaration of a StringValue, initialized to "hello world" 00069 openfluid::core::StringValue Val2("hello world"); 00070 @endcode 00071 00072 00073 <I>Example : getting the contained value</I> 00074 @code 00075 std::string Tmp1; 00076 00077 // using the get method 00078 Tmp1 = Val1.get(); 00079 00080 // or using the cast operator 00081 Tmp1 = Val1; 00082 @endcode 00083 00084 00085 <I>Example : setting the contained value</I> 00086 @code 00087 // using the set method 00088 Val1.set("Have a nice day"); 00089 @endcode 00090 */ 00091 class DLLEXPORT StringValue : public SimpleValue 00092 { 00093 private: 00094 00095 std::string m_Value; 00096 00097 static bool convertStringToDouble(const std::string& Str, double& Dbl); 00098 00099 static std::vector<std::string> splitString(const std::string& StrToSplit, 00100 const std::string& Separators, 00101 bool ReturnsEmpty = false); 00102 00103 std::vector<std::string> split(const std::string& Separators, 00104 bool ReturnsEmpty = false) const; 00105 00106 public: 00107 00108 /** 00109 Default constructor 00110 */ 00111 StringValue() : m_Value("") {}; 00112 00113 /** 00114 Copy constructor 00115 */ 00116 StringValue(const StringValue& Val) : SimpleValue(Val), m_Value(Val.m_Value) {}; 00117 00118 /** 00119 Constructor from plain old type 00120 */ 00121 StringValue(const std::string& POD) : SimpleValue(), m_Value(POD) {}; 00122 00123 Value& operator =(const Value& Other); 00124 00125 /** 00126 * Cast operator 00127 */ 00128 operator std::string() const { return m_Value; }; 00129 00130 virtual ~StringValue() {}; 00131 00132 inline Type getType() const { return Value::STRING; }; 00133 00134 Value* clone() const { return new StringValue(*this); }; 00135 00136 /** 00137 Returns the string value as plain old type 00138 @return the string value 00139 */ 00140 inline std::string& get() { return m_Value; }; 00141 00142 /** 00143 Returns the string value as a const plain old type 00144 @return the string value 00145 */ 00146 inline const std::string& get() const { return m_Value; }; 00147 00148 /** 00149 Sets the string value 00150 @param[in] Val the string value 00151 */ 00152 inline void set(const std::string& Val) { m_Value = Val; }; 00153 00154 void writeToStream(std::ostream& OutStm) const; 00155 00156 /** 00157 Returns the size of the string 00158 @return size of the string 00159 */ 00160 inline unsigned long getSize() const { return m_Value.size(); }; 00161 00162 /** 00163 Returns the size of the string 00164 @return size of the string 00165 */ 00166 unsigned long size() const { return m_Value.size(); }; 00167 00168 /** 00169 Converts the contained string to a double value (if possible) 00170 @return bool true if the conversion is correct, false otherwise 00171 */ 00172 bool toDouble(double& Val) const; 00173 00174 /** 00175 Converts the contained string to a DoubleValue (if possible) 00176 @param[out] Val the converted value 00177 @return bool true if the conversion is correct, false otherwise 00178 */ 00179 bool toDoubleValue(DoubleValue& Val) const; 00180 00181 /** 00182 Converts the contained string to a boolean value (if possible) 00183 @param[out] Val the converted value 00184 @return bool true if the conversion is correct, false otherwise 00185 */ 00186 bool toBoolean(bool& Val) const; 00187 00188 /** 00189 Converts the contained string to a BooleanValue (if possible) 00190 @param[out] Val the converted value 00191 @return bool true if the conversion is correct, false otherwise 00192 */ 00193 bool toBooleanValue(BooleanValue& Val) const; 00194 00195 /** 00196 Converts the contained string to a long value (if possible) 00197 @param[out] Val the converted value 00198 @return bool true if the conversion is correct, false otherwise 00199 */ 00200 bool toInteger(long& Val) const; 00201 00202 /** 00203 Converts the contained string to an IntegerValue (if possible) 00204 @param[out] Val the converted value 00205 @return bool true if the conversion is correct, false otherwise 00206 */ 00207 bool toIntegerValue(IntegerValue& Val) const; 00208 00209 /** 00210 Converts the contained string to a NullValue (if possible) 00211 @param[out] Val the converted value 00212 @return bool true if the conversion is correct, false otherwise 00213 */ 00214 bool toNullValue(NullValue& Val) const; 00215 00216 /** 00217 Converts the contained string to a VectorValue value (if possible) 00218 @param[in] Sep the separator used to split the string into vector items 00219 @param[out] Val the converted value 00220 @return bool true if the conversion is correct, false otherwise 00221 */ 00222 bool toVectorValue(const std::string& Sep, VectorValue& Val) const; 00223 00224 /** 00225 Converts the contained string to a MatrixValue value (if possible) 00226 @param[in] ColSep the column separator used to split the string columns 00227 @param[in] RowSep the row separator used to split the string rows 00228 @param[out] Val the converted value 00229 @return bool true if the conversion is correct, false otherwise 00230 */ 00231 bool toMatrixValue(const std::string& ColSep, const std::string& RowSep, MatrixValue& Val) const; 00232 00233 /** 00234 Converts the contained string to a MatrixValue value (if possible) 00235 @param[in] Sep the separator used to split the string 00236 @param[in] RowLength the size of a row 00237 @param[out] Val the converted value 00238 @return bool true if the conversion is correct, false otherwise 00239 */ 00240 bool toMatrixValue(const std::string& Sep, const unsigned int& RowLength, MatrixValue& Val) const; 00241 00242 /** 00243 Converts the contained string to a MapValue value (if possible) 00244 @param[in] Sep the separator used to split the string into map items 00245 @param[out] Val the converted value 00246 @return bool true if the conversion is correct, false otherwise 00247 */ 00248 bool toMapValue(const std::string& Sep, MapValue& Val) const; 00249 00250 }; 00251 00252 00253 } } // namespaces 00254 00255 00256 00257 #endif /* __STRINGVALUE_HPP___ */