BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn_json.h
Go to the documentation of this file.
1/// @file bdljsn_json.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdljsn_json.h -*-C++-*-
8#ifndef INCLUDED_BDLJSN_JSON
9#define INCLUDED_BDLJSN_JSON
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdljsn_json bdljsn_json
15/// @brief Provide an in-memory representation of a JSON document.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdljsn
19/// @{
20/// @addtogroup bdljsn_json
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdljsn_json-purpose"> Purpose</a>
25/// * <a href="#bdljsn_json-classes"> Classes </a>
26/// * <a href="#bdljsn_json-description"> Description </a>
27/// * <a href="#bdljsn_json-reading-and-writing-a-bdljsn-json-object"> Reading and Writing a bdljsn::Json Object </a>
28/// * <a href="#bdljsn_json-all-bdljsn-json-objects-are-valid-json-documents"> All bdljsn::Json Objects are Valid JSON Documents </a>
29/// * <a href="#bdljsn_json-important-preconditions"> Important Preconditions </a>
30/// * <a href="#bdljsn_json-operator==-and-the-definition-of-value"> operator== and the Definition of Value </a>
31/// * <a href="#bdljsn_json-usage"> Usage </a>
32/// * <a href="#bdljsn_json-example-1-constructor-a-basic-bdljsn-json-object"> Example 1: Constructor a Basic bdljsn::Json Object </a>
33/// * <a href="#bdljsn_json-example-2-more-efficiently-creating-a-bdljsn-json"> Example 2: More Efficiently Creating a bdljsn::Json </a>
34///
35/// # Purpose {#bdljsn_json-purpose}
36/// Provide an in-memory representation of a JSON document.
37///
38/// # Classes {#bdljsn_json-classes}
39///
40/// - bdljsn::Json: representation of a JSON document
41/// - bdljsn::JsonArray: representation of a JSON array
42/// - bdljsn::JsonObject: representation of a JSON object
43///
44/// @see bdljsn_jsonutil, bdljsn_jsonnumber, bdljsn_jsonnull
45///
46/// # Description {#bdljsn_json-description}
47/// This component provides a value-semantic type, `bdljsn::Json`,
48/// used as an in-memory representation for a JSON document. This component
49/// also provides `bdljsn::JsonArray` and `bdljsn::JsonObject` types for
50/// representing JSON Arrays and Objects respectively.
51///
52/// `bdljsn::Json` has a close structural similarity to the JSON grammar itself,
53/// which at a high-level looks like:
54/// @code
55/// JSON ::= Object
56/// | Array
57/// | String
58/// | Number
59/// | Boolean
60/// | null
61/// @endcode
62/// Where the Object and Array alternatives can recursively contain JSON. Just
63/// like this grammar, a `bdljsn::Json` is a variant holding either an Object,
64/// Array, String, Number, Boolean, or null. These variant selections are
65/// represented by the following types:
66///
67/// * Object: `JsonObject`
68/// * Array: `JsonArray`
69/// * String: `bsl::string`
70/// * Number: `JsonNumber`
71/// * Boolean: `bool`
72/// * null: `JsonNull`
73///
74/// For more details on the JSON grammar see:
75///
76/// * website: https://www.json.org/
77/// * RFC: https://datatracker.ietf.org/doc/html/rfc8259
78///
79/// ## Reading and Writing a bdljsn::Json Object {#bdljsn_json-reading-and-writing-a-bdljsn-json-object}
80///
81///
82/// @ref bdljsn_jsonutil is the recommended facility to write and read
83/// `bdljsn::Json` objects to and from JSON document text.
84///
85/// `operator<<` overloads are available for all the types. In addition a
86/// canonical BDE print method is available for `bdljsn::Json`,
87/// `bdljsn::JsonObject`, `bdljsn::JsonArray` `bdljsn::JsonNumber` and
88/// `bdljsn::JsonNull`.
89///
90/// ## All bdljsn::Json Objects are Valid JSON Documents {#bdljsn_json-all-bdljsn-json-objects-are-valid-json-documents}
91///
92///
93/// Every `bdljsn::Json` represents a (valid) JSON document (`bdljsn::Json` does
94/// not have an "invalid" state). This means writing a `bdljsn::Json` to a
95/// string can only fail if an out-of-memory condition occurs.
96///
97/// Similarly, every JSON document has a `bdljsn::Json` representation.
98/// However, `bdljsn::JsonObject` represents Objects having only unique member
99/// names, meaning that duplicate member names in a JSON document will be
100/// ignored (see `bdljsn::JsonUtil` for more information on how duplicate names
101/// are handled when parsing a JSON document). Note that the JSON RFC says that
102/// Object member names "SHOULD be unique", and there is no standard behavior
103/// for JSON parsers where member names are not unique (typically an in-process
104/// representation with unique member names is used).
105///
106/// ### Important Preconditions {#bdljsn_json-important-preconditions}
107///
108///
109/// In order to preserve the invariant that all `bdljsn::Json` objects are valid
110/// JSON documents there are some constructors and assignment operations in
111/// `bdljsn` package that have notable preconditions:
112///
113/// * `bdljsn::JsonNumber` constructors from string require that the string
114/// conform to the JSON grammar for a number (see
115/// `bdljsn::NumberUtil::isValidNumber`).
116/// * Constructors and assignment operators from `double` or
117/// `bdldfp::Decimal64` require the value *not* be either INF or NaN
118/// * `bdljsn::Json` constructors and assignment operators require that
119/// strings contain valid UTF-8 (see `bdlde::Utf8Util::isValid`).
120///
121/// ## operator== and the Definition of Value {#bdljsn_json-operator==-and-the-definition-of-value}
122///
123///
124/// `bdljsn::Json` type's definition of value (i.e., the behavior for
125/// `operator==`) mirrors comparing the text of two JSON documents where all the
126/// white-space is ignored.
127///
128/// Concretely, `bdljsn::Json` is a variant type, whose definition of equality
129/// is derived from the definition of equality of its constituent types. I.e.,
130/// two `bdljsn::Json` objects compare equal if they have the same `type` and
131/// the two objects of that `type` they contain compare equal. The definition
132/// of equality for Object, Array, Boolean, string, and `JsonNull` types are
133/// relatively self-explanatory (see respective `operator==` definitions for
134/// details). The definition of equality for `JsonNumber` is notable:
135/// `JsonNumber` objects define value in terms of the text of the JSON number
136/// string they contain. So two JSON numbers having the same numerical value
137/// may compare *unequal* (e.g., "2" and "2.0" and "20e-1" are considered
138/// different `JsonNumber` values!). Note that `bdljsn::JsonNumber::isEqual`
139/// provides a semantic comparison of two numbers (see @ref bdljsn_jsonnumber for
140/// more detail).
141///
142/// ## Usage {#bdljsn_json-usage}
143///
144///
145/// This section illustrates the intended use of this component.
146///
147/// ### Example 1: Constructor a Basic bdljsn::Json Object {#bdljsn_json-example-1-constructor-a-basic-bdljsn-json-object}
148///
149///
150/// Most often `bdljsn::Json` objects will be written and read from JSON text
151/// using @ref bdljsn_jsonutil . In this simple example, we demonstrate manually
152/// creating the document below and then verify the properties of the resulting
153/// object:
154/// @code
155/// {
156/// "number": 3.14,
157/// "boolean": true,
158/// "string": "text",
159/// "null": null,
160/// "array": [ "2.76", true ],
161/// "object": { "boolean": false }
162/// }
163/// @endcode
164/// First, we use `bdljsn::Json::makeObject` to configure the top level
165/// `bdljsn::Json` object to be a `bdljsn::Json` object, and use the various
166/// manipulators of `bdljsn::JsonObject` to configure its value:
167/// @code
168/// using namespace bdldfp::DecimalLiterals;
169///
170/// bdljsn::Json json;
171///
172/// json.makeObject();
173/// json["number"] = 3.14;
174/// json["boolean"] = true;
175/// json["string"] = "text";
176/// json["array"].makeArray();
177/// json["array"].theArray().pushBack(bdljsn::Json(2.76_d64));
178/// json["array"].theArray().pushBack(bdljsn::Json(true));
179/// json["object"].makeObject()["boolean"] = false;
180/// @endcode
181/// Notice that we used `operator[]` to implicitly create new members of the
182/// top-level object. Using `json.theObject().insert` would be more efficient
183/// (see example 2).
184///
185/// Finally, we validate the properties of the resulting object:
186/// @code
187/// assert(3.14 == json["number"].asDouble());
188/// assert(true == json["boolean"].theBoolean());
189/// assert("text" == json["string"].theString());
190/// assert(true == json["null"].isNull());
191/// assert(2.76_d64 == json["array"][0].asDecimal64());
192/// assert(false == json["object"]["boolean"].theBoolean());
193/// @endcode
194///
195/// ## Example 2: More Efficiently Creating a bdljsn::Json {#bdljsn_json-example-2-more-efficiently-creating-a-bdljsn-json}
196///
197///
198/// Example 1 used `operator[]` to implicitly add members to the Objects. Using
199/// `operator[]` is intuitive but not the most efficient method to add new
200/// members to a `bdljsn::JsonObject` (similar to using `operator[]` to add
201/// elements to an `unordered_map`). The following code demonstrates a more
202/// efficient way to create the same `bdljsn::Json` representation as example 1:
203/// @code
204/// using namespace bdldfp::DecimalLiterals;
205///
206/// bdljsn::Json json;
207/// bdljsn::JsonArray subArray;
208/// bdljsn::JsonObject subObject;
209///
210/// json.makeObject();
211/// json.theObject().insert("number", bdljsn::JsonNumber(3.14));
212/// json.theObject().insert("boolean", true);
213/// json.theObject().insert("string", "text");
214/// json.theObject().insert("null", bdljsn::JsonNull());
215///
216/// subArray.pushBack(bdljsn::Json(2.76_d64));
217/// subArray.pushBack(bdljsn::Json(true));
218/// json.theObject().insert("array", bsl::move(subArray));
219///
220/// subObject.insert("boolean", false);
221/// json.theObject().insert("object", bsl::move(subObject));
222/// @endcode
223/#include <bdlscm_version.h>
224/// @}
225/** @} */
226/** @} */
227
228/** @addtogroup bdl
229 * @{
230 */
231/** @addtogroup bdljsn
232 * @{
233 */
234/** @addtogroup bdljsn_json
235 * @{
236 */
237
238#include <bdlb_variant.h>
239
240#include <bdlde_utf8util.h>
241
242#include <bdljsn_jsonnull.h>
243#include <bdljsn_jsonnumber.h>
244#include <bdljsn_jsontype.h>
245
247#include <bdlb_transparenthash.h>
248#include <bdldfp_decimal.h>
249
250#include <bslma_allocator.h>
251#include <bslma_bslallocator.h>
253
254#include <bslmf_assert.h>
255#include <bslmf_enableif.h>
256#include <bslmf_issame.h>
257#include <bslmf_movableref.h>
259#include <bslmf_util.h>
260
261#include <bsls_assert.h>
263#include <bsls_keyword.h>
264#include <bsls_types.h>
265#include <bsls_util.h>
266
267#include <bsl_iterator.h>
268#include <bsl_unordered_map.h>
269#include <bsl_vector.h>
270
271
272namespace bdljsn {
273
274// FORWARD DECLARATIONS
275class Json;
276class JsonArray;
277class JsonObject;
278
279 // ===============
280 // class JsonArray
281 // ===============
282
283/// This type is designed to replicate much of the standard sequence
284/// container interface, eliding interfaces that are less relevant for a
285/// non-generic container. Note that a `bsl::vector` is chosen for the
286/// implementation because our implementation permits the element type to be
287/// incomplete (when just spelling the type name).
288///
289/// See @ref bdljsn_json
291
292 private:
293 // PRIVATE TYPES
295
296 public:
297 // TYPES
300
304
307
310
311 private:
312 // DATA
313 Elements d_elements; // the underlying sequence of elements
314
315 // FRIENDS
316 friend bool operator==(const JsonArray&, const JsonArray&);
317 friend bool operator!=(const JsonArray&, const JsonArray&);
318 template <class HASHALG>
319 friend void hashAppend(HASHALG&, const JsonArray&);
320 friend void swap(JsonArray&, JsonArray&);
321
322 public:
323 // TRAITS
327
328 // CREATORS
329
330 JsonArray();
331 /// Create an empty `JsonArray`. Optionally specify a `basicAllocator`
332 /// used to supply memory. If `basicAllocator` is not specified, the
333 /// currently installed default allocator is used.
334 explicit JsonArray(bslma::Allocator *basicAllocator);
335
336 /// Create a `JsonArray` having the same value as the specified
337 /// `original` object. Optionally specify `basicAllocator` to supply
338 /// memory. If `basicAllocator` is not specified, the allocator
339 /// associated with `original` is propagated for use in the
340 /// newly-created `JsonArray`.
341 JsonArray(const JsonArray& original, bslma::Allocator *basicAllocator = 0);
342
343 /// Create a `JsonArray` having the same value as the specified
344 /// `original` object by moving (in constant time) the contents of
345 /// `original` to the new `JsonArray` object. The allocator associated
346 /// with `original` is propagated for use in the newly-created
347 /// `JsonArray` object. `original` is left in a valid but unspecified
348 /// state.
350
351 /// Create a `JsonArray` having the same value as the specified
352 /// `original` object that uses the specified `basicAllocator` to supply
353 /// memory. The contents of `original` are moved (in constant time) to
354 /// the new `JsonArray` object if
355 /// `basicAllocator == original.allocator()`, and are move-inserted (in
356 /// linear time) using `basicAllocator` otherwise. `original` is left
357 /// in a valid but unspecified state.
359 bslma::Allocator *basicAllocator);
360
361 /// Create a `JsonArray` and insert (in order) each `Json` object in the
362 /// range starting at the specified `first` element, and ending
363 /// immediately before the specified `last` element. Optionally specify
364 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
365 /// specified, the currently installed default allocator is used. Throw
366 /// `bsl::length_error` if the number of elements in `[first .. last)`
367 /// exceeds the value returned by the method `maxSize`. The (template
368 /// parameter) type `INPUT_ITERATOR` shall meet the requirements of an
369 /// input iterator defined in the c++11 standard [24.2.3] providing
370 /// access to values of a type convertible to `Json`, and `Json` must be
371 /// `emplace-constructible` form `*i`, where `i` is a dereferenceable
372 /// iterator in the range `[first .. last)`. The behavior is undefined
373 /// unless `first` and `last` refer to a range of valid values where
374 /// `first` is at a position at or before `last`.
375 template <class INPUT_ITERATOR>
376 JsonArray(INPUT_ITERATOR first,
377 INPUT_ITERATOR last,
378 bslma::Allocator *basicAllocator = 0);
379
380#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
381
382 /// Create a `JsonArray` and insert (in order) each `Json` object in the
383 /// specified `elements` initializer list. Optionally specify a
384 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
385 /// specified, the currently installed default allocator is used.
386 JsonArray(std::initializer_list<Json> elements,
387 bslma::Allocator *basicAllocator = 0); // IMPLICIT
388
389#endif
390
391 // MANIPULATORS
392
393 /// Assign to this object the value of the specified `rhs` object, and
394 /// return a reference providing modifiable access to this object. If
395 /// an exception is thrown, `*this` is left in a valid but unspecified
396 /// state.
397 JsonArray& operator=(const JsonArray& rhs);
398
399 /// Assign to this object the value of the specified `rhs` object, and
400 /// return a reference providing modifiable access to this object. The
401 /// contents of `rhs` are moved (in constant time) to this JsonArray if
402 /// `allocator() == rhs.allocator()`; otherwise, all elements in this
403 /// `JsonArray` are either destroyed or move-assigned to and each
404 /// additional element in `rhs` is move-inserted into this JsonArray.
405 /// `rhs` is left in a valid but unspecified state.
407
408#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
409 /// Assign to this object the value resulting from first clearing this
410 /// `JsonArray` and then inserting (in order) each `Json` object in the
411 /// specified `initializer` initializer list. Return a reference to
412 /// `*this`. If an exception is thrown, `*this` is left in a valid but
413 /// unspecified state.
414 JsonArray& operator=(std::initializer_list<Json> initializer);
415
416 /// Assign to this object the value resulting from first clearing this
417 /// JsonArray and then inserting (in order) each `Json` object in the
418 /// specified `initializer` initializer list. If an exception is
419 /// thrown, `*this` is left in a valid but unspecified state.
420 void assign(std::initializer_list<Json> initializer);
421#endif
422
423 /// Return a reference providing modifiable access to the element at the
424 /// specified `index` in this `JsonArray`. The behavior is undefined
425 /// unless `index < size()`.
426 Json& operator[](bsl::size_t index);
427
428 /// Assign to this object the value resulting from first clearing this
429 /// `JsonArray` and then inserting (in order) each `Json` object in the
430 /// range starting at the specified `first` element, and ending
431 /// immediately before the specified `last` element. If an exception is
432 /// thrown, `*this` is left in a valid but unspecified state. Throw
433 /// `bsl::length_error` if `distance(first,last) > maxSize()`. The
434 /// (template parameter) type `INPUT_ITERATOR` shall meet the
435 /// requirements of an input iterator defined in the c++11 standard
436 /// [24.2.3] providing access to values of a type convertible to `Json`,
437 /// and `Json` must be `emplace-constructible` form `*i`, where `i` is a
438 /// dereferenceable iterator in the range `[first .. last)`. The
439 /// behavior is undefined unless `first` and `last` refer to a range of
440 /// valid values where `first` is at a position at or before `last`.
441 template <class INPUT_ITERATOR>
442 void assign(INPUT_ITERATOR first, INPUT_ITERATOR last);
443
444 // BDE_VERIFY pragma: -FABC01
445
446 /// Return an iterator providing modifiable access to the first element
447 /// in this `JsonArray, or the past-the-end iterator if this `JsonArray'
448 /// is empty.
449 Iterator begin();
450
451 /// Return the past-the-end iterator providing modifiable access to this
452 /// `JsonArray`.
453 Iterator end();
454
455 /// Return a reference providing modifiable access to the first element
456 /// in this `JsonArray`. The behavior is undefined unless this
457 /// `JsonArray` is not empty.
458 Json& front();
459
460 /// Return a reference providing modifiable access to the last element
461 /// in this `JsonArray`. The behavior is undefined unless this
462 /// `JsonArray` is not empty.
463 Json& back();
464
465 // BDE_VERIFY pragma: +FABC01
466
467 /// Remove all elements from this `JsonArray` making its size 0. Note
468 /// that although this `JsonArray` is empty after this method returns,
469 /// it preserves the same capacity it had before the method was called.
470 void clear();
471
472 /// Remove from this `JsonArray` the element at the specified `index`,
473 /// and return an iterator providing modifiable access to the element
474 /// immediately following the removed element, or the position returned
475 /// by the method `end` if the removed element was the last in the
476 /// sequence. The behavior is undefined unless `index` is in the range
477 /// `[0 .. size())`.
478 Iterator erase(bsl::size_t index);
479
480 /// Remove from this `JsonArray` the element at the specified
481 /// `position`, and return an iterator providing modifiable access to
482 /// the element immediately following the removed element, or the
483 /// position returned by the method `end` if the removed element was the
484 /// last in the sequence. The behavior is undefined unless `position`
485 /// is an iterator in the range `[cbegin() .. cend())`.
486 Iterator erase(ConstIterator position);
487
488 /// Remove from this `JsonArray` the sequence of elements starting at
489 /// the specified `first` position and ending before the specified
490 /// `last` position, and return an iterator providing modifiable access
491 /// to the element immediately following the last removed element, or
492 /// the position returned by the method `end` if the removed elements
493 /// were last in the sequence. The behavior is undefined unless `first`
494 /// is an iterator in the range `[cbegin() .. cend()]` (both endpoints
495 /// included) and `last` is an iterator in the range `[first .. cend()]`
496 /// (both endpoints included).
498
499 /// Insert at the specified `index` in this JsonArray a copy of the
500 /// specified `json`, and return an iterator referring to the newly
501 /// inserted element. If an exception is thrown, `*this` is unaffected.
502 /// Throw `bsl::length_error` if `size() == maxSize()`. The behavior is
503 /// undefined unless `index` is in the range `[0 .. size()]`.
504 Iterator insert(bsl::size_t index, const Json& json);
505
506 /// Insert at the specified `index` in this JsonArray the specified
507 /// move-insertable `json`, and return an iterator referring to the
508 /// newly inserted element. `json` is left in a valid but unspecified
509 /// state. If an exception is thrown, `this` is unaffected. Throw
510 /// `bsl::length_error` if `size() == maxSize()`. The behavior is
511 /// undefined unless `index` is in the range `[0 .. size()]` (both
512 /// endpoints included).
513 Iterator insert(bsl::size_t index, bslmf::MovableRef<Json> json);
514
515 /// Insert at the specified `index` in this JsonArray the values in the
516 /// range starting at the specified `first` element, and ending
517 /// immediately before the specified `last` element. Return an iterator
518 /// referring to the first newly inserted element. If an exception is
519 /// thrown, `*this` is unaffected. Throw `bsl::length_error` if
520 /// `size() + distance(first, last) > maxSize()`. The (template
521 /// parameter) type `INPUT_ITERATOR` shall meet the requirements of an
522 /// input iterator defined in the C++11 standard [24.2.3] providing
523 /// access to values of a type convertible to `Json`, and `Json` must be
524 /// `emplace-constructible` from `*i` into this `JsonArray, where `i' is
525 /// a dereferenceable iterator in the range `[first .. last)`. The
526 /// behavior is undefined unless `index` is in the range `[0 .. size()]`
527 /// (both endpoints included), and `first` and `last` refer to a range
528 /// of valid values where `first` is at a position at or before `last`.
529 template <class INPUT_ITERATOR>
530 Iterator insert(bsl::size_t index,
531 INPUT_ITERATOR first,
532 INPUT_ITERATOR last);
533
534 /// Insert at the specified `position` in this `JsonArray` a copy of the
535 /// specified `json`, and return an iterator referring to the newly
536 /// inserted element. If an exception is thrown, `*this` is unaffected.
537 /// Throw `bsl::length_error` if `size() == maxSize()`. The behavior is
538 /// undefined unless `position` is an iterator in the range
539 /// `[begin() .. end()]` (both endpoints included).
540 Iterator insert(ConstIterator position, const Json& json);
541
542 /// Insert at the specified `position` in this `JsonArray` the specified
543 /// move-insertable `json`, and return an iterator referring to the
544 /// newly inserted element. `json` is left in a valid but unspecified
545 /// state. If an exception is thrown, `this` is unaffected. Throw
546 /// `bsl::length_error` if `size() == maxSize()`. The behavior is
547 /// undefined unless `position` is an iterator in the range
548 /// `[begin() .. end()]` (both endpoints included).
550
551 /// Insert at the specified `position` in this `JsonArray` the values in
552 /// the range starting at the specified `first` element, and ending
553 /// immediately before the specified `last` element. Return an iterator
554 /// referring to the first newly inserted element. If an exception is
555 /// thrown, `*this` is unaffected. Throw `bsl::length_error` if
556 /// `size() + distance(first, last) > maxSize()`. The (template
557 /// parameter) type `INPUT_ITERATOR` shall meet the requirements of an
558 /// input iterator defined in the C++11 standard [24.2.3] providing
559 /// access to values of a type convertible to `value_type`, and
560 /// `value_type` must be `emplace-constructible` from `*i` into this
561 /// JsonArray, where `i` is a dereferenceable iterator in the range
562 /// `[first .. last)`. The behavior is undefined unless `position` is
563 /// an iterator in the range `[begin() .. end()]` (both endpoints
564 /// included), and `first` and `last` refer to a range of valid values
565 /// where `first` is at a position at or before `last`.
566 template <class INPUT_ITERATOR>
568 INPUT_ITERATOR first,
569 INPUT_ITERATOR last);
570
571 /// Erase the last element from this `JsonArray`. The behavior is
572 /// undefined if this JsonArray is empty.
573 void popBack();
574
575 /// Append to the end of this `JsonArray` a copy of the specified
576 /// `json`. If an exception is thrown, `*this` is unaffected. Throw
577 /// `bsl::length_error` if `size() == maxSize()`.
578 void pushBack(const Json& json);
579
580 /// Append to the end of this `JsonArray` the specified move-insertable
581 /// `Json`. `value` is left in a valid but unspecified state. If an
582 /// exception is thrown, `*this` is unaffected. Throw
583 /// `bsl::length_error` if `size() == maxSize()`.
585
586 /// Change the size of this `JsonArray` to the specified `count`. If
587 /// `count < size()`, the elements in the range `[count .. size())` are
588 /// erased, and this function does not throw. If `count > size()`, the
589 /// (newly created) elements in the range `[size() .. count)` are
590 /// default-constructed `Json` objects, and if an exception is thrown,
591 /// `*this` is unaffected. Throw `bsl::length_error` if
592 /// `count > maxSize()`.
593 void resize(bsl::size_t count);
594
595 /// Change the size of this JsonArray to the specified `count`,
596 /// inserting copies of the specified `json` at the end if
597 /// `count > size()`. If `count < size()`, the elements in the range
598 /// `[count .. size())` are erased `json` is ignored, and this method
599 /// does not throw. If `count > size()` and an exception is thrown,
600 /// `*this` is unaffected. Throw `bsl::length_error` if
601 /// `count > maxSize()`.
602 void resize(bsl::size_t count, const Json& json);
603
604 /// Exchange the value of this object with that of the specified `other`
605 /// object. If an exception is thrown, both objects are left in valid
606 /// but unspecified states. This operation guarantees O[1] complexity.
607 /// The behavior is undefined unless this object was created with the
608 /// same allocator as `other`.
609 void swap(JsonArray& other);
610
611 // ACCESSORS
612
613 /// Return a reference providing non-modifiable access to the element at
614 /// the specified `index` in this `JsonArray`. The behavior is
615 /// undefined unless `index < size()`.
616 const Json& operator[](bsl::size_t index) const;
617
618 // BDE_VERIFY pragma: -FABC01
619
621
622 /// Return an iterator providing non-modifiable access to the first
623 /// element in this `JsonArray`, and the past-the-end iterator if this
624 /// `JsonArray` is empty.
626
628
629 /// Return the past-the-end iterator providing non-modifiable access to
630 /// this `JsonArray`.
632
633 /// Return a reference providing non-modifiable access to the first
634 /// element in this `JsonArray`. The behavior is undefined unless this
635 /// `JsonArray` is not empty.
636 const Json& front() const;
637
638 /// Return a reference providing non-modifiable access to the last
639 /// element in this `JsonArray`. The behavior is undefined unless this
640 /// `JsonArray` is not empty.
641 const Json& back() const;
642
643 // BDE_VERIFY pragma: +FABC01
644
645 /// Return `true` if this `JsonArray` has size 0, and `false` otherwise.
646 bool empty() const;
647
648 /// Return the number of elements in this `JsonArray`.
649 bsl::size_t size() const;
650
651 // Aspects
652
653 /// Return the allocator used by this object to allocate memory.
654 bslma::Allocator *allocator() const BSLS_KEYWORD_NOEXCEPT;
655
656 /// Return a theoretical upper bound on the largest number of elements
657 /// that this `JsonArray` could possibly hold. Note that there is no
658 /// guarantee that the `JsonArray` can successfully grow to the returned
659 /// size, or even close to that size without running out of resources.
660 /// Also note that requests to create a `JsonArray` longer than this
661 /// number of elements are guaranteed to raise a `bsl::length_error`
662 /// exception.
663 bsl::size_t maxSize() const BSLS_KEYWORD_NOEXCEPT;
664
665 /// Write the value of this object to the specified output `stream` in a
666 /// human-readable format, and return a reference to `stream`.
667 /// Optionally specify an initial indentation `level`, whose absolute
668 /// value is incremented recursively for nested objects. If `level` is
669 /// specified, optionally specify `spacesPerLevel`, whose absolute value
670 /// indicates the number of spaces per indentation level for this and
671 /// all of its nested objects. If `level` is negative, suppress
672 /// indentation of the first line. If `spacesPerLevel` is negative,
673 /// format the entire output on one line, suppressing all but the
674 /// initial indentation (as governed by `level`). If `stream` is not
675 /// valid on entry, this operation has no effect. Note that this
676 /// human-readable format is not fully specified, and can change without
677 /// notice.
678 bsl::ostream& print(bsl::ostream& stream,
679 int level = 0,
680 int spacesPerLevel = 4) const;
681};
682
683// FREE OPERATORS
684
685/// Write the value of the specified `object` to the specified output
686/// `stream` in a single-line format, and return a reference to `stream`.
687/// If `stream` is not valid on entry, this operation has no effect. Note
688/// that this human-readable format is not fully specified, can change
689/// without notice, and is logically equivalent to:
690/// @code
691/// print(stream, 0, -1);
692/// @endcode
693bsl::ostream& operator<<(bsl::ostream& stream, const JsonArray& object);
694
695/// Return `true` if the specified `lhs` and `rhs` objects have the same
696/// value, and `false` otherwise. Two `JsonArray` objects `lhs` and `rhs`
697/// have the same value if they have the same number of elements, and each
698/// element in the ordered sequence of elements of `lhs` has the same value
699/// as the corresponding element in the ordered sequence of elements of
700/// `rhs`.
701bool operator==(const JsonArray& lhs, const JsonArray& rhs);
702
703/// Return `false` if the specified `lhs` and `rhs` objects have the same
704/// value, and `true` otherwise. Two `JsonArray` objects `lhs` and `rhs`
705/// have the same value if they have the same number of elements, and each
706/// element in the ordered sequence of elements of `lhs` has the same value
707/// as the corresponding element in the ordered sequence of elements of
708/// `rhs`.
709bool operator!=(const JsonArray& lhs, const JsonArray& rhs);
710
711/// Invoke the specified `hashAlg` on the attributes of the specified
712/// `object`.
713template <class HASHALG>
714void hashAppend(HASHALG& hashAlg, const JsonArray& object);
715
716/// Exchange the value of the specified `a` `JsonArray` with that of the
717/// specified `b` `JsonArray`. This function provides the no-throw
718/// exception-safety guarantee. This operation has O[1] complexity if `a`
719/// was created with the same allocator as `b`; otherwise, it has O[n+m]
720/// complexity, where n and m are the number of elements in `a` and `b`,
721/// respectively.
723
724 // ================
725 // class JsonObject
726 // ================
727
728/// This type is designed to replicate much of the standard associative
729/// container interface, eliding interfaces that are less relevant for a
730/// non-generic container, like hasher and comparator access, emplacement,
731/// nodes, capacity management, etc.
732///
733/// See @ref bdljsn_json
735
736 private:
737 // PRIVATE TYPES
739 Json,
742 Container;
743
744 public:
745 // TYPES
746 typedef Container::value_type Member;
747 typedef Container::const_iterator ConstIterator;
748 typedef Container::iterator Iterator;
750
751 typedef Container::value_type value_type;
754
755 typedef Container::iterator iterator;
756 typedef Container::const_iterator const_iterator;
757
760
761 private:
762 // DATA
763 Container d_members; // the underlying container of element mappings
764
765 // FRIENDS
766 friend bool operator==(const JsonObject&, const JsonObject&);
767 friend bool operator!=(const JsonObject&, const JsonObject&);
768 template <class HASHALG>
769 friend void hashAppend(HASHALG&, const JsonObject&);
770 friend void swap(JsonObject&, JsonObject&);
771
772 public:
773 // TRAITS
777
778 // CREATORS
779
780 JsonObject();
781 /// Create an empty `JsonObject`. Optionally specify the
782 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
783 /// specified, the currently installed default allocator is used to
784 /// supply memory.
785 explicit JsonObject(bslma::Allocator *basicAllocator);
786
787 /// Create a `JsonObject` having the same value as the specified
788 /// `original`. Optionally specify the `basicAllocator` used to supply
789 /// memory. If `basicAllocator` is not specified, the currently
790 /// installed default allocator is used to supply memory.
791 JsonObject(const JsonObject& original,
792 bslma::Allocator *basicAllocator = 0);
793
794 /// Create a `JsonObject` having the same value as the specified
795 /// `original` object by moving (in constant time) the contents of
796 /// `original` to the new `JsonObject`. The allocator associated with
797 /// `original` is propagated for use in the newly-created `JsonObject`.
798 /// `original` is left in a valid but unspecified state.
800
801 /// Create a `JsonObject` having the same value as the specified
802 /// `original`. Use the specified `basicAllocator` to supply memory.
803 /// If `basicAllocator == original.allocator()` the value of `original`
804 /// will be moved (in constant time) to the newly-created `JsonObject`,
805 /// and `original` will be left in a valid but unspecified state.
806 /// Otherwise, `original` is copied, and `basicAllocator` used to supply
807 /// memory.
809 bslma::Allocator *basicAllocator);
810
811 /// Create an empty `JsonObject`, and then create a `Json` object for
812 /// each iterator in the range starting at the specified `first`
813 /// iterator and ending immediately before the specified `last`
814 /// iterator, by converting from the object referred to by each
815 /// iterator. Insert into this `JsonObject` each such object, ignoring
816 /// those having a key that appears earlier in the sequence. Optionally
817 /// specify a `basicAllocator` used to supply memory. If
818 /// `basicAllocator` is not supplied, the currently installed default
819 /// allocator is used to supply memory. The (template parameter) type
820 /// `INPUT_ITERATOR` shall meet the requirements of an input iterator
821 /// defined in the C++11 standard [24.2.3] providing access to values of
822 /// a type convertible to `Member`. The behavior is undefined unless
823 /// `first` and `last` refer to a sequence of valid values where `first`
824 /// is at a position at or before `last`, and all keys of all `Member`
825 /// objects inserted are valid UTF-8 (see `bdlde::Utf8Util::isValid`).
826 template <class INPUT_ITERATOR>
827 JsonObject(INPUT_ITERATOR first,
828 INPUT_ITERATOR last,
829 bslma::Allocator *basicAllocator = 0);
830
831#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
832 /// Create an empty `JsonObject`, and then create a `Json` object for
833 /// each in the range specified by `members` argument, ignoring elements
834 /// having a key that appears earlier in the sequence. Optionally
835 /// specify the `basicAllocator` used to supply memory. If
836 /// `basicAllocator` is not specified, the currently installed default
837 /// allocator is used to supply memory. The behavior is undefined
838 /// unless the keys of all `Member` objects in `members` are valid UTF-8
839 /// (see `bdlde::Utf8Util::isValid`).
840 JsonObject(std::initializer_list<Member> members,
841 bslma::Allocator *basicAllocator = 0); // IMPLICIT
842#endif
843
844 // MANIPULATORS
845
846 /// Assign to this object the value of the specified `rhs` object, and
847 /// return a reference providing modifiable access to this object.
848 JsonObject& operator=(const JsonObject& rhs);
849
850 /// Assign to this object the value of the specified `rhs` object, and
851 /// return a reference providing modifiable access to this object. The
852 /// contents of `rhs` are moved (in constant time) to this `JsonObject`
853 /// if `allocator() == rhs.allocator()`; otherwise, all elements in this
854 /// container are either destroyed or move-assigned to, and each
855 /// additional element in `rhs`, if any, is move-inserted into this
856 /// `JsonObject`. `rhs` is left in a valid but unspecified state.
858
859#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
860 /// Assign to this object the value resulting from first clearing this
861 /// `JsonObject` and then inserting (in order) each `Member` object in
862 /// the specified `members` initializer list. Return a reference to
863 /// `*this`. If an exception is thrown, `*this` is left in a valid but
864 /// unspecified state.
865 JsonObject& operator=(std::initializer_list<Member> members);
866#endif
867
868 /// Return a reference providing modifiable access to the `Json` object
869 /// associated with the specified `key` in this `JsonObject`; if this
870 /// `JsonObject` does not already contain a `Json` object associated
871 /// with `key`, first insert a new default-constructed `Json` object
872 /// associated with `key`. The behavior is undefined unless `key` is
873 /// valid UTF-8 (see `bdlde::Utf8Util::isValid`).
874 Json& operator[](const bsl::string_view& key);
875
876 // BDE_VERIFY pragma: -FABC01
877
878 /// Return an iterator providing modifiable access to the first `Member`
879 /// object in the sequence of `Member` objects maintained by this
880 /// `JsonObject`, or the `end` iterator if this `JsonObject` is empty.
882
883 /// Return an iterator providing modifiable access to the past-the-end
884 /// position in the sequence of `Member` objects maintained by this
885 /// `JsonObject`.
887
888 // BDE_VERIFY pragma: +FABC01
889
890 /// Remove all entries from this `JsonObject`. Note that this
891 /// `JsonObject` will be empty after calling this method, but allocated
892 /// memory may be retained for future use.
894
895 /// Remove from this `JsonObject` the `Member` object having the
896 /// specified `key`, if it exists, and return 1; otherwise (there is no
897 /// object with a key equivalent to `key` in this `JsonObject`) return 0
898 /// with no other effect. This method invalidates only iterators and
899 /// references to the removed element and previously saved values of the
900 /// `end()` iterator, and preserves the relative order of the elements
901 /// not removed.
902 bsl::size_t erase(const bsl::string_view& key);
903
904 Iterator erase(Iterator position);
905 /// Remove from this unordered map the `value_type` object at the
906 /// specified `position`, and return an iterator referring to the
907 /// element immediately following the removed element, or to the
908 /// past-the-end position if the removed element was the last element in
909 /// the sequence of elements maintained by this unordered map. This
910 /// method invalidates only iterators and references to the removed
911 /// element and previously saved values of the `end()` iterator, and
912 /// preserves the relative order of the elements not removed. The
913 /// behavior is undefined unless `position` refers to a `value_type`
914 /// object in this unordered map.
915 Iterator erase(ConstIterator position);
916
917 /// Return an iterator providing modifiable access to the `Member`
918 /// object in this `JsonObject` with a key equivalent to the specified
919 /// `key`, if such an entry exists, and the past-the-end iterator
920 /// (`end`) otherwise.
921 Iterator find(const bsl::string_view& key);
922
923 /// Insert the specified `member` into this `JsonObject` if the key (the
924 /// `first` element) of the object referred to by `value` does not
925 /// already exist in this `JsonObject`; otherwise, this method has no
926 /// effect. Return a `pair` whose `first` member is an iterator
927 /// referring to the (possibly newly inserted) `value_type` object in
928 /// this `JsonObject` whose key is equivalent to that of the object to
929 /// be inserted, and whose `second` member is `true` if a new value was
930 /// inserted, and `false` if a value having an equivalent key was
931 /// already present. The behavior is undefined unless `member.first` is
932 /// valid UTF-8 (see `bdlde::Utf8Util::isValid`).
933 bsl::pair<Iterator, bool> insert(const Member& member);
934
935 /// Insert the specified `member` into this `JsonObject` if the key (the
936 /// `first` element) of the object referred to by `member` does not
937 /// already exist in this `JsonObject`; otherwise, this method has no
938 /// effect. Return a `pair` whose `first` member is an iterator
939 /// referring to the (possibly newly inserted) `member` object in this
940 /// `JsonObject` whose key is the equivalent to that of the object to be
941 /// inserted, and whose `second` member is `true` if a new value was
942 /// inserted, and `false` otherwise. The behavior is undefined unless
943 /// `member.first` is valid UTF-8 (see `bdlde::Utf8Util::isValid`).
944 bsl::pair<Iterator, bool> insert(bslmf::MovableRef<Member> member);
945
946 /// Create a `member` object for each iterator in the range starting at
947 /// the specified `first` iterator and ending immediately before the
948 /// specified `last` iterator, by converting from the object referred to
949 /// by each iterator. Insert into this `JsonObject` each such object
950 /// whose key is not already contained. The (template parameter) type
951 /// `INPUT_ITERATOR` shall meet the requirements of an input iterator
952 /// defined in the C++11 standard [24.2.3] providing access to values of
953 /// a type convertible to `Member`. The behavior is undefined unless
954 /// `first` and `last` refer to a sequence of value values where `first`
955 /// is at a position at or before `last`. The behavior is undefined
956 /// unless the keys of all `Member` objects inserted are valid UTF-8
957 /// (see `bdlde::Utf8Util::isValid`).
958 template <class INPUT_ITERATOR>
959 typename bsl::enable_if<!bsl::is_convertible<INPUT_ITERATOR,
960 bsl::string_view>::value,
961 void>::type
962 insert(INPUT_ITERATOR first, INPUT_ITERATOR last);
963
964#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
965 /// Create a `Member` object for each element in the specified
966 /// `members`. Insert into this `JsonObject` each such object whose key
967 /// is not already contained. The behavior is undefined unless the keys
968 /// of all `Member` objects inserted are valid UTF-8 (see
969 /// `bdlde::Utf8Util::isValid`).
970 void insert(std::initializer_list<Member> members);
971#endif
972
973 /// Insert into this `JsonObject` a `Member` constructed from the
974 /// specified `key` and the specified `value`, respectively, if `key`
975 /// does not already exist in this `JsonObject`; otherwise, this method
976 /// has no effect. Return a `pair` whose `first` member is an iterator
977 /// referring to the (possibly newly inserted) `Member` object in this
978 /// `JsonObject` whose key is the equivalent to that of the object to be
979 /// inserted, and whose `second` member is `true` if a new value was
980 /// inserted, and `false` otherwise. The behavior is undefined unless
981 /// `key` is valid UTF-8 (see `bdlde::Utf8Util::isValid`).
982 template <class VALUE>
984 const bsl::string_view& key,
986
987 /// Exchange the value of this object with that of the specified `other`
988 /// object. If an exception is thrown, both objects are left in valid
989 /// but unspecified states. This operation guarantees O[1] complexity.
990 /// The behavior is undefined unless this object was created with the
991 /// same allocator as `other`.
992 void swap(JsonObject& other);
993
994 // ACCESSORS
995
996 /// Return a reference providing non-modifiable access to the `Json`
997 /// object associated with the specified `key` in this `JsonObject`.
998 /// The behavior is undefined unless `key` is valid UTF-8 (see
999 /// `bdlde::Utf8Util::isValid`) and this `JsonObject` already contains a
1000 /// `Json` object associated with `key`.
1001 const Json& operator[](const bsl::string_view& key) const;
1002
1003 // BDE_VERIFY pragma: -FABC01
1004
1006
1007 /// Return an iterator providing non-modifiable access to the first
1008 /// `Member` object in the sequence of `Member` objects maintained by
1009 /// this `JsonObject`, or the `end` iterator if this `JsonObject` is
1010 /// empty.
1012
1014
1015 /// Return an iterator providing non-modifiable access to the
1016 /// past-the-end position in the sequence of `Member` objects maintained
1017 /// by this `JsonObject`.
1019
1020 // BDE_VERIFY pragma: +FABC01
1021
1022 /// Return `true` if there is a `Member` object in this `JsonObject`
1023 /// with a key equivalent to the specified `key`, and return `false`
1024 /// otherwise.
1025 bool contains(const bsl::string_view& key) const;
1026
1027 /// Return `true` if this `JsonObject` contains no elements, and `false`
1028 /// otherwise.
1029 bool empty() const BSLS_KEYWORD_NOEXCEPT;
1030
1031 /// Return an iterator providing non-modifiable access to the `Member`
1032 /// object in this `JsonObject` with a key equivalent to the specified
1033 /// `key`, if such an entry exists, and the past-the-end iterator
1034 /// (`end`) otherwise.
1035 ConstIterator find(const bsl::string_view& key) const;
1036
1037 /// Return the number of elements in this `JsonObject`.
1038 bsl::size_t size() const BSLS_KEYWORD_NOEXCEPT;
1039
1040 // Aspects
1041
1042 /// Return the allocator used by this object to allocate memory.
1043 bslma::Allocator *allocator() const BSLS_KEYWORD_NOEXCEPT;
1044
1045 /// Write the value of this object to the specified output `stream` in a
1046 /// human-readable format, and return a reference to `stream`.
1047 /// Optionally specify an initial indentation `level`, whose absolute
1048 /// value is incremented recursively for nested objects. If `level` is
1049 /// specified, optionally specify `spacesPerLevel`, whose absolute value
1050 /// indicates the number of spaces per indentation level for this and
1051 /// all of its nested objects. If `level` is negative, suppress
1052 /// indentation of the first line. If `spacesPerLevel` is negative,
1053 /// format the entire output on one line, suppressing all but the
1054 /// initial indentation (as governed by `level`). If `stream` is not
1055 /// valid on entry, this operation has no effect. Note that this
1056 /// human-readable format is not fully specified, and can change without
1057 /// notice.
1058 bsl::ostream& print(bsl::ostream& stream,
1059 int level = 0,
1060 int spacesPerLevel = 4) const;
1061};
1062
1063// FREE OPERATORS
1064
1065/// Write the value of the specified `object` to the specified output
1066/// `stream` in a single-line format, and return a reference to `stream`.
1067/// If `stream` is not valid on entry, this operation has no effect. Note
1068/// that this human-readable format is not fully specified, can change
1069/// without notice, and is logically equivalent to:
1070/// @code
1071/// print(stream, 0, -1);
1072/// @endcode
1073bsl::ostream& operator<<(bsl::ostream& stream, const JsonObject& object);
1074
1075/// Return `true` if the specified `lhs` and `rhs` objects have the same
1076/// value, and `false` otherwise. Two `JsonObject` objects have the same
1077/// value if they have the same number of `Member` objects, and for each
1078/// `Member` object that is contained in `lhs` there is a key-value pair
1079/// contained in `rhs` having the same value, and vice versa.
1080bool operator==(const JsonObject& lhs, const JsonObject& rhs);
1081
1082/// Return `false` if the specified `lhs` and `rhs` objects have the same
1083/// value, and `true` otherwise. Two `JsonObject` objects have the same
1084/// value if they have the same number of `Member` objects, and for each
1085/// `Member` object that is contained in `lhs` there is a key-value pair
1086/// contained in `rhs` having the same value, and vice versa.
1087bool operator!=(const JsonObject& lhs, const JsonObject& rhs);
1088
1089/// Invoke the specified `hashAlg` on the attributes of the specified
1090/// `object`.
1091template <class HASHALG>
1092void hashAppend(HASHALG& hashAlg, const JsonObject& object);
1093
1094/// Exchange the value of the specified `a` `JsonObject` with that of the
1095/// specified `b` `JsonObject`. This function provides the no-throw
1096/// exception-safety guarantee. This operation has O[1] complexity if `a`
1097/// was created with the same allocator as `b`; otherwise, it has O[n+m]
1098/// complexity, where n and m are the number of elements in `a` and `b`,
1099/// respectively.
1101
1102 // ==========
1103 // class Json
1104 // ==========
1105
1106/// This type is designed to be a thin wrapper around a variant of the
1107/// possible JSON types, using a BDE-style variant interface.
1108///
1109/// See @ref bdljsn_json
1110class Json {
1111
1112 // PRIVATE TYPES
1113 typedef bdlb::
1114 Variant<JsonObject, JsonArray, bsl::string, JsonNumber, bool, JsonNull>
1115 Value;
1116
1123
1124 private:
1125 // DATA
1126 Value d_value; // the underlying variant value
1127
1128 // FRIENDS
1129 friend bool operator==(const Json&, const Json&);
1130 friend bool operator!=(const Json&, const Json&);
1131 template <class HASHALG>
1132 friend void hashAppend(HASHALG&, const Json&);
1133 friend void swap(Json&, Json&);
1134
1135 public:
1136 // TRAITS
1140
1141 // CREATORS
1142
1143 Json();
1144 /// Create a `Json` object having the type (and the singleton value) of
1145 /// `JsonNull`. Optionally specify the `basicAllocator` used to supply
1146 /// memory. If `basicAllocator` is not specified, the currently
1147 /// installed default allocator is used to supply memory.
1148 explicit Json(bslma::Allocator *basicAllocator);
1149
1150 /// Create a `Json` object having the same value as the specified
1151 /// `original`. Optionally specify the `basicAllocator` used to supply
1152 /// memory. If `basicAllocator` is not specified, the currently
1153 /// installed default allocator is used to supply memory.
1154 Json(const Json& original, bslma::Allocator *basicAllocator = 0);
1155
1156 /// Create a `Json` object having the same value as the specified
1157 /// `original` object by moving (in constant time) the contents of
1158 /// `original` to the new `JsonObject`. The allocator associated with
1159 /// `original` is propagated for use in the newly-created `Json` object.
1160 /// `original` is left in a valid but unspecified state.
1161 Json(bslmf::MovableRef<Json> original);
1162
1163 /// Create a `Json` object having the same value as the specified
1164 /// `original`. Use the specified `basicAllocator` to supply memory.
1165 Json(bslmf::MovableRef<Json> original, bslma::Allocator *basicAllocator);
1166
1167 /// Create a `Json` object having the type `JsonArray` and the same
1168 /// value as the specified `array`. Optionally specify the
1169 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
1170 /// specified, the currently installed default allocator is used to
1171 /// supply memory.
1172 explicit Json(const JsonArray& array,
1173 bslma::Allocator *basicAllocator = 0);
1174
1175 /// Create a `Json` object having the type `JsonArray` and the same
1176 /// value as the specified `array` object by moving (in constant time)
1177 /// the contents of `array` to the new `Json` object. Optionally
1178 /// specify the `basicAllocator` used to supply memory. If
1179 /// `basicAllocator` is not specified, the allocator associated with
1180 /// `array` is propagated for use in the newly-created `Json` object.
1181 /// `array` is left in a valid but unspecified state.
1182 explicit Json(bslmf::MovableRef<JsonArray> array,
1183 bslma::Allocator *basicAllocator = 0);
1184
1185 /// Create a `Json` object having the type `bool` and the same value as
1186 /// the specified `boolean`. Optionally specify the `basicAllocator`
1187 /// used to supply memory. If `basicAllocator` is not specified, the
1188 /// currently installed default allocator is used to supply memory.
1189 explicit Json(bool boolean, bslma::Allocator *basicAllocator = 0);
1190
1191 /// Create a `Json` object having the type `JsonNull` and the same value
1192 /// as the specified `null`. Optionally specify the `basicAllocator`
1193 /// used to supply memory. If `basicAllocator` is not specified, the
1194 /// currently installed default allocator is used to supply memory.
1195 explicit Json(const JsonNull& null, bslma::Allocator *basicAllocator = 0);
1196
1197 explicit Json(float number, bslma::Allocator *basicAllocator = 0);
1198 explicit Json(double number, bslma::Allocator *basicAllocator = 0);
1199 explicit Json(bdldfp::Decimal64 number,
1200 bslma::Allocator *basicAllocator = 0);
1201 explicit Json(int number, bslma::Allocator *basicAllocator = 0);
1202 explicit Json(unsigned int number, bslma::Allocator *basicAllocator = 0);
1203 explicit Json(bsls::Types::Int64 number,
1204 bslma::Allocator *basicAllocator = 0);
1205 explicit Json(bsls::Types::Uint64 number,
1206 bslma::Allocator *basicAllocator = 0);
1207 /// Create a `Json` object having the type `JsonNumber` and the same
1208 /// value as the specified `number`. Optionally specify the
1209 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
1210 /// specified, the currently installed default allocator is used to
1211 /// supply memory.
1212 explicit Json(const JsonNumber& number,
1213 bslma::Allocator *basicAllocator = 0);
1214
1215 /// Create a `Json` object having the type `JsonNumber` and the same
1216 /// value as the specified `number` object by moving (in constant time)
1217 /// the contents of `number` to the new `Json` object. Optionally
1218 /// specify the `basicAllocator` used to supply memory. If
1219 /// `basicAllocator` is not specified, the allocator associated with
1220 /// `number` is propagated for use in the newly-created `Json` object.
1221 /// `number` is left in a valid but unspecified state.
1222 explicit Json(bslmf::MovableRef<JsonNumber> number,
1223 bslma::Allocator *basicAllocator = 0);
1224
1225 /// Create a `Json` object having the type `JsonObject` and the same
1226 /// value as the specified `object`. Optionally specify the
1227 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
1228 /// specified, the currently installed default allocator is used to
1229 /// supply memory.
1230 explicit Json(const JsonObject& object,
1231 bslma::Allocator *basicAllocator = 0);
1232
1233 /// Create a `Json` object having the type `JsonObject` and the same
1234 /// value as the specified `object` by moving (in constant time) the
1235 /// contents of `object` to the new `Json` object. Optionally specify
1236 /// the `basicAllocator` used to supply memory. If `basicAllocator` is
1237 /// not specified, the allocator associated with `object` is propagated
1238 /// for use in the newly-created `Json` object. `object` is left in a
1239 /// valid but unspecified state.
1240 explicit Json(bslmf::MovableRef<JsonObject> object,
1241 bslma::Allocator *basicAllocator = 0);
1242
1243 // BDE_VERIFY pragma: -FD06 'string' and 'bsl::string' are too similar
1244 // BDE_VERIFY pragma: -FD07 'string' and 'bsl::string' are too similar
1245
1246 explicit Json(const char *string, bslma::Allocator *basicAllocator = 0);
1247 /// Create a `Json` object having the type `bsl::string` and the same
1248 /// value as the specified `string`. Optionally specify the
1249 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
1250 /// specified, the currently installed default allocator is used to
1251 /// supply memory. The behavior is undefined unless `string` is valid
1252 /// UTF-8 (see `bdlde::Utf8Util::isValid`).
1253 explicit Json(const bsl::string_view& string,
1254 bslma::Allocator *basicAllocator = 0);
1255
1256 // BDE_VERIFY pragma: -IND01 DEDUCE macro confuses bde_verify
1257
1258 /// Create a `Json` object having the type `bsl::string` and the same
1259 /// value as the specified `string` by moving (in constant time) the
1260 /// contents of `string` to the new `Json` object. Optionally specify
1261 /// the `basicAllocator` used to supply memory. If `basicAllocator` is
1262 /// not specified, the allocator associated with `string` is propagated
1263 /// for use in the newly-created `Json` object. `string` is left in a
1264 /// valid but unspecified state. This function does not participate in
1265 /// overload resolution unless the specified `STRING_TYPE` is
1266 /// `bsl::string`. The behavior is undefined unless `string` is valid
1267 /// UTF-8 (see `bdlde::Utf8Util::isValid`).
1268 template <class STRING_TYPE>
1269 explicit Json(
1270 BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) string,
1271 bslma::Allocator *basicAllocator = 0,
1272 typename bsl::enable_if<
1274
1275 // BDE_VERIFY pragma: +IND01 DEDUCE macro confuses bde_verify
1276 // BDE_VERIFY pragma: +FD06 'string' and 'bsl::string' are too similar
1277 // BDE_VERIFY pragma: +FD07 'string' and 'bsl::string' are too similar
1278
1279 // MANIPULATORS
1280
1281 /// Assign to this object the value of the specified `rhs` object, and
1282 /// return a reference providing modifiable access to this object. The
1283 /// value currently held by this variant is destroyed if that value's
1284 /// type is not the same as the type held by the `rhs` object.
1285 Json& operator=(const Json& rhs);
1286
1287 /// Assign to this object the value of the specified `rhs` object, and
1288 /// return a reference providing modifiable access to this object. The
1289 /// contents of `rhs` are moved (in constant time) to this `Json` object
1290 /// if `allocator() == rhs.allocator()`; otherwise they are copied.
1291 /// `rhs` is left in a valid but unspecified state.
1293
1294 /// Assign to this object a value of type `JsonNumber` initialized from
1295 /// the specified `rhs`, and return a reference providing modifiable
1296 /// access to this object. The value currently held by this object (if
1297 /// any) is destroyed if that value's type is not `JsonNumber`.
1298 Json& operator=(float rhs);
1299 Json& operator=(double rhs);
1301 Json& operator=(int rhs);
1302 Json& operator=(unsigned int rhs);
1305 Json& operator=(const JsonNumber& rhs);
1306
1307 /// Assign to this object the value of the specified `rhs` object, and
1308 /// return a reference providing modifiable access to this object. The
1309 /// contents of `rhs` are moved (in constant time) to this `Json` object
1310 /// if `allocator() == rhs.allocator()`; otherwise, they are copied.
1311 /// `rhs` is left in a valid but unspecified state. The value currently
1312 /// held by this object (if any) is destroyed if that value's type is
1313 /// not `JsonNumber`.
1315
1316 /// Assign to this object a value of type `bsl::string` initialized from
1317 /// the specified `rhs`, and return a reference providing modifiable
1318 /// access to this object. The value currently held by this object (if
1319 /// any) is destroyed if that value's type is not `bsl::string`. The
1320 /// behavior is undefined unless `rhs` is valid UTF-8 (see
1321 /// `bdlde::Utf8Util::isValid`).
1322 Json& operator=(const char *rhs);
1323 Json& operator=(const bsl::string_view& rhs);
1324
1325 /// Assign to this object the value of the specified `rhs` object, and
1326 /// return a reference providing modifiable access to this object. The
1327 /// contents of `rhs` are moved (in constant time) to this `Json` object
1328 /// if `allocator() == rhs.allocator()`; otherwise, they are copied.
1329 /// `rhs` is left in a valid but unspecified state. The value currently
1330 /// held by this object (if any) is destroyed if that value's type is
1331 /// not `bsl::string`. This function does not participate in overload
1332 /// resolution unless the specified `STRING_TYPE` is `bsl::string`. The
1333 /// behavior is undefined unless `rhs` is valid UTF-8 (see
1334 /// `bdlde::Utf8Util::isValid`).
1335 template <class STRING_TYPE>
1337 Json>::type&
1338 operator=(BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) rhs);
1339
1340 /// Assign to this object a value of type `bool` initialized from the
1341 /// specified `rhs`, and return a reference providing modifiable access
1342 /// to this object. The value currently held by this object (if any) is
1343 /// destroyed if that value's type is not `bsl::string`.
1344 Json& operator=(bool rhs);
1345
1346 /// Assign to this object a value of type `JsonObject` initialized from
1347 /// the specified `rhs`, and return a reference providing modifiable
1348 /// access to this object. The value currently held by this object (if
1349 /// any) is destroyed if that value's type is not `JsonObject`.
1350 Json& operator=(const JsonObject& rhs);
1351
1352 /// Assign to this object the value of the specified `rhs` object, and
1353 /// return a reference providing modifiable access to this object. The
1354 /// contents of `rhs` are moved (in constant time) to this `Json` object
1355 /// if `allocator() == rhs.allocator()`; otherwise, they are copied.
1356 /// `rhs` is left in a valid but unspecified state. The value currently
1357 /// held by this object (if any) is destroyed if that value's type is
1358 /// not `JsonObject`.
1360
1361 /// Assign to this object a value of type `JsonArray` initialized from
1362 /// the specified `rhs`, and return a reference providing modifiable
1363 /// access to this object. The value currently held by this object (if
1364 /// any) is destroyed if that value's type is not `JsonArray`.
1365 Json& operator=(const JsonArray& rhs);
1366
1367 /// Assign to this object the value of the specified `rhs` object, and
1368 /// return a reference providing modifiable access to this object. The
1369 /// contents of `rhs` are moved (in constant time) to this `Json` object
1370 /// if `allocator() == rhs.allocator()`; otherwise, they are copied.
1371 /// `rhs` is left in a valid but unspecified state. The value currently
1372 /// held by this object (if any) is destroyed if that value's type is
1373 /// not `JsonArray`.
1375
1376 /// Assign to this object the singleton value of type `JsonNull`, and
1377 /// return a reference providing modifiable access to this object. The
1378 /// value currently held by this object (if any) is destroyed if that
1379 /// value's type is not `JsonNull`.
1380 Json& operator=(const JsonNull&);
1381
1382 /// Assign to this object the singleton value of type `JsonNull`, and
1383 /// return a reference providing modifiable access to this object.
1384 /// `rhs` is left in a valid but unspecified state. The value currently
1385 /// held by this object (if any) is destroyed if that value's type is
1386 /// not `JsonNull`.
1388
1389 /// Create an instance of type `JsonArray` in this object, using the
1390 /// allocator currently held by this object to supply memory, and return
1391 /// a reference providing modifiable access to the created instance.
1392 /// Optionally specify `array` to initialize the `JsonArray` created.
1393 /// This method first destroys the current value held by this object
1394 /// (even if the type currently held is `JsonArray`).
1395 JsonArray& makeArray();
1396 JsonArray& makeArray(const JsonArray& array);
1397 JsonArray& makeArray(bslmf::MovableRef<JsonArray> array);
1398
1399 /// Create an instance of type `bool` in this object and return a
1400 /// reference providing modifiable access to the created instance.
1401 /// Optionally specify `boolean` to initialize the `bool` created. This
1402 /// method first destroys the current value held by this object.
1403 bool& makeBoolean();
1404 bool& makeBoolean(bool boolean);
1405
1406 /// Create an instance of type `JsonNull` in this object. This method
1407 /// first destroys the current value held by this object.
1408 void makeNull();
1409
1410 /// Create an instance of type `JsonNumber` in this object, using the
1411 /// allocator currently held by this object to supply memory, and return
1412 /// a reference providing modifiable access to the created instance.
1413 /// Optionally specify `number` to initialize the `JsonNumber` created.
1414 /// This method first destroys the current value held by this object
1415 /// (even if the type currently held is `JsonNumber`).
1416 JsonNumber& makeNumber();
1417 JsonNumber& makeNumber(const JsonNumber& number);
1418 JsonNumber& makeNumber(bslmf::MovableRef<JsonNumber> number);
1419
1420 /// Create an instance of type `JsonObject` in this object, using the
1421 /// allocator currently held by this object to supply memory, and return
1422 /// a reference providing modifiable access to the created instance.
1423 /// Optionally specify `object` to initialize the `JsonObject` created.
1424 /// This method first destroys the current value held by this object
1425 /// (even if the type currently held is `JsonObject`).
1426 JsonObject& makeObject();
1427 JsonObject& makeObject(const JsonObject& object);
1428 JsonObject& makeObject(bslmf::MovableRef<JsonObject> object);
1429
1430 // BDE_VERIFY pragma: -FD06 'string' and 'bsl::string' are too similar
1431 // BDE_VERIFY pragma: -FD07 'string' and 'bsl::string' are too similar
1432
1433 void makeString(const char *string);
1434 /// Create an instance of type `bsl::string` in this object, using the
1435 /// allocator currently held by this object to supply memory.
1436 /// Optionally specify `string` to initialize the `bsl::string` created.
1437 /// This method first destroys the current value held by this object
1438 /// (even if the type currently held is `bsl::string`). The behavior is
1439 /// undefined unless `string` is valid UTF-8 (see
1440 /// `bdlde::Utf8Util::isValid`).
1441 void makeString(const bsl::string_view& string);
1442
1443 /// Create an instance of type `bsl::string` in this object, using the
1444 /// allocator currently held by this object to supply memory.
1445 /// Optionally specify `string` to initialize the `bsl::string` created.
1446 /// This method first destroys the current value held by this object
1447 /// (even if the type currently held is `bsl::string`). This function
1448 /// does not participate in overload resolution unless the specified
1449 /// `STRING_TYPE` is `bsl::string`. The behavior is undefined unless
1450 /// `string` is valid UTF-8 (see `bdlde::Utf8Util::isValid`).
1451 template <class STRING_TYPE>
1452 typename bsl::enable_if<bsl::is_same<STRING_TYPE,
1453 bsl::string>::value>::type
1454 makeString(BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) string);
1455
1456 // BDE_VERIFY pragma: +FD06 'string' and 'bsl::string' are too similar
1457 // BDE_VERIFY pragma: +FD07 'string' and 'bsl::string' are too similar
1458
1459 /// Exchange the value of this with that of the specified `other`. If
1460 /// an exception is thrown, both objects are left in valid but
1461 /// unspecified states. This operation guarantees O[1] complexity. The
1462 /// behavior is undefined unless this object was created with the same
1463 /// allocator as `other`.
1464 void swap(Json& other);
1465
1466 /// Return a reference providing modifiable access to the value of type
1467 /// `JsonArray` held by this object. The behavior is undefined unless
1468 /// `isArray()` returns true.
1469 JsonArray& theArray();
1470
1471 /// Return a reference providing modifiable access to the value of type
1472 /// `boolean` held by this object. The behavior is undefined unless
1473 /// `isBoolean()` returns true.
1474 bool& theBoolean();
1475
1476 /// Return a reference providing modifiable access to the value of type
1477 /// `JsonNull` held by this object. The behavior is undefined unless
1478 /// `isNull()` returns true.
1479 JsonNull& theNull();
1480
1481 /// Return a reference providing modifiable access to the value of type
1482 /// `JsonNumber` held by this object. The behavior is undefined unless
1483 /// `isNumber()` returns true.
1484 JsonNumber& theNumber();
1485
1486 /// Return a reference providing modifiable access to the value of type
1487 /// `JsonObject` held by this object. The behavior is undefined unless
1488 /// `isObject()` returns true.
1489 JsonObject& theObject();
1490
1491#if defined(BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT)
1492 /// Return a reference providing modifiable access to the value of type
1493 /// `JsonArray` held by this object. The behavior is undefined unless
1494 /// `isArray()` returns true.
1495 explicit operator JsonArray &();
1496
1497 /// Return a reference providing modifiable access to the value of type
1498 /// `boolean` held by this object. The behavior is undefined unless
1499 /// `isBoolean()` returns true.
1500 explicit operator bool &();
1501
1502 /// Return a reference providing modifiable access to the value of type
1503 /// `JsonNull` held by this object. The behavior is undefined unless
1504 /// `isNull()` returns true.
1505 explicit operator JsonNull &();
1506
1507 /// Return a reference providing modifiable access to the value of type
1508 /// `JsonNumber` held by this object. The behavior is undefined unless
1509 /// `isNumber()` returns true.
1510 explicit operator JsonNumber &();
1511
1512 /// Return a reference providing modifiable access to the value of type
1513 /// `JsonObject` held by this object. The behavior is undefined unless
1514 /// `isObject()` returns true.
1515 explicit operator JsonObject &();
1516#endif
1517
1518 /// Return a reference providing modifiable access to the `Json` object
1519 /// associated with the specified `key` in the `JsonObject` held by this
1520 /// object; if the `JsonObject` does not already contain a `Json` object
1521 /// associated with `key`, first insert a new default-constructed `Json`
1522 /// object associated with `key`. The behavior is undefined unless
1523 /// `isObject()` returns true.
1524 Json& operator[](const bsl::string_view& key);
1525
1526 /// Return a reference providing modifiable access to the element at the
1527 /// specified `index` in the `JsonArray` held by this object. The
1528 /// behavior is undefined unless `isArray()` returns true and
1529 /// `index < theArray().size()`.
1530 Json& operator[](bsl::size_t index);
1531
1532 // ACCESSORS
1533 // BDE_VERIFY pragma: -FABC01
1534
1535 /// Load into the specified `result` the integer value of the value of type
1536 /// `JsonNumber` held by this object. Return 0 on success,
1537 /// `JsonNumber::k_OVERFLOW` if `value` is larger than can be represented
1538 /// by `result`, `JsonNumber::k_UNDERFLOW` if `value` is smaller than can
1539 /// be represented by `result`, and `JsonNumber::k_NOT_INTEGRAL` if `value`
1540 /// is not an integral number (i.e., there is a fractional part). For
1541 /// underflow, `result` will be loaded with the minimum representable
1542 /// value, for overflow, `result` will be loaded with the maximum
1543 /// representable value, for non-integral values `result` will be loaded
1544 /// with the integer part of `value` (truncating the value to the nearest
1545 /// integer). If the result is not an integer and also either overflows or
1546 /// underflows, it is treated as an overflow or underflow (respectively).
1547 /// Note that this operation returns a status value (unlike similar
1548 /// floating point conversions) because typically it is an error if a
1549 /// conversion to an integer results in an inexact value. The behavior is
1550 /// undefined unless `isNumber()` returns true.
1551 int asInt(int *result) const;
1552 int asInt64(bsls::Types::Int64 *result) const;
1553 int asUint(unsigned int *result) const;
1554 int asUint64(bsls::Types::Uint64 *result) const;
1555
1556 /// Return the closest floating point representation to the value of the
1557 /// type `JsonNumber` held by this object. If this number is outside the
1558 /// representable range, return +INF or -INF (as appropriate). The
1559 /// behavior is undefined unless `isNumber()` returns true.
1560 float asFloat() const;
1561 double asDouble() const;
1562 bdldfp::Decimal64 asDecimal64() const;
1563
1564 // BDE_VERIFY pragma: +FABC01
1565
1566 /// Load the specified `result` with the closest floating point
1567 /// representation to the value of type `JsonNumber` held by this
1568 /// object, even if a non-zero status is returned. Return 0 if this
1569 /// number can be represented exactly, and return
1570 /// `JsonNumber::k_INEXACT` if `value` cannot be represented exactly.
1571 /// If this number is outside the representable range, load `result`
1572 /// with +INF or -INF (as appropriate). A number can be represented
1573 /// exactly as a `Decimal64` if, for the significand and exponent,
1574 /// `abs(significand) <= 9,999,999,999,999,999` and '-398 <= exponent <=
1575 /// 369'. The behavior is undefined unless `isNumber()` returns true;
1576 int asDecimal64Exact(bdldfp::Decimal64 *result) const;
1577
1578 /// Return true if the value held by this object is of type `JsonArray`,
1579 /// and false otherwise.
1580 bool isArray() const;
1581
1582 /// Return true if the value held by this object is of type `bool`, and
1583 /// false otherwise.
1584 bool isBoolean() const;
1585
1586 /// Return true if the value held by this object is of type `JsonNull`,
1587 /// and false otherwise.
1588 bool isNull() const;
1589
1590 /// Return true if the value held by this object is of type
1591 /// `JsonNumber`, and false otherwise.
1592 bool isNumber() const;
1593
1594 /// Return true if the value held by this object is of type
1595 /// `JsonObject`, and false otherwise.
1596 bool isObject() const;
1597
1598 /// Return true if the value held by this object is of type
1599 /// `bsl::string`, and false otherwise.
1600 bool isString() const;
1601
1602 /// Return a reference providing non-modifiable access to the value of
1603 /// type `JsonArray` held by this object. The behavior is undefined
1604 /// unless `isArray()` returns true.
1605 const JsonArray& theArray() const;
1606
1607 /// Return a reference providing non-modifiable access to the value of
1608 /// type `boolean` held by this object. The behavior is undefined
1609 /// unless `isBoolean()` returns true.
1610 const bool& theBoolean() const;
1611
1612 /// Return a reference providing non-modifiable access to the value of
1613 /// type `JsonNull` held by this object. The behavior is undefined
1614 /// unless `isNull()` returns true.
1615 const JsonNull& theNull() const;
1616
1617 /// Return a reference providing non-modifiable access to the value of
1618 /// type `JsonNumber` held by this object. The behavior is undefined
1619 /// unless `isNumber()` returns true.
1620 const JsonNumber& theNumber() const;
1621
1622 /// Return a reference providing non-modifiable access to the value of
1623 /// type `JsonObject` held by this object. The behavior is undefined
1624 /// unless `isObject()` returns true.
1625 const JsonObject& theObject() const;
1626
1627 /// Return a reference providing non-modifiable access to the value of
1628 /// type `JsonString` held by this object. The behavior is undefined
1629 /// unless `isString()` returns true.
1630 const bsl::string& theString() const;
1631
1632 /// Return the type of this `Json` value.
1634
1635 /// Return a reference providing non-modifiable access to the `Json`
1636 /// object associated with the specified `key` in this `JsonObject`.
1637 /// The behavior is undefined unless `key` is valid UTF-8 (see
1638 /// `bdlde::Utf8Util::isValid`) and this `JsonObject` already contains a
1639 /// `Json` object associated with `key`.
1640 const Json& operator[](const bsl::string_view& key) const;
1641
1642 /// Return a reference providing non-modifiable access to the element at
1643 /// the specified `index` in the `JsonArray` held by this object. The
1644 /// behavior is undefined unless `isArray()` returns true and
1645 /// `index < theArray().size()`.
1646 const Json& operator[](bsl::size_t index) const;
1647
1648#if defined(BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT)
1649 /// Return a reference providing non-modifiable access to the value of
1650 /// type `JsonArray` held by this object. The behavior is undefined
1651 /// unless `isArray()` returns true.
1652 explicit operator const JsonArray &() const;
1653
1654 /// Return a reference providing non-modifiable access to the value of
1655 /// type `boolean` held by this object. The behavior is undefined
1656 /// unless `isBoolean()` returns true.
1657 explicit operator const bool &() const;
1658
1659 /// Return a reference providing non-modifiable access to the value of
1660 /// type `JsonNull` held by this object. The behavior is undefined
1661 /// unless `isNull()` returns true.
1662 explicit operator const JsonNull &() const;
1663
1664 /// Return a reference providing non-modifiable access to the value of
1665 /// type `JsonNumber` held by this object. The behavior is undefined
1666 /// unless `isNumber()` returns true.
1667 explicit operator const JsonNumber &() const;
1668
1669 /// Return a reference providing non-modifiable access to the value of
1670 /// type `JsonObject` held by this object. The behavior is undefined
1671 /// unless `isObject()` returns true.
1672 explicit operator const JsonObject &() const;
1673
1674 /// Return a reference providing non-modifiable access to the value of
1675 /// type `JsonString` held by this object. The behavior is undefined
1676 /// unless `isString()` returns true.
1677 explicit operator const bsl::string &() const;
1678#endif
1679
1680 /// Return the number of elements in the `JsonObject` or `JsonArray`
1681 /// held by this object. The behavior is undefined unless
1682 /// `isArray() || isObject()` evaluates to true.
1683 bsl::size_t size() const;
1684
1685 // Aspects
1686
1687 /// Return the allocator used by this object to allocate memory.
1689
1690 /// Write the value of this object to the specified output `stream` in a
1691 /// human-readable format, and return a reference to `stream`.
1692 /// Optionally specify an initial indentation `level`, whose absolute
1693 /// value is incremented recursively for nested objects. If `level` is
1694 /// specified, optionally specify `spacesPerLevel`, whose absolute value
1695 /// indicates the number of spaces per indentation level for this and
1696 /// all of its nested objects. If `level` is negative, suppress
1697 /// indentation of the first line. If `spacesPerLevel` is negative,
1698 /// format the entire output on one line, suppressing all but the
1699 /// initial indentation (as governed by `level`). If `stream` is not
1700 /// valid on entry, this operation has no effect. Note that this
1701 /// human-readable format is not fully specified, and can change without
1702 /// notice.
1703 bsl::ostream& print(bsl::ostream& stream,
1704 int level = 0,
1705 int spacesPerLevel = 4) const;
1706};
1707
1708// FREE OPERATORS
1709
1710/// Write the value of the specified `object` to the specified output
1711/// `stream` in a single-line format, and return a reference to `stream`.
1712/// If `stream` is not valid on entry, this operation has no effect. Note
1713/// that this human-readable format is not fully specified, can change
1714/// without notice, and is logically equivalent to:
1715/// @code
1716/// print(stream, 0, -1);
1717/// @endcode
1718bsl::ostream& operator<<(bsl::ostream& stream, const Json& object);
1719
1720/// Return `true` if the specified `lhs` and `rhs` objects have the same
1721/// value, and `false` otherwise. Two `Json` objects `lhs` and `rhs` have
1722/// the same value if they hold objects of the same type, and those objects
1723/// have the same value.
1724bool operator==(const Json& lhs, const Json& rhs);
1725
1726/// Return `false` if the specified `lhs` and `rhs` objects have the same
1727/// value, and `true` otherwise. Two `Json` objects `lhs` and `rhs` have
1728/// the same value if they hold objects of the same type, and those objects
1729/// have the same value.
1730bool operator!=(const Json& lhs, const Json& rhs);
1731
1732/// Invoke the specified `hashAlg` on the attributes of the specified
1733/// `object`.
1734template <class HASHALG>
1735void hashAppend(HASHALG& hashAlg, const Json& object);
1736
1737/// Exchange the value of the specified `a` `Json` object with that of the
1738/// specified `b` `Json` object. If an exception is thrown, both objects
1739/// are left in valid but unspecified states. This operation guarantees
1740/// O[1] complexity. The behavior is undefined unless `a` was created with
1741/// the same allocator as `b`.
1742void swap(Json& a, Json& b);
1743
1744// ============================================================================
1745// INLINE DEFINITIONS
1746// ============================================================================
1747
1748 // ---------------
1749 // class JsonArray
1750 // ---------------
1751
1752// CREATORS
1753inline
1755: d_elements()
1756{
1757}
1758
1759inline
1761: d_elements(basicAllocator)
1762{
1763}
1764
1765inline
1767 bslma::Allocator *basicAllocator)
1768: d_elements(original.d_elements, basicAllocator)
1769{
1770}
1771
1772inline
1779
1780inline
1782 bslma::Allocator *basicAllocator)
1783: d_elements(basicAllocator)
1784{
1785 JsonArray& originalAsLvalue = bslmf::MovableRefUtil::access(original);
1786
1787 if (basicAllocator == originalAsLvalue.allocator()) {
1788 d_elements = bslmf::MovableRefUtil::move(originalAsLvalue.d_elements);
1789 }
1790 else {
1791 d_elements = originalAsLvalue.d_elements;
1792 }
1793}
1794
1795template <class INPUT_ITERATOR>
1796inline
1797JsonArray::JsonArray(INPUT_ITERATOR first,
1798 INPUT_ITERATOR last,
1799 bslma::Allocator *basicAllocator)
1800: d_elements(first, last, basicAllocator)
1801{
1802}
1803
1804#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1805inline
1806JsonArray::JsonArray(std::initializer_list<Json> elements,
1807 bslma::Allocator *basicAllocator)
1808: d_elements(elements, basicAllocator)
1809{
1810}
1811#endif
1812
1813// MANIPULATORS
1814inline
1816{
1817 d_elements = rhs.d_elements;
1818 return *this;
1819}
1820
1821inline
1823{
1824 d_elements = bslmf::MovableRefUtil::move(
1825 bslmf::MovableRefUtil::access(rhs).d_elements);
1826 return *this;
1827}
1828
1829#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1830inline
1831JsonArray& JsonArray::operator=(std::initializer_list<Json> initializer)
1832{
1833 d_elements = initializer;
1834 return *this;
1835}
1836#endif
1837
1838inline
1839Json& JsonArray::operator[](bsl::size_t index)
1840{
1841 BSLS_ASSERT(index < d_elements.size());
1842 return d_elements[index];
1843}
1844
1845template <class INPUT_ITERATOR>
1846inline
1847void JsonArray::assign(INPUT_ITERATOR first, INPUT_ITERATOR last)
1848{
1849 d_elements.assign(first, last);
1850}
1851
1852#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1853inline
1854void JsonArray::assign(std::initializer_list<Json> initializer)
1855{
1856 d_elements.assign(initializer);
1857}
1858#endif
1859
1860inline
1862{
1863 return d_elements.back();
1864}
1865
1866inline
1868{
1869 return d_elements.begin();
1870}
1871
1872inline
1874{
1875 d_elements.clear();
1876}
1877
1878inline
1880{
1881 return d_elements.end();
1882}
1883
1884inline
1886{
1887 return d_elements.erase(d_elements.begin() + index);
1888}
1889
1890inline
1892{
1893 return d_elements.erase(position);
1894}
1895
1896inline
1898{
1899 return d_elements.erase(first, last);
1900}
1901
1902inline
1904{
1905 return d_elements.front();
1906}
1907
1908inline
1909JsonArray::Iterator JsonArray::insert(bsl::size_t index, const Json& json)
1910{
1911 return d_elements.insert(d_elements.begin() + index, json);
1912}
1913
1914inline
1917{
1918 return d_elements.insert(d_elements.begin() + index,
1920}
1921
1922template <class INPUT_ITERATOR>
1923inline
1925 INPUT_ITERATOR first,
1926 INPUT_ITERATOR last)
1927{
1928 return d_elements.insert(d_elements.begin() + index, first, last);
1929}
1930
1931inline
1933{
1934 return d_elements.insert(position, json);
1935}
1936
1937inline
1940{
1941 return d_elements.insert(position, bslmf::MovableRefUtil::move(json));
1942}
1943
1944template <class INPUT_ITERATOR>
1945inline
1947 INPUT_ITERATOR first,
1948 INPUT_ITERATOR last)
1949{
1950 return d_elements.insert(position, first, last);
1951}
1952
1953inline
1955{
1956 d_elements.pop_back();
1957}
1958
1959inline
1960void JsonArray::pushBack(const Json& json)
1961{
1962 d_elements.push_back(json);
1963}
1964
1965inline
1970
1971inline
1972void JsonArray::resize(bsl::size_t count)
1973{
1974 d_elements.resize(count);
1975}
1976
1977inline
1978void JsonArray::resize(bsl::size_t count, const Json& json)
1979{
1980 d_elements.resize(count, json);
1981}
1982
1983inline
1985{
1986 BSLS_ASSERT(allocator() == other.allocator());
1987 d_elements.swap(other.d_elements);
1988}
1989
1990// ACCESSORS
1991inline
1992const Json& JsonArray::operator[](bsl::size_t index) const
1993{
1994 BSLS_ASSERT(index < d_elements.size());
1995 return d_elements[index];
1996}
1997
1998inline
2003
2004inline
2005const Json& JsonArray::back() const
2006{
2007 return d_elements.back();
2008}
2009
2010inline
2012{
2013 return d_elements.begin();
2014}
2015
2016inline
2018{
2019 return d_elements.begin();
2020}
2021
2022inline
2024{
2025 return d_elements.end();
2026}
2027
2028inline
2030{
2031 return d_elements.empty();
2032}
2033
2034inline
2036{
2037 return d_elements.end();
2038}
2039
2040inline
2042{
2043 return d_elements.front();
2044}
2045
2046inline
2048{
2049 return d_elements.max_size();
2050}
2051
2052inline
2053bsl::size_t JsonArray::size() const
2054{
2055 return d_elements.size();
2056}
2057
2058 // ----------------
2059 // class JsonObject
2060 // ----------------
2061
2062// CREATORS
2063inline
2065: d_members()
2066{
2067}
2068
2069inline
2071: d_members(basicAllocator)
2072{
2073}
2074
2075inline
2077 bslma::Allocator *basicAllocator)
2078: d_members(original.d_members, basicAllocator)
2079{
2080}
2081
2082inline
2089
2090inline
2092 bslma::Allocator *basicAllocator)
2093: d_members(basicAllocator)
2094{
2095 JsonObject& originalAsLvalue = bslmf::MovableRefUtil::access(original);
2096
2097 if (basicAllocator == originalAsLvalue.allocator()) {
2098 d_members = bslmf::MovableRefUtil::move(originalAsLvalue.d_members);
2099 }
2100 else {
2101 d_members = originalAsLvalue.d_members;
2102 }
2103}
2104
2105template <class INPUT_ITERATOR>
2106inline
2107JsonObject::JsonObject(INPUT_ITERATOR first,
2108 INPUT_ITERATOR last,
2109 bslma::Allocator *basicAllocator)
2110: d_members(first, last, basicAllocator)
2111{
2112#ifdef BSLS_ASSERT_IS_ACTIVE
2113 for (Container::const_iterator iter = d_members.begin();
2114 iter != d_members.end();
2115 ++iter) {
2116 BSLS_ASSERT(bdlde::Utf8Util::isValid(iter->first.data(),
2117 iter->first.size()));
2118 }
2119#endif
2120}
2121
2122#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2123inline
2124JsonObject::JsonObject(std::initializer_list<Member> members,
2125 bslma::Allocator *basicAllocator)
2126: d_members(members, basicAllocator)
2127{
2128#ifdef BSLS_ASSERT_IS_ACTIVE
2129 for (Container::const_iterator iter = d_members.begin();
2130 iter != d_members.end();
2131 ++iter) {
2132 BSLS_ASSERT(bdlde::Utf8Util::isValid(iter->first.data(),
2133 iter->first.size()));
2134 }
2135#endif
2136}
2137#endif
2138
2139// MANIPULATORS
2140inline
2142{
2143 d_members = rhs.d_members;
2144 return *this;
2145}
2146
2147inline
2149{
2150 Container& rhsMembers = bslmf::MovableRefUtil::access(rhs).d_members;
2151 if (d_members.get_allocator() == rhsMembers.get_allocator()) {
2152 d_members = bslmf::MovableRefUtil::move(rhsMembers);
2153 }
2154 else {
2155 d_members = rhsMembers;
2156 }
2157 return *this;
2158}
2159
2160#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2161inline
2162JsonObject& JsonObject::operator=(std::initializer_list<Member> members)
2163{
2164 d_members = members;
2165 return *this;
2166}
2167#endif
2168
2169inline
2171{
2173
2174 Iterator it = d_members.find(key);
2175 if (it != d_members.end()) {
2176 return it->second; // RETURN
2177 }
2178
2179#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_PAIR_PIECEWISE_CONSTRUCTOR)
2180 return d_members.emplace(std::piecewise_construct,
2181 std::forward_as_tuple(key),
2182 std::forward_as_tuple())
2183 .first->second;
2184#else
2185 bslma::Allocator *alloc = allocator();
2187 value.first = key;
2188 return d_members.emplace(bslmf::MovableRefUtil::move(value)).first->second;
2189#endif
2190}
2191
2192inline
2197
2198inline
2200{
2201 d_members.clear();
2202}
2203
2204inline
2206{
2207 return d_members.end();
2208}
2209
2210inline
2212{
2213 Iterator it = d_members.find(key);
2214 if (it == d_members.end()) {
2215 return 0; // RETURN
2216 }
2217 d_members.erase(it);
2218 return 1;
2219}
2220
2221inline
2223{
2224 return d_members.erase(position);
2225}
2226
2227inline
2229{
2230 return d_members.erase(position);
2231}
2232
2233inline
2235{
2236 return d_members.find(key);
2237}
2238
2239inline
2241{
2242 return d_members.insert(member);
2243}
2244
2245inline
2248{
2249#ifdef BSLS_ASSERT_IS_ACTIVE
2250 const bsl::string& key = bslmf::MovableRefUtil::access(member).first;
2252#endif
2253 return d_members.insert(bslmf::MovableRefUtil::move(member));
2254}
2255
2256template <class INPUT_ITERATOR>
2257inline
2258typename bsl::enable_if<
2260 void>::type
2261JsonObject::insert(INPUT_ITERATOR first, INPUT_ITERATOR last)
2262{
2263 d_members.insert(first, last);
2264#ifdef BSLS_ASSERT_SAFE_IS_ACTIVE
2265 for (Container::const_iterator iter = d_members.begin();
2266 iter != d_members.end();
2267 ++iter) {
2269 bdlde::Utf8Util::isValid(iter->first.data(), iter->first.size()));
2270 }
2271#endif
2272}
2273
2274#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2275inline
2276void JsonObject::insert(std::initializer_list<Member> members)
2277{
2278#ifdef BSLS_ASSERT_IS_ACTIVE
2279 for (auto member : members) {
2280 BSLS_ASSERT(bdlde::Utf8Util::isValid(member.first.data(),
2281 member.first.size()));
2282 }
2283#endif
2284 d_members.insert(members);
2285}
2286#endif
2287
2288template <class VALUE>
2290 const bsl::string_view& key,
2292{
2294 Json json(BSLS_COMPILERFEATURES_FORWARD(VALUE, value), allocator());
2295 Member member(key, Json(), allocator());
2296 member.second = bslmf::MovableRefUtil::move(json);
2297 return insert(bslmf::MovableRefUtil::move(member));
2298}
2299
2300inline
2302{
2303 BSLS_ASSERT(allocator() == other.allocator());
2304 d_members.swap(other.d_members);
2305}
2306
2307// ACCESSORS
2308inline
2310{
2311 ConstIterator it = d_members.find(key);
2312 BSLS_ASSERT(it != d_members.end());
2313 return it->second;
2314}
2315
2316inline
2321
2322inline
2324{
2325 return d_members.begin();
2326}
2327
2328inline
2333
2334inline
2336{
2337 return d_members.cend();
2338}
2339
2340inline
2342{
2343 return d_members.find(key) != d_members.end();
2344}
2345
2346inline
2348{
2349 return d_members.empty();
2350}
2351
2352inline
2354{
2355 return d_members.end();
2356}
2357
2358inline
2360{
2361 return d_members.find(key);
2362}
2363
2364inline
2366{
2367 return d_members.size();
2368}
2369 // ----------
2370 // class Json
2371 // ----------
2372
2373// CREATORS
2374inline
2376: d_value(JsonNull())
2377{
2378}
2379
2380inline
2382: d_value(JsonNull(), basicAllocator)
2383{
2384}
2385
2386inline
2387Json::Json(const Json& original, bslma::Allocator *basicAllocator)
2388: d_value(original.d_value, basicAllocator)
2389{
2390}
2391
2392inline
2394: d_value(bslmf::MovableRefUtil::move(
2395 bslmf::MovableRefUtil::access(original).d_value))
2396{
2397}
2398
2399inline
2401: d_value(bslmf::MovableRefUtil::move(
2402 bslmf::MovableRefUtil::access(original).d_value),
2403 basicAllocator)
2404{
2405}
2406
2407inline
2408Json::Json(const JsonArray& array, bslma::Allocator *basicAllocator)
2409: d_value(array, basicAllocator)
2410{
2411}
2412
2413inline
2415 bslma::Allocator *basicAllocator)
2416: d_value(bslmf::MovableRefUtil::move(array), basicAllocator)
2417{
2418}
2419
2420inline
2421Json::Json(bool boolean, bslma::Allocator *basicAllocator)
2422: d_value(boolean, basicAllocator)
2423{
2424}
2425
2426inline
2427Json::Json(const JsonNull& null, bslma::Allocator *basicAllocator)
2428: d_value(null, basicAllocator)
2429{
2430}
2431
2432inline
2433Json::Json(float number, bslma::Allocator *basicAllocator)
2434: d_value(JsonNumber(number), basicAllocator)
2435{
2436}
2437
2438inline
2439Json::Json(double number, bslma::Allocator *basicAllocator)
2440: d_value(JsonNumber(number), basicAllocator)
2441{
2442}
2443
2444inline
2446: d_value(JsonNumber(number), basicAllocator)
2447{
2448}
2449
2450inline
2451Json::Json(int number, bslma::Allocator *basicAllocator)
2452: d_value(JsonNumber(number), basicAllocator)
2453{
2454}
2455
2456inline
2457Json::Json(unsigned int number, bslma::Allocator *basicAllocator)
2458: d_value(JsonNumber(number), basicAllocator)
2459{
2460}
2461
2462inline
2464: d_value(JsonNumber(number), basicAllocator)
2465{
2466}
2467
2468inline
2470: d_value(JsonNumber(number), basicAllocator)
2471{
2472}
2473
2474inline
2475Json::Json(const JsonNumber& number, bslma::Allocator *basicAllocator)
2476: d_value(number, basicAllocator)
2477{
2478}
2479
2480inline
2482 bslma::Allocator *basicAllocator)
2483: d_value(bslmf::MovableRefUtil::move(number), basicAllocator)
2484{
2485}
2486
2487inline
2488Json::Json(const JsonObject& object, bslma::Allocator *basicAllocator)
2489: d_value(object, basicAllocator)
2490{
2491}
2492
2493inline
2495 bslma::Allocator *basicAllocator)
2496: d_value(bslmf::MovableRefUtil::move(object), basicAllocator)
2497{
2498}
2499
2500inline
2501Json::Json(const char *string, bslma::Allocator *basicAllocator)
2502: d_value(basicAllocator)
2503{
2505 d_value.createInPlace<bsl::string>(string);
2506}
2507
2508inline
2509Json::Json(const bsl::string_view& string, bslma::Allocator *basicAllocator)
2510: d_value(basicAllocator)
2511{
2513 d_value.createInPlace<bsl::string>(string);
2514}
2515
2516template <class STRING_TYPE>
2517inline
2519 bslma::Allocator *basicAllocator,
2520 typename bsl::enable_if<
2522: d_value(bslmf::MovableRefUtil::move(string), basicAllocator)
2523{
2526}
2527
2528// MANIPULATORS
2529inline
2531{
2532 d_value = rhs.d_value;
2533 return *this;
2534}
2535
2536inline
2538{
2539 Json& rhsRef = bslmf::MovableRefUtil::access(rhs);
2540 d_value = bslmf::MovableRefUtil::move(rhsRef.d_value);
2541 return *this;
2542}
2543
2544inline
2546{
2547 d_value.createInPlace<JsonNumber>(rhs);
2548 return *this;
2549}
2550
2551inline
2553{
2554 d_value.createInPlace<JsonNumber>(rhs);
2555 return *this;
2556}
2557
2558inline
2560{
2561 d_value.createInPlace<JsonNumber>(rhs);
2562 return *this;
2563}
2564
2565inline
2567{
2568 d_value.createInPlace<JsonNumber>(rhs);
2569 return *this;
2570}
2571
2572inline
2573Json& Json::operator=(unsigned int rhs)
2574{
2575 d_value.createInPlace<JsonNumber>(rhs);
2576 return *this;
2577}
2578
2579inline
2581{
2582 d_value.createInPlace<JsonNumber>(rhs);
2583 return *this;
2584}
2585
2586inline
2588{
2589 d_value.createInPlace<JsonNumber>(rhs);
2590 return *this;
2591}
2592
2593inline
2595{
2596 d_value.createInPlace<JsonNumber>(rhs);
2597 return *this;
2598}
2599
2600inline
2602{
2603 d_value = bslmf::MovableRefUtil::move(rhs);
2604 return *this;
2605}
2606
2607inline
2608Json& Json::operator=(const char *rhs)
2609{
2610 makeString(rhs);
2611 return *this;
2612}
2613
2614inline
2616{
2617 makeString(rhs);
2618 return *this;
2619}
2620
2621template <class STRING_TYPE>
2623 Json>::type&
2625{
2627 return *this;
2628}
2629
2630inline
2632{
2633 makeBoolean(rhs);
2634 return *this;
2635}
2636
2637inline
2639{
2640 makeObject(rhs);
2641 return *this;
2642}
2643
2644inline
2650
2651inline
2653{
2654 makeArray(rhs);
2655 return *this;
2656}
2657
2658inline
2664
2665inline
2667{
2668 makeNull();
2669 return *this;
2670}
2671
2672inline
2674{
2675 makeNull();
2676 return *this;
2677}
2678
2679inline
2681{
2682 return d_value.createInPlace<JsonArray>();
2683}
2684
2685inline
2687{
2688 d_value = array;
2689 return d_value.the<JsonArray>();
2690}
2691
2692inline
2694{
2695 d_value = bslmf::MovableRefUtil::move(array);
2696 return d_value.the<JsonArray>();
2697}
2698
2699inline
2701{
2702 return d_value.createInPlace<bool>();
2703}
2704
2705inline
2706bool& Json::makeBoolean(bool boolean)
2707{
2708 d_value = boolean;
2709 return d_value.the<bool>();
2710}
2711
2712inline
2714{
2715 d_value.createInPlace<JsonNull>();
2716}
2717
2718inline
2720{
2721 return d_value.createInPlace<JsonNumber>();
2722}
2723
2724inline
2726{
2727 d_value = number;
2728 return d_value.the<JsonNumber>();
2729}
2730
2731inline
2733{
2734 d_value = bslmf::MovableRefUtil::move(number);
2735 return d_value.the<JsonNumber>();
2736}
2737
2738inline
2740{
2741 return d_value.createInPlace<JsonObject>();
2742}
2743
2744inline
2746{
2747 d_value = object;
2748 return d_value.the<JsonObject>();
2749}
2750
2751inline
2753{
2754 d_value = bslmf::MovableRefUtil::move(object);
2755 return d_value.the<JsonObject>();
2756}
2757
2758inline
2759void Json::makeString(const char *string)
2760{
2762 d_value.createInPlace<bsl::string>(string);
2763}
2764
2765inline
2767{
2768 BSLS_ASSERT(bdlde::Utf8Util::isValid(string.data(), string.size()));
2769 d_value.createInPlace<bsl::string>(string);
2770}
2771
2772template <class STRING_TYPE>
2773inline
2781
2782inline
2783void Json::swap(Json& other)
2784{
2785 BSLS_ASSERT(allocator() == other.allocator());
2786 d_value.swap(other.d_value);
2787}
2788
2789// ACCESSORS
2790inline
2791bool Json::isArray() const
2792{
2793 return type() == JsonType::e_ARRAY;
2794}
2795
2796inline
2798{
2799 return type() == JsonType::e_BOOLEAN;
2800}
2801
2802inline
2803bool Json::isNull() const
2804{
2805 return type() == JsonType::e_NULL;
2806}
2807
2808inline
2809bool Json::isNumber() const
2810{
2811 return type() == JsonType::e_NUMBER;
2812}
2813
2814inline
2815bool Json::isObject() const
2816{
2817 return type() == JsonType::e_OBJECT;
2818}
2819
2820inline
2821bool Json::isString() const
2822{
2823 return type() == JsonType::e_STRING;
2824}
2825
2826inline
2828{
2829 return d_value.the<JsonArray>();
2830}
2831
2832inline
2834{
2835 return d_value.the<bool>();
2836}
2837
2838inline
2840{
2841 return d_value.the<JsonNull>();
2842}
2843
2844inline
2846{
2847 return d_value.the<JsonNumber>();
2848}
2849
2850inline
2852{
2853 return d_value.the<JsonObject>();
2854}
2855
2856#if defined(BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT)
2857inline
2858Json::operator JsonArray &()
2859{
2860 return theArray();
2861}
2862
2863inline
2864Json::operator bool &()
2865{
2866 return theBoolean();
2867}
2868
2869inline
2870Json::operator JsonNull &()
2871{
2872 return theNull();
2873}
2874
2875inline
2876Json::operator JsonNumber &()
2877{
2878 return theNumber();
2879}
2880
2881inline
2882Json::operator JsonObject &()
2883{
2884 return theObject();
2885}
2886#endif
2887
2888inline
2890{
2891 BSLS_ASSERT(d_value.is<JsonObject>());
2892 return theObject()[key];
2893}
2894
2895inline
2896Json& Json::operator[](bsl::size_t index)
2897{
2898 BSLS_ASSERT(d_value.is<JsonArray>());
2899 return theArray()[index];
2900}
2901
2902inline
2903bsl::size_t Json::size() const
2904{
2906 return isArray() ? theArray().size() : theObject().size();
2907}
2908
2909// ACCESSORS
2910inline
2912{
2913 return d_value.getAllocator();
2914}
2915
2916inline
2918{
2920 return theNumber().asDecimal64();
2921}
2922
2923inline
2925{
2927 return theNumber().asDecimal64Exact(result);
2928}
2929
2930inline
2931double Json::asDouble() const
2932{
2934 return theNumber().asDouble();
2935}
2936
2937inline
2938float Json::asFloat() const
2939{
2941 return theNumber().asFloat();
2942}
2943
2944inline
2945int Json::asInt(int *result) const
2946{
2948 return theNumber().asInt(result);
2949}
2950
2951inline
2953{
2955 return theNumber().asInt64(result);
2956}
2957
2958inline
2959int Json::asUint(unsigned int *result) const
2960{
2962 return theNumber().asUint(result);
2963}
2964
2965inline
2967{
2969 return theNumber().asUint64(result);
2970}
2971
2972
2973inline
2975{
2976 return d_value.the<JsonArray>();
2977}
2978
2979inline
2980const bool& Json::theBoolean() const
2981{
2982 return d_value.the<bool>();
2983}
2984
2985inline
2987{
2988 return d_value.the<JsonNull>();
2989}
2990
2991inline
2993{
2994 return d_value.the<JsonNumber>();
2995}
2996
2997inline
2999{
3000 return d_value.the<JsonObject>();
3001}
3002
3003inline
3005{
3006 return d_value.the<bsl::string>();
3007}
3008
3009inline
3011{
3012 return static_cast<JsonType::Enum>(d_value.typeIndex() - 1);
3013}
3014inline
3016{
3017 BSLS_ASSERT(d_value.is<JsonObject>());
3018 return theObject()[key];
3019}
3020
3021inline
3022const Json& Json::operator[](bsl::size_t index) const
3023{
3024 BSLS_ASSERT(d_value.is<JsonArray>());
3025 return theArray()[index];
3026}
3027
3028#if defined(BSLS_COMPILERFEATURES_SUPPORT_OPERATOR_EXPLICIT)
3029inline
3030Json::operator const JsonArray &() const
3031{
3032 return theArray();
3033}
3034
3035inline
3036Json::operator const bool &() const
3037{
3038 return theBoolean();
3039}
3040
3041inline
3042Json::operator const JsonNull &() const
3043{
3044 return theNull();
3045}
3046
3047inline
3048Json::operator const JsonNumber &() const
3049{
3050 return theNumber();
3051}
3052
3053inline
3054Json::operator const JsonObject &() const
3055{
3056 return theObject();
3057}
3058
3059inline
3060Json::operator const bsl::string &() const
3061{
3062 return theString();
3063}
3064#endif
3065
3066} // close package namespace
3067
3068// FREE OPERATORS
3069inline
3070bsl::ostream& bdljsn::operator<<(bsl::ostream& stream,
3071 const bdljsn::JsonArray& object)
3072{
3073 return object.print(stream, 0, -1);
3074}
3075
3076inline
3078 const bdljsn::JsonArray& rhs)
3079{
3080 return lhs.d_elements == rhs.d_elements;
3081}
3082
3083inline
3085 const bdljsn::JsonArray& rhs)
3086{
3087 return lhs.d_elements != rhs.d_elements;
3088}
3089
3090template <class HASHALG>
3091inline
3092void bdljsn::hashAppend(HASHALG& hashAlg, const bdljsn::JsonArray& object)
3093{
3094 hashAppend(hashAlg, object.d_elements);
3095}
3096
3097inline
3099{
3100 bslalg::SwapUtil::swap(&a.d_elements, &b.d_elements);
3101}
3102
3103inline
3104bsl::ostream& bdljsn::operator<<(bsl::ostream& stream,
3105 const bdljsn::JsonObject& object)
3106{
3107 return object.print(stream, 0, -1);
3108}
3109
3110inline
3112 const bdljsn::JsonObject& rhs)
3113{
3114 return lhs.d_members == rhs.d_members;
3115}
3116
3117inline
3119 const bdljsn::JsonObject& rhs)
3120{
3121 return lhs.d_members != rhs.d_members;
3122}
3123
3124template <class HASHALG>
3125inline
3126void bdljsn::hashAppend(HASHALG& hashAlg, const bdljsn::JsonObject& object)
3127{
3128 hashAppend(hashAlg, object.d_members);
3129}
3130
3131inline
3133{
3134 if (a.allocator() == b.allocator()) {
3135 bslalg::SwapUtil::swap(&a.d_members, &b.d_members);
3136 }
3137 else {
3138 bslma::Allocator *const allocA = a.allocator();
3139 bslma::Allocator *const allocB = b.allocator();
3140 JsonObject ta(b, allocA);
3141 JsonObject tb(a, allocB);
3142 swap(a, ta);
3143 swap(b, tb);
3144 }
3145}
3146
3147inline
3148bsl::ostream& bdljsn::operator<<(bsl::ostream& stream,
3149 const bdljsn::Json& object)
3150{
3151 return object.print(stream, 0, -1);
3152}
3153
3154inline
3155bool bdljsn::operator==(const bdljsn::Json& lhs, const bdljsn::Json& rhs)
3156{
3157 return lhs.d_value == rhs.d_value;
3158}
3159
3160inline
3161bool bdljsn::operator!=(const bdljsn::Json& lhs, const bdljsn::Json& rhs)
3162{
3163 return lhs.d_value != rhs.d_value;
3164}
3165
3166template <class HASHALG>
3167inline
3168void bdljsn::hashAppend(HASHALG& hashAlg, const bdljsn::Json& object)
3169{
3170 hashAppend(hashAlg, object.d_value);
3171}
3172
3173inline
3175{
3176 bslalg::SwapUtil::swap(&a.d_value, &b.d_value);
3177}
3178
3179
3180
3181#endif // INCLUDED_BDLJSN_JSON
3182
3183// ----------------------------------------------------------------------------
3184// Copyright 2022 Bloomberg Finance L.P.
3185//
3186// Licensed under the Apache License, Version 2.0 (the "License");
3187// you may not use this file except in compliance with the License.
3188// You may obtain a copy of the License at
3189//
3190// http://www.apache.org/licenses/LICENSE-2.0
3191//
3192// Unless required by applicable law or agreed to in writing, software
3193// distributed under the License is distributed on an "AS IS" BASIS,
3194// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3195// See the License for the specific language governing permissions and
3196// limitations under the License.
3197// ----------------------------- END-OF-FILE ----------------------------------
3198
3199/** @} */
3200/** @} */
3201/** @} */
bool is() const
Definition bdlb_variant.h:7605
int typeIndex() const
Definition bdlb_variant.h:7646
TYPE & createInPlace(ARGS &&... arguments)
Definition bdlb_variant.h:7454
TYPE & the()
Definition bdlb_variant.h:7517
void swap(VariantImp &other)
Definition bdlb_variant.h:7482
Definition bdldfp_decimal.h:1834
Definition bdljsn_json.h:290
void resize(bsl::size_t count)
Definition bdljsn_json.h:1972
bsl::size_t size() const
Return the number of elements in this JsonArray.
Definition bdljsn_json.h:2053
friend bool operator==(const JsonArray &, const JsonArray &)
friend void hashAppend(HASHALG &, const JsonArray &)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Json & back()
Definition bdljsn_json.h:1861
Elements::size_type size_type
Definition bdljsn_json.h:309
BSLMF_NESTED_TRAIT_DECLARATION(JsonArray, bslma::UsesBslmaAllocator)
Json & front()
Definition bdljsn_json.h:1903
Iterator end()
Definition bdljsn_json.h:1879
Elements::const_reference const_reference
Definition bdljsn_json.h:303
Elements::iterator iterator
Definition bdljsn_json.h:305
bslma::Allocator * allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by this object to allocate memory.
Definition bdljsn_json.h:1999
BSLMF_NESTED_TRAIT_DECLARATION(JsonArray, bdlb::HasPrintMethod)
Iterator begin()
Definition bdljsn_json.h:1867
void assign(INPUT_ITERATOR first, INPUT_ITERATOR last)
Definition bdljsn_json.h:1847
void popBack()
Definition bdljsn_json.h:1954
void pushBack(const Json &json)
Definition bdljsn_json.h:1960
bool empty() const
Return true if this JsonArray has size 0, and false otherwise.
Definition bdljsn_json.h:2029
Iterator erase(bsl::size_t index)
Definition bdljsn_json.h:1885
Elements::iterator Iterator
Definition bdljsn_json.h:298
Elements::const_iterator ConstIterator
Definition bdljsn_json.h:299
void clear()
Definition bdljsn_json.h:1873
ConstIterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2023
Elements::value_type value_type
Definition bdljsn_json.h:301
BSLMF_NESTED_TRAIT_DECLARATION(JsonArray, bslmf::IsBitwiseMoveable)
friend bool operator!=(const JsonArray &, const JsonArray &)
Elements::difference_type difference_type
Definition bdljsn_json.h:308
JsonArray & operator=(const JsonArray &rhs)
Definition bdljsn_json.h:1815
friend void swap(JsonArray &, JsonArray &)
bsl::size_t maxSize() const BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2047
Json & operator[](bsl::size_t index)
Definition bdljsn_json.h:1839
JsonArray()
Definition bdljsn_json.h:1754
ConstIterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2017
Elements::const_iterator const_iterator
Definition bdljsn_json.h:306
Iterator insert(bsl::size_t index, const Json &json)
Definition bdljsn_json.h:1909
Elements::reference reference
Definition bdljsn_json.h:302
Definition bdljsn_jsonnull.h:119
Definition bdljsn_jsonnumber.h:408
int asUint64(bsls::Types::Uint64 *result) const
Definition bdljsn_jsonnumber.h:981
int asInt(int *result) const
Definition bdljsn_jsonnumber.h:963
int asDecimal64Exact(bdldfp::Decimal64 *result) const
Definition bdljsn_jsonnumber.h:1007
float asFloat() const
Definition bdljsn_jsonnumber.h:987
int asInt64(bsls::Types::Int64 *result) const
Definition bdljsn_jsonnumber.h:969
bdldfp::Decimal64 asDecimal64() const
Definition bdljsn_jsonnumber.h:999
int asUint(unsigned int *result) const
Definition bdljsn_jsonnumber.h:975
double asDouble() const
Definition bdljsn_jsonnumber.h:993
Definition bdljsn_json.h:734
Container::value_type Member
Definition bdljsn_json.h:746
bslma::Allocator * allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by this object to allocate memory.
Definition bdljsn_json.h:2317
Json & operator[](const bsl::string_view &key)
Definition bdljsn_json.h:2170
void clear() BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2199
bsl::size_t size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this JsonObject.
Definition bdljsn_json.h:2365
Iterator find(const bsl::string_view &key)
Definition bdljsn_json.h:2234
bool empty() const BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2347
Container::const_reference const_reference
Definition bdljsn_json.h:753
friend void hashAppend(HASHALG &, const JsonObject &)
friend bool operator==(const JsonObject &, const JsonObject &)
Iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2205
Container::const_iterator const_iterator
Definition bdljsn_json.h:756
friend void swap(JsonObject &, JsonObject &)
bsl::pair< Iterator, bool > IteratorAndStatus
Definition bdljsn_json.h:749
BSLMF_NESTED_TRAIT_DECLARATION(JsonObject, bslmf::IsBitwiseMoveable)
Container::size_type size_type
Definition bdljsn_json.h:759
JsonObject()
Definition bdljsn_json.h:2064
BSLMF_NESTED_TRAIT_DECLARATION(JsonObject, bdlb::HasPrintMethod)
Container::reference reference
Definition bdljsn_json.h:752
bsl::size_t erase(const bsl::string_view &key)
Definition bdljsn_json.h:2211
JsonObject & operator=(const JsonObject &rhs)
Definition bdljsn_json.h:2141
bool contains(const bsl::string_view &key) const
Definition bdljsn_json.h:2341
Container::const_iterator ConstIterator
Definition bdljsn_json.h:747
ConstIterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2329
Container::iterator iterator
Definition bdljsn_json.h:755
bsl::pair< Iterator, bool > insert(const Member &member)
Definition bdljsn_json.h:2240
BSLMF_NESTED_TRAIT_DECLARATION(JsonObject, bslma::UsesBslmaAllocator)
Container::difference_type difference_type
Definition bdljsn_json.h:758
friend bool operator!=(const JsonObject &, const JsonObject &)
Container::value_type value_type
Definition bdljsn_json.h:751
Container::iterator Iterator
Definition bdljsn_json.h:748
Iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2193
ConstIterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bdljsn_json.h:2335
Definition bdljsn_json.h:1110
bool isBoolean() const
Definition bdljsn_json.h:2797
BSLMF_NESTED_TRAIT_DECLARATION(Json, bdlb::HasPrintMethod)
int asInt(int *result) const
Definition bdljsn_json.h:2945
bool isObject() const
Definition bdljsn_json.h:2815
JsonNumber & makeNumber()
Definition bdljsn_json.h:2719
int asUint(unsigned int *result) const
Definition bdljsn_json.h:2959
BSLMF_NESTED_TRAIT_DECLARATION(Json, bslma::UsesBslmaAllocator)
bool isArray() const
Definition bdljsn_json.h:2791
int asUint64(bsls::Types::Uint64 *result) const
Definition bdljsn_json.h:2966
BSLMF_NESTED_TRAIT_DECLARATION(Json, bslmf::IsBitwiseMoveable)
JsonNull & theNull()
Definition bdljsn_json.h:2839
bdldfp::Decimal64 asDecimal64() const
Definition bdljsn_json.h:2917
void makeString(const char *string)
Definition bdljsn_json.h:2759
double asDouble() const
Definition bdljsn_json.h:2931
friend bool operator==(const Json &, const Json &)
bool isNumber() const
Definition bdljsn_json.h:2809
JsonArray & theArray()
Definition bdljsn_json.h:2827
bool isString() const
Definition bdljsn_json.h:2821
int asDecimal64Exact(bdldfp::Decimal64 *result) const
Definition bdljsn_json.h:2924
friend void swap(Json &, Json &)
JsonNumber & theNumber()
Definition bdljsn_json.h:2845
JsonObject & makeObject()
Definition bdljsn_json.h:2739
bool & makeBoolean()
Definition bdljsn_json.h:2700
Json & operator=(const Json &rhs)
Definition bdljsn_json.h:2530
friend bool operator!=(const Json &, const Json &)
bool isNull() const
Definition bdljsn_json.h:2803
friend void hashAppend(HASHALG &, const Json &)
JsonObject & theObject()
Definition bdljsn_json.h:2851
bool & theBoolean()
Definition bdljsn_json.h:2833
bsl::size_t size() const
Definition bdljsn_json.h:2903
JsonType::Enum type() const BSLS_KEYWORD_NOEXCEPT
Return the type of this Json value.
Definition bdljsn_json.h:3010
void makeNull()
Definition bdljsn_json.h:2713
JsonArray & makeArray()
Definition bdljsn_json.h:2680
float asFloat() const
Definition bdljsn_json.h:2938
const bsl::string & theString() const
Definition bdljsn_json.h:3004
Json()
Definition bdljsn_json.h:2375
int asInt64(bsls::Types::Int64 *result) const
Definition bdljsn_json.h:2952
bslma::Allocator * allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by this object to allocate memory.
Definition bdljsn_json.h:2911
Json & operator[](const bsl::string_view &key)
Definition bdljsn_json.h:2889
BloombergLP::bslma::Allocator * mechanism() const
Definition bslma_bslallocator.h:1126
Definition bslstl_stringview.h:441
BSLS_KEYWORD_CONSTEXPR const_pointer data() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_stringview.h:1760
BSLS_KEYWORD_CONSTEXPR size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the length of this view.
Definition bslstl_stringview.h:1676
Definition bslstl_string.h:1281
size_type size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6592
CHAR_TYPE * data() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6477
Definition bslstl_pair.h:1210
Definition bslstl_unorderedmap.h:1089
enable_if< BloombergLP::bslmf::IsTransparentPredicate< HASH, LOOKUP_KEY >::value &&BloombergLP::bslmf::IsTransparentPredicate< EQUAL, LOOKUP_KEY >::value, iterator >::type find(const LOOKUP_KEY &key)
Definition bslstl_unorderedmap.h:1559
const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:3350
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this unordered map.
Definition bslstl_unorderedmap.h:3544
AllocatorTraits::size_type size_type
Definition bslstl_unorderedmap.h:1152
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:2894
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:3502
pair< iterator, bool > insert(const value_type &value)
Definition bslstl_unorderedmap.h:3051
iterator erase(const_iterator position)
Definition bslstl_unorderedmap.h:2974
pair< iterator, bool > emplace(Args &&... args)
const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:3359
void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:2922
AllocatorTraits::difference_type difference_type
Definition bslstl_unorderedmap.h:1153
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:2885
BloombergLP::bslstl::HashTableIterator< const value_type, difference_type > const_iterator
Definition bslstl_unorderedmap.h:1160
bool empty() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_unorderedmap.h:3461
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this vector.
Definition bslstl_vector.h:2664
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2511
reference back()
Definition bslstl_vector.h:2577
VALUE_TYPE const * const_iterator
Definition bslstl_vector.h:854
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2519
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this vector has size 0, and false otherwise.
Definition bslstl_vector.h:2679
reference front()
Definition bslstl_vector.h:2567
Definition bslstl_vector.h:1025
Json & reference
Definition bslstl_vector.h:1049
const Json & const_reference
Definition bslstl_vector.h:1050
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:4019
Json value_type
Definition bslstl_vector.h:1047
iterator insert(const_iterator position, const VALUE_TYPE &value)
Definition bslstl_vector.h:3803
AllocatorTraits::size_type size_type
Definition bslstl_vector.h:1052
void push_back(const VALUE_TYPE &value)
Definition bslstl_vector.h:3760
Json * iterator
Definition bslstl_vector.h:1057
AllocatorTraits::difference_type difference_type
Definition bslstl_vector.h:1053
iterator erase(const_iterator position)
Definition bslstl_vector.h:3933
size_type max_size() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:4029
void swap(vector &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:1712
void resize(size_type newSize)
Definition bslstl_vector.h:3616
void pop_back()
Definition bslstl_vector.h:3792
vector &operator=(BloombergLP::bslmf::MovableRef< vector< VALUE_TYPE, ALLOCATOR > > rhs) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(AllocatorTraits void assign(INPUT_ITER first, INPUT_ITER last)
static void swap(T *a, T *b)
Definition bslalg_swaputil.h:194
Definition bslma_allocator.h:457
Definition bslmf_movableref.h:751
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLMF_MOVABLEREF_DEDUCE(...)
Definition bslmf_movableref.h:690
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2012
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:632
void swap(OptionValue &a, OptionValue &b)
Definition bdljsn_error.h:143
bool operator!=(const Error &lhs, const Error &rhs)
void swap(Error &a, Error &b)
bool operator==(const Error &lhs, const Error &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const Error &object)
void hashAppend(HASHALG &hashAlgorithm, const Error &object)
Definition bdlb_printmethods.h:283
basic_string< char > string
Definition bslstl_string.h:782
Definition balxml_encoderoptions.h:68
Definition bdlbb_blob.h:576
Definition bdlb_printmethods.h:306
Definition bdlb_transparentequalto.h:124
Definition bdlb_transparenthash.h:158
static bool isValid(const char *string)
Definition bdlde_utf8util.h:983
Enum
Definition bdljsn_jsontype.h:127
@ e_STRING
Definition bdljsn_jsontype.h:130
@ e_BOOLEAN
Definition bdljsn_jsontype.h:132
@ e_ARRAY
Definition bdljsn_jsontype.h:129
@ e_NULL
Definition bdljsn_jsontype.h:133
@ e_OBJECT
Definition bdljsn_jsontype.h:128
@ e_NUMBER
Definition bdljsn_jsontype.h:131
TYPE first
Definition bslstl_pair.h:605
Definition bslmf_enableif.h:525
Definition bslmf_isconvertible.h:867
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:343
Definition bslmf_isbitwisemoveable.h:718
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060
static t_TYPE & access(t_TYPE &ref) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1032
unsigned long long Uint64
Definition bsls_types.h:137
long long Int64
Definition bsls_types.h:132