@@ -171,21 +171,6 @@ namespace web { namespace json
171
171
// / <returns>The JSON value object that contains the result of the assignment.</returns>
172
172
_ASYNCRTIMP value &operator =(value &&);
173
173
174
- // / <summary>
175
- // / Constructor creating a JSON value from an input stream, by parsing its contents.
176
- // / </summary>
177
- // / <param name="input">The stream to read the JSON value from</param>
178
- // / <returns>The JSON value object created from the input stream.</returns>
179
- _ASYNCRTIMP static value parse (utility::istream_t &input);
180
-
181
- #ifdef _MS_WINDOWS
182
- // / <summary>
183
- // / Constructor creating a JSON value from a byte buffer stream, by parsing its contents.
184
- // / </summary>
185
- // / <param name="stream">The stream to read the JSON value from</param>
186
- _ASYNCRTIMP static value parse (std::istream& stream);
187
- #endif
188
-
189
174
// Static factories
190
175
191
176
// / <summary>
@@ -312,31 +297,44 @@ namespace web { namespace json
312
297
// / <returns>The number of children. 0 for all non-composites.</returns>
313
298
size_t size () const ;
314
299
300
+ // / <summary>
301
+ // / Parse a string and construct a JSON value.
302
+ // / </summary>
303
+ // / <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
304
+ _ASYNCRTIMP static value parse (utility::string_t );
305
+
315
306
// / <summary>
316
307
// / Serialize the current JSON value to a C++ string.
317
308
// / </summary>
318
309
// / <returns>A string representation of the value</returns>
319
310
_ASYNCRTIMP utility::string_t to_string () const ;
320
311
321
312
// / <summary>
322
- // / Parse a string and construct a JSON value .
313
+ // / Parse a JSON value from the contents of an input stream using the native platform character width .
323
314
// / </summary>
324
- // / <param name="value">The C++ value to create a JSON value from, a C++ STL double-byte string</param>
325
- _ASYNCRTIMP static value parse (utility::string_t );
315
+ // / <param name="input">The stream to read the JSON value from</param>
316
+ // / <returns>The JSON value object created from the input stream.</returns>
317
+ _ASYNCRTIMP static value parse (utility::istream_t &input);
326
318
327
- #ifdef _MS_WINDOWS
328
319
// / <summary>
329
- // / Write the current JSON value as a double-byte string to a stream instance .
320
+ // / Write the current JSON value to a stream with the native platform character width .
330
321
// / </summary>
331
322
// / <param name="stream">The stream that the JSON string representation should be written to.</param>
332
- _ASYNCRTIMP void serialize (std::basic_ostream<utf16char> &stream) const ;
333
- #endif
323
+ _ASYNCRTIMP void serialize (utility::ostream_t &stream) const ;
334
324
325
+ #ifdef _MS_WINDOWS
335
326
// / <summary>
336
- // / Serialize the content of the value into a stream in UTF8 format
327
+ // / Parse a JSON value from the contents of a single-byte (UTF8) stream.
328
+ // / </summary>
329
+ // / <param name="stream">The stream to read the JSON value from</param>
330
+ _ASYNCRTIMP static value parse (std::istream& stream);
331
+
332
+ // / <summary>
333
+ // / Serialize the content of the value into a single-byte (UTF8) stream.
337
334
// / </summary>
338
335
// / <param name="stream">The stream that the JSON string representation should be written to.</param>
339
- _ASYNCRTIMP void serialize (std::basic_ostream<char >& stream) const ;
336
+ _ASYNCRTIMP void serialize (std::ostream& stream) const ;
337
+ #endif
340
338
341
339
// / <summary>
342
340
// / Convert the JSON value to a C++ double, if and only if it is a number value.
@@ -381,6 +379,13 @@ namespace web { namespace json
381
379
return !((*this ) == other);
382
380
}
383
381
382
+ // / <summary>
383
+ // / Access a field of a JSON object.
384
+ // / </summary>
385
+ // / <param name="key">The name of the field</param>
386
+ // / <returns>The value kept in the field; null if the field does not exist</returns>
387
+ value get (const utility::string_t &key) const ;
388
+
384
389
// / <summary>
385
390
// / Access a field of a JSON object.
386
391
// / </summary>
@@ -406,6 +411,13 @@ namespace web { namespace json
406
411
public:
407
412
#endif
408
413
414
+ // / <summary>
415
+ // / Access an element of a JSON array.
416
+ // / </summary>
417
+ // / <param name="key">The index of an element in the JSON array</param>
418
+ // / <returns>The value kept at the array index; null if outside the boundaries of the array</returns>
419
+ value get (size_t index) const ;
420
+
409
421
// / <summary>
410
422
// / Accesses an element of a JSON array.
411
423
// / </summary>
@@ -530,6 +542,9 @@ namespace web { namespace json
530
542
virtual const json::value::element_vector &elements () const { throw json_exception (U (" not an array" )); }
531
543
virtual const json::value::field_map &fields () const { throw json_exception (U (" not an object" )); }
532
544
545
+ virtual value get_field (const utility::string_t &) const { throw json_exception (U (" not an object" )); }
546
+ virtual value get_element (std::vector<value>::size_type) const { throw json_exception (U (" not an array" )); }
547
+
533
548
virtual value &index (const utility::string_t &) { throw json_exception (U (" not an object" )); }
534
549
virtual value &index (std::vector<value>::size_type) { throw json_exception (U (" not an array" )); }
535
550
@@ -775,6 +790,7 @@ namespace web { namespace json
775
790
776
791
virtual json::value::value_type type () const { return json::value::Object; }
777
792
793
+ _ASYNCRTIMP virtual value get_field (const utility::string_t &) const ;
778
794
_ASYNCRTIMP virtual json::value &index (const utility::string_t &key);
779
795
_ASYNCRTIMP virtual const json::value &cnst_index (const utility::string_t &key) const ;
780
796
@@ -843,6 +859,18 @@ namespace web { namespace json
843
859
844
860
virtual json::value::value_type type () const { return json::value::Array; }
845
861
862
+ virtual value get_element (std::vector<value>::size_type index) const
863
+ {
864
+ #ifdef _MS_WINDOWS
865
+ msl::utilities::SafeInt<std::vector<json::value>::size_type> idx (index);
866
+ msl::utilities::SafeInt<std::vector<json::value>::size_type> size (m_elements.size ());
867
+ #else
868
+ size_t idx = index;
869
+ size_t size = m_elements.size ();
870
+ #endif
871
+ return (idx >= size) ? value () : m_elements[index].second ;
872
+ }
873
+
846
874
virtual json::value &index (std::vector<json::value>::size_type index)
847
875
{
848
876
#ifdef _MS_WINDOWS
@@ -925,6 +953,17 @@ namespace web { namespace json
925
953
return m_value->size ();
926
954
}
927
955
956
+ inline json::value json::value::get (const utility::string_t & key) const
957
+ {
958
+ return m_value->get_field (key);
959
+ }
960
+
961
+ inline json::value json::value::get (size_t index) const
962
+ {
963
+ return m_value->get_element (index);
964
+ }
965
+
966
+
928
967
inline json::value::iterator json::value::begin ()
929
968
{
930
969
return m_value->elements ().begin ();
0 commit comments