11//
22// DynamicAny.h
33//
4- // $Id: //poco/Main/Foundation/include/Poco/DynamicAny.h#9 $
4+ // $Id: //poco/Main/Foundation/include/Poco/DynamicAny.h#10 $
55//
66// Library: Foundation
77// Package: Core
@@ -64,7 +64,7 @@ class Foundation_API DynamicAny
6464 // / String truncation is allowed -- it is possible to convert between string and character when string length is
6565 // / greater than 1. An empty string gets converted to the char '\0', a non-empty string is truncated to the first character.
6666 // /
67- // / Bolean conversion are performed as follows:
67+ // / Boolean conversion is performed as follows:
6868 // /
6969 // / A string value "false" (not case sensitive) or "0" can be converted to a boolean value false, any other string
7070 // / not being false by the above criteria evaluates to true (e.g: "hi" -> true).
@@ -180,15 +180,15 @@ class Foundation_API DynamicAny
180180 }
181181
182182 template <typename T>
183- bool operator == (const T& other)
183+ bool operator == (const T& other) const
184184 // / Equality operator
185185 {
186186 T value;
187187 _pHolder->convert (value);
188188 return value == other;
189189 }
190190
191- bool operator == (const char * other)
191+ bool operator == (const char * other) const
192192 // / Equality operator
193193 {
194194 std::string value;
@@ -197,30 +197,79 @@ class Foundation_API DynamicAny
197197 }
198198
199199 template <typename T>
200- bool operator != (const T& other)
200+ bool operator != (const T& other) const
201201 // / Inequality operator
202202 {
203203 T value;
204204 _pHolder->convert (value);
205205 return value != other;
206206 }
207207
208- bool operator != (const char * other)
208+ bool operator != (const char * other) const
209209 // / Inequality operator
210210 {
211211 std::string value;
212212 _pHolder->convert (value);
213213 return value != other;
214214 }
215215
216- const std::type_info& type () const ;
216+ bool isArray () const ;
217+ // / Returns true if DynamicAny represents a vector
218+
219+ bool isStruct () const ;
220+ // / Returns true if DynamicAny represents a struct
221+
222+ DynamicAny& operator [](std::vector<DynamicAny>::size_type n);
223+ // / Index operator, only use on DynamicAnys where isArray
224+ // / returns true! In all other cases a BadCastException is thrown!
225+
226+ const DynamicAny& operator [](std::vector<DynamicAny>::size_type n) const ;
227+ // / const Index operator, only use on DynamicAnys where isArray
228+ // / returns true! In all other cases a BadCastException is thrown!
229+
230+ DynamicAny& operator [](const std::string& name);
231+ // / Index operator by name, only use on DynamicAnys where isStruct
232+ // / returns true! In all other cases a BadCastException is thrown!
233+
234+ const DynamicAny& operator [](const std::string& name) const ;
235+ // / Index operator by name, only use on DynamicAnys where isStruct
236+ // / returns true! In all other cases a BadCastException is thrown!
237+
238+ const std::type_info& type () const ;
217239 // / Returns the type information of the stored content.
240+
241+ static DynamicAny parse (const std::string& val);
242+ // / Parses the string which must be in JSON format
243+
244+ static std::string toString (const DynamicAny& any);
245+ // / Converts the DynamicAny to a string in JSON format. Note that toString will return
246+ // / a different result than any.convert<std::string>()!
218247
248+ private:
249+ static DynamicAny parse (const std::string& val, std::string::size_type& offset);
250+ // / Parses the string which must be in JSON format
251+
252+ static DynamicAny parseObject (const std::string& val, std::string::size_type& pos);
253+ static DynamicAny parseArray (const std::string& val, std::string::size_type& pos);
254+ static std::string parseString (const std::string& val, std::string::size_type& pos);
255+ static void skipWhiteSpace (const std::string& val, std::string::size_type& pos);
219256private:
220257 DynamicAnyHolder* _pHolder;
221258};
222259
223260
261+ inline bool DynamicAny::isArray () const
262+ {
263+ return _pHolder->isArray ();
264+ }
265+
266+
267+ inline bool DynamicAny::isStruct () const
268+ {
269+ return _pHolder->isStruct ();
270+ }
271+
272+
224273} // namespace Poco
225274
226275
0 commit comments