All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StringValue.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 StringValue.hpp
36  \brief Header of ...
37 
38  \author Jean-Christophe FABRE <fabrejc@supagro.inra.fr>
39  */
40 
41 
42 #ifndef __STRINGVALUE_HPP___
43 #define __STRINGVALUE_HPP___
44 
45 
46 #include <string>
47 #include <vector>
48 
50 
51 #include <openfluid/dllexport.hpp>
52 
53 
54 
55 namespace openfluid { namespace core {
56 /**
57 StringValue is a container for a std::string value, with methods for conversion to other containers derived from Value.\n
58 
59 \see Value
60 
61 \n
62 
63 <I>Example : declaration</I>
64 @code
65  // declaration of a StringValue, initialized to an empty string by default
66  openfluid::core::StringValue Val1;
67 
68  // declaration of a StringValue, initialized to "hello world"
69  openfluid::core::StringValue Val2("hello world");
70 @endcode
71 
72 
73 <I>Example : getting the contained value</I>
74 @code
75  std::string Tmp1;
76 
77  // using the get method
78  Tmp1 = Val1.get();
79 
80  // or using the cast operator
81  Tmp1 = Val1;
82 @endcode
83 
84 
85 <I>Example : setting the contained value</I>
86 @code
87  // using the set method
88  Val1.set("Have a nice day");
89 @endcode
90 */
92 {
93  private:
94 
95  std::string m_Value;
96 
97  static bool convertStringToDouble(const std::string& Str, double& Dbl);
98 
99  static std::vector<std::string> splitString(const std::string& StrToSplit,
100  const std::string& Separators,
101  bool ReturnsEmpty = false);
102 
103  std::vector<std::string> split(const std::string& Separators,
104  bool ReturnsEmpty = false) const;
105 
106  public:
107 
108  /**
109  Default constructor
110  */
111  StringValue() : m_Value("") {};
112 
113  /**
114  Copy constructor
115  */
116  StringValue(const StringValue& Val) : SimpleValue(Val), m_Value(Val.m_Value) {};
117 
118  /**
119  Constructor from plain old type
120  */
121  StringValue(const std::string& POD) : SimpleValue(), m_Value(POD) {};
122 
123  Value& operator =(const Value& Other);
124 
125  /**
126  * Cast operator
127  */
128  operator std::string() const { return m_Value; };
129 
130  virtual ~StringValue() {};
131 
132  inline Type getType() const { return Value::STRING; };
133 
134  Value* clone() const { return new StringValue(*this); };
135 
136  /**
137  Returns the string value as plain old type
138  @return the string value
139  */
140  inline std::string& get() { return m_Value; };
141 
142  /**
143  Returns the string value as a const plain old type
144  @return the string value
145  */
146  inline const std::string& get() const { return m_Value; };
147 
148  /**
149  Sets the string value
150  @param[in] Val the string value
151  */
152  inline void set(const std::string& Val) { m_Value = Val; };
153 
154  void writeToStream(std::ostream& OutStm) const;
155 
156  /**
157  Returns the size of the string
158  @return size of the string
159  */
160  inline unsigned long getSize() const { return m_Value.size(); };
161 
162  /**
163  Returns the size of the string
164  @return size of the string
165  */
166  unsigned long size() const { return m_Value.size(); };
167 
168  /**
169  Converts the contained string to a double value (if possible)
170  @return bool true if the conversion is correct, false otherwise
171  */
172  bool toDouble(double& Val) const;
173 
174  /**
175  Converts the contained string to a DoubleValue (if possible)
176  @param[out] Val the converted value
177  @return bool true if the conversion is correct, false otherwise
178  */
179  bool toDoubleValue(DoubleValue& Val) const;
180 
181  /**
182  Converts the contained string to a boolean value (if possible)
183  @param[out] Val the converted value
184  @return bool true if the conversion is correct, false otherwise
185  */
186  bool toBoolean(bool& Val) const;
187 
188  /**
189  Converts the contained string to a BooleanValue (if possible)
190  @param[out] Val the converted value
191  @return bool true if the conversion is correct, false otherwise
192  */
193  bool toBooleanValue(BooleanValue& Val) const;
194 
195  /**
196  Converts the contained string to a long value (if possible)
197  @param[out] Val the converted value
198  @return bool true if the conversion is correct, false otherwise
199  */
200  bool toInteger(long& Val) const;
201 
202  /**
203  Converts the contained string to an IntegerValue (if possible)
204  @param[out] Val the converted value
205  @return bool true if the conversion is correct, false otherwise
206  */
207  bool toIntegerValue(IntegerValue& Val) const;
208 
209  /**
210  Converts the contained string to a NullValue (if possible)
211  @param[out] Val the converted value
212  @return bool true if the conversion is correct, false otherwise
213  */
214  bool toNullValue(NullValue& Val) const;
215 
216  /**
217  Converts the contained string to a VectorValue value (if possible)
218  @param[in] Sep the separator used to split the string into vector items
219  @param[out] Val the converted value
220  @return bool true if the conversion is correct, false otherwise
221  */
222  bool toVectorValue(const std::string& Sep, VectorValue& Val) const;
223 
224  /**
225  Converts the contained string to a MatrixValue value (if possible)
226  @param[in] ColSep the column separator used to split the string columns
227  @param[in] RowSep the row separator used to split the string rows
228  @param[out] Val the converted value
229  @return bool true if the conversion is correct, false otherwise
230  */
231  bool toMatrixValue(const std::string& ColSep, const std::string& RowSep, MatrixValue& Val) const;
232 
233  /**
234  Converts the contained string to a MatrixValue value (if possible)
235  @param[in] Sep the separator used to split the string
236  @param[in] RowLength the size of a row
237  @param[out] Val the converted value
238  @return bool true if the conversion is correct, false otherwise
239  */
240  bool toMatrixValue(const std::string& Sep, const unsigned int& RowLength, MatrixValue& Val) const;
241 
242  /**
243  Converts the contained string to a MapValue value (if possible)
244  @param[in] Sep the separator used to split the string into map items
245  @param[out] Val the converted value
246  @return bool true if the conversion is correct, false otherwise
247  */
248  bool toMapValue(const std::string& Sep, MapValue& Val) const;
249 
250 };
251 
252 
253 } } // namespaces
254 
255 
256 
257 #endif /* __STRINGVALUE_HPP___ */
Definition: StringValue.hpp:91
unsigned long getSize() const
Definition: StringValue.hpp:160
Type getType() const
Definition: StringValue.hpp:132
StringValue()
Definition: StringValue.hpp:111
Definition: IntegerValue.hpp:106
Definition: DoubleValue.hpp:103
unsigned long size() const
Definition: StringValue.hpp:166
Header of ...
Definition: Value.hpp:68
Definition: MapValue.hpp:134
StringValue(const std::string &POD)
Definition: StringValue.hpp:121
virtual ~StringValue()
Definition: StringValue.hpp:130
Definition: NullValue.hpp:59
Type
Definition: Value.hpp:68
Definition: SimpleValue.hpp:50
Definition: MatrixValue.hpp:115
Definition: Value.hpp:64
void set(const std::string &Val)
Definition: StringValue.hpp:152
Value * clone() const
Definition: StringValue.hpp:134
StringValue(const StringValue &Val)
Definition: StringValue.hpp:116
Definition: VectorValue.hpp:119
Definition: BooleanValue.hpp:104
#define DLLEXPORT
Definition: dllexport.hpp:51