BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn::Json Class Reference

#include <bdljsn_json.h>

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (Json, bslma::UsesBslmaAllocator)
 
 BSLMF_NESTED_TRAIT_DECLARATION (Json, bslmf::IsBitwiseMoveable)
 
 BSLMF_NESTED_TRAIT_DECLARATION (Json, bdlb::HasPrintMethod)
 
 Json ()
 
 Json (bslma::Allocator *basicAllocator)
 
 Json (const Json &original, bslma::Allocator *basicAllocator=0)
 
 Json (bslmf::MovableRef< Json > original)
 
 Json (bslmf::MovableRef< Json > original, bslma::Allocator *basicAllocator)
 
 Json (const JsonArray &array, bslma::Allocator *basicAllocator=0)
 
 Json (bslmf::MovableRef< JsonArray > array, bslma::Allocator *basicAllocator=0)
 
 Json (bool boolean, bslma::Allocator *basicAllocator=0)
 
 Json (const JsonNull &null, bslma::Allocator *basicAllocator=0)
 
 Json (float number, bslma::Allocator *basicAllocator=0)
 
 Json (double number, bslma::Allocator *basicAllocator=0)
 
 Json (bdldfp::Decimal64 number, bslma::Allocator *basicAllocator=0)
 
 Json (int number, bslma::Allocator *basicAllocator=0)
 
 Json (unsigned int number, bslma::Allocator *basicAllocator=0)
 
 Json (bsls::Types::Int64 number, bslma::Allocator *basicAllocator=0)
 
 Json (bsls::Types::Uint64 number, bslma::Allocator *basicAllocator=0)
 
 Json (const JsonNumber &number, bslma::Allocator *basicAllocator=0)
 
 Json (bslmf::MovableRef< JsonNumber > number, bslma::Allocator *basicAllocator=0)
 
 Json (const JsonObject &object, bslma::Allocator *basicAllocator=0)
 
 Json (bslmf::MovableRef< JsonObject > object, bslma::Allocator *basicAllocator=0)
 
 Json (const char *string, bslma::Allocator *basicAllocator=0)
 
 Json (const bsl::string_view &string, bslma::Allocator *basicAllocator=0)
 
template<class STRING_TYPE >
 Json (BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) string, bslma::Allocator *basicAllocator=0, typename bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value >::type *=0)
 
Jsonoperator= (const Json &rhs)
 
Jsonoperator= (bslmf::MovableRef< Json > rhs)
 
Jsonoperator= (float rhs)
 
Jsonoperator= (double rhs)
 
Jsonoperator= (bdldfp::Decimal64 rhs)
 
Jsonoperator= (int rhs)
 
Jsonoperator= (unsigned int rhs)
 
Jsonoperator= (bsls::Types::Int64 rhs)
 
Jsonoperator= (bsls::Types::Uint64 rhs)
 
Jsonoperator= (const JsonNumber &rhs)
 
Jsonoperator= (bslmf::MovableRef< JsonNumber > rhs)
 
Jsonoperator= (const char *rhs)
 
Jsonoperator= (const bsl::string_view &rhs)
 
template<class STRING_TYPE >
bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value, Json >::typeoperator= (BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) rhs)
 
Jsonoperator= (bool rhs)
 
Jsonoperator= (const JsonObject &rhs)
 
Jsonoperator= (bslmf::MovableRef< JsonObject > rhs)
 
Jsonoperator= (const JsonArray &rhs)
 
Jsonoperator= (bslmf::MovableRef< JsonArray > rhs)
 
Jsonoperator= (const JsonNull &)
 
Jsonoperator= (bslmf::MovableRef< JsonNull >)
 
JsonArraymakeArray ()
 
JsonArraymakeArray (const JsonArray &array)
 
JsonArraymakeArray (bslmf::MovableRef< JsonArray > array)
 
bool & makeBoolean ()
 
bool & makeBoolean (bool boolean)
 
void makeNull ()
 
JsonNumbermakeNumber ()
 
JsonNumbermakeNumber (const JsonNumber &number)
 
JsonNumbermakeNumber (bslmf::MovableRef< JsonNumber > number)
 
JsonObjectmakeObject ()
 
JsonObjectmakeObject (const JsonObject &object)
 
JsonObjectmakeObject (bslmf::MovableRef< JsonObject > object)
 
void makeString (const char *string)
 
void makeString (const bsl::string_view &string)
 
template<class STRING_TYPE >
bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value >::type makeString (BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) string)
 
void swap (Json &other)
 
JsonArraytheArray ()
 
bool & theBoolean ()
 
JsonNulltheNull ()
 
JsonNumbertheNumber ()
 
JsonObjecttheObject ()
 
Jsonoperator[] (const bsl::string_view &key)
 
Jsonoperator[] (bsl::size_t index)
 
int asInt (int *result) const
 
int asInt64 (bsls::Types::Int64 *result) const
 
int asUint (unsigned int *result) const
 
int asUint64 (bsls::Types::Uint64 *result) const
 
float asFloat () const
 
double asDouble () const
 
bdldfp::Decimal64 asDecimal64 () const
 
int asDecimal64Exact (bdldfp::Decimal64 *result) const
 
bool isArray () const
 
bool isBoolean () const
 
bool isNull () const
 
bool isNumber () const
 
bool isObject () const
 
bool isString () const
 
const JsonArraytheArray () const
 
const bool & theBoolean () const
 
const JsonNulltheNull () const
 
const JsonNumbertheNumber () const
 
const JsonObjecttheObject () const
 
const bsl::stringtheString () const
 
JsonType::Enum type () const BSLS_KEYWORD_NOEXCEPT
 Return the type of this Json value.
 
const Jsonoperator[] (const bsl::string_view &key) const
 
const Jsonoperator[] (bsl::size_t index) const
 
bsl::size_t size () const
 
bslma::Allocatorallocator () const BSLS_KEYWORD_NOEXCEPT
 Return the allocator used by this object to allocate memory.
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 

Friends

bool operator== (const Json &, const Json &)
 
bool operator!= (const Json &, const Json &)
 
template<class HASHALG >
void hashAppend (HASHALG &, const Json &)
 
void swap (Json &, Json &)
 

Detailed Description

This type is designed to be a thin wrapper around a variant of the possible JSON types, using a BDE-style variant interface.

See bdljsn_json

Constructor & Destructor Documentation

◆ Json() [1/23]

bdljsn::Json::Json ( )
inline

◆ Json() [2/23]

bdljsn::Json::Json ( bslma::Allocator basicAllocator)
inlineexplicit

Create a Json object having the type (and the singleton value) of JsonNull. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [3/23]

bdljsn::Json::Json ( const Json original,
bslma::Allocator basicAllocator = 0 
)
inline

Create a Json object having the same value as the specified original. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [4/23]

bdljsn::Json::Json ( bslmf::MovableRef< Json original)
inline

Create a Json object having the same value as the specified original object by moving (in constant time) the contents of original to the new JsonObject. The allocator associated with original is propagated for use in the newly-created Json object. original is left in a valid but unspecified state.

◆ Json() [5/23]

bdljsn::Json::Json ( bslmf::MovableRef< Json original,
bslma::Allocator basicAllocator 
)
inline

Create a Json object having the same value as the specified original. Use the specified basicAllocator to supply memory.

◆ Json() [6/23]

bdljsn::Json::Json ( const JsonArray array,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonArray and the same value as the specified array. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [7/23]

bdljsn::Json::Json ( bslmf::MovableRef< JsonArray array,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonArray and the same value as the specified array object by moving (in constant time) the contents of array to the new Json object. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the allocator associated with array is propagated for use in the newly-created Json object. array is left in a valid but unspecified state.

◆ Json() [8/23]

bdljsn::Json::Json ( bool  boolean,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type bool and the same value as the specified boolean. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [9/23]

bdljsn::Json::Json ( const JsonNull null,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonNull and the same value as the specified null. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [10/23]

bdljsn::Json::Json ( float  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [11/23]

bdljsn::Json::Json ( double  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [12/23]

bdljsn::Json::Json ( bdldfp::Decimal64  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [13/23]

bdljsn::Json::Json ( int  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [14/23]

bdljsn::Json::Json ( unsigned int  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [15/23]

bdljsn::Json::Json ( bsls::Types::Int64  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [16/23]

bdljsn::Json::Json ( bsls::Types::Uint64  number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [17/23]

bdljsn::Json::Json ( const JsonNumber number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonNumber and the same value as the specified number. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [18/23]

bdljsn::Json::Json ( bslmf::MovableRef< JsonNumber number,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonNumber and the same value as the specified number object by moving (in constant time) the contents of number to the new Json object. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the allocator associated with number is propagated for use in the newly-created Json object. number is left in a valid but unspecified state.

◆ Json() [19/23]

bdljsn::Json::Json ( const JsonObject object,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonObject and the same value as the specified object. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory.

◆ Json() [20/23]

bdljsn::Json::Json ( bslmf::MovableRef< JsonObject object,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type JsonObject and the same value as the specified object by moving (in constant time) the contents of object to the new Json object. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the allocator associated with object is propagated for use in the newly-created Json object. object is left in a valid but unspecified state.

◆ Json() [21/23]

bdljsn::Json::Json ( const char *  string,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

◆ Json() [22/23]

bdljsn::Json::Json ( const bsl::string_view string,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a Json object having the type bsl::string and the same value as the specified string. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used to supply memory. The behavior is undefined unless string is valid UTF-8 (see bdlde::Utf8Util::isValid).

◆ Json() [23/23]

template<class STRING_TYPE >
bdljsn::Json::Json ( BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE)  string,
bslma::Allocator basicAllocator = 0,
typename bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value >::type = 0 
)
inlineexplicit

Create a Json object having the type bsl::string and the same value as the specified string by moving (in constant time) the contents of string to the new Json object. Optionally specify the basicAllocator used to supply memory. If basicAllocator is not specified, the allocator associated with string is propagated for use in the newly-created Json object. string is left in a valid but unspecified state. This function does not participate in overload resolution unless the specified STRING_TYPE is bsl::string. The behavior is undefined unless string is valid UTF-8 (see bdlde::Utf8Util::isValid).

Member Function Documentation

◆ allocator()

bslma::Allocator * bdljsn::Json::allocator ( ) const
inline

◆ asDecimal64()

bdldfp::Decimal64 bdljsn::Json::asDecimal64 ( ) const
inline

◆ asDecimal64Exact()

int bdljsn::Json::asDecimal64Exact ( bdldfp::Decimal64 result) const
inline

Load the specified result with the closest floating point representation to the value of type JsonNumber held by this object, even if a non-zero status is returned. Return 0 if this number can be represented exactly, and return JsonNumber::k_INEXACT if value cannot be represented exactly. If this number is outside the representable range, load result with +INF or -INF (as appropriate). A number can be represented exactly as a Decimal64 if, for the significand and exponent, abs(significand) <= 9,999,999,999,999,999 and '-398 <= exponent <= 369'. The behavior is undefined unless isNumber() returns true;

◆ asDouble()

double bdljsn::Json::asDouble ( ) const
inline

◆ asFloat()

float bdljsn::Json::asFloat ( ) const
inline

Return the closest floating point representation to the value of the type JsonNumber held by this object. If this number is outside the representable range, return +INF or -INF (as appropriate). The behavior is undefined unless isNumber() returns true.

◆ asInt()

int bdljsn::Json::asInt ( int *  result) const
inline

Load into the specified result the integer value of the value of type JsonNumber held by this object. Return 0 on success, JsonNumber::k_OVERFLOW if value is larger than can be represented by result, JsonNumber::k_UNDERFLOW if value is smaller than can be represented by result, and JsonNumber::k_NOT_INTEGRAL if value is not an integral number (i.e., there is a fractional part). For underflow, result will be loaded with the minimum representable value, for overflow, result will be loaded with the maximum representable value, for non-integral values result will be loaded with the integer part of value (truncating the value to the nearest integer). If the result is not an integer and also either overflows or underflows, it is treated as an overflow or underflow (respectively). Note that this operation returns a status value (unlike similar floating point conversions) because typically it is an error if a conversion to an integer results in an inexact value. The behavior is undefined unless isNumber() returns true.

◆ asInt64()

int bdljsn::Json::asInt64 ( bsls::Types::Int64 result) const
inline

◆ asUint()

int bdljsn::Json::asUint ( unsigned int *  result) const
inline

◆ asUint64()

int bdljsn::Json::asUint64 ( bsls::Types::Uint64 result) const
inline

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/3]

bdljsn::Json::BSLMF_NESTED_TRAIT_DECLARATION ( Json  ,
bdlb::HasPrintMethod   
)

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/3]

bdljsn::Json::BSLMF_NESTED_TRAIT_DECLARATION ( Json  ,
bslma::UsesBslmaAllocator   
)

◆ BSLMF_NESTED_TRAIT_DECLARATION() [3/3]

bdljsn::Json::BSLMF_NESTED_TRAIT_DECLARATION ( Json  ,
bslmf::IsBitwiseMoveable   
)

◆ isArray()

bool bdljsn::Json::isArray ( ) const
inline

Return true if the value held by this object is of type JsonArray, and false otherwise.

◆ isBoolean()

bool bdljsn::Json::isBoolean ( ) const
inline

Return true if the value held by this object is of type bool, and false otherwise.

◆ isNull()

bool bdljsn::Json::isNull ( ) const
inline

Return true if the value held by this object is of type JsonNull, and false otherwise.

◆ isNumber()

bool bdljsn::Json::isNumber ( ) const
inline

Return true if the value held by this object is of type JsonNumber, and false otherwise.

◆ isObject()

bool bdljsn::Json::isObject ( ) const
inline

Return true if the value held by this object is of type JsonObject, and false otherwise.

◆ isString()

bool bdljsn::Json::isString ( ) const
inline

Return true if the value held by this object is of type bsl::string, and false otherwise.

◆ makeArray() [1/3]

JsonArray & bdljsn::Json::makeArray ( )
inline

Create an instance of type JsonArray in this object, using the allocator currently held by this object to supply memory, and return a reference providing modifiable access to the created instance. Optionally specify array to initialize the JsonArray created. This method first destroys the current value held by this object (even if the type currently held is JsonArray).

◆ makeArray() [2/3]

JsonArray & bdljsn::Json::makeArray ( bslmf::MovableRef< JsonArray array)
inline

◆ makeArray() [3/3]

JsonArray & bdljsn::Json::makeArray ( const JsonArray array)
inline

◆ makeBoolean() [1/2]

bool & bdljsn::Json::makeBoolean ( )
inline

Create an instance of type bool in this object and return a reference providing modifiable access to the created instance. Optionally specify boolean to initialize the bool created. This method first destroys the current value held by this object.

◆ makeBoolean() [2/2]

bool & bdljsn::Json::makeBoolean ( bool  boolean)
inline

◆ makeNull()

void bdljsn::Json::makeNull ( )
inline

Create an instance of type JsonNull in this object. This method first destroys the current value held by this object.

◆ makeNumber() [1/3]

JsonNumber & bdljsn::Json::makeNumber ( )
inline

Create an instance of type JsonNumber in this object, using the allocator currently held by this object to supply memory, and return a reference providing modifiable access to the created instance. Optionally specify number to initialize the JsonNumber created. This method first destroys the current value held by this object (even if the type currently held is JsonNumber).

◆ makeNumber() [2/3]

JsonNumber & bdljsn::Json::makeNumber ( bslmf::MovableRef< JsonNumber number)
inline

◆ makeNumber() [3/3]

JsonNumber & bdljsn::Json::makeNumber ( const JsonNumber number)
inline

◆ makeObject() [1/3]

JsonObject & bdljsn::Json::makeObject ( )
inline

Create an instance of type JsonObject in this object, using the allocator currently held by this object to supply memory, and return a reference providing modifiable access to the created instance. Optionally specify object to initialize the JsonObject created. This method first destroys the current value held by this object (even if the type currently held is JsonObject).

◆ makeObject() [2/3]

JsonObject & bdljsn::Json::makeObject ( bslmf::MovableRef< JsonObject object)
inline

◆ makeObject() [3/3]

JsonObject & bdljsn::Json::makeObject ( const JsonObject object)
inline

◆ makeString() [1/3]

template<class STRING_TYPE >
bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value >::type bdljsn::Json::makeString ( BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE)  string)
inline

Create an instance of type bsl::string in this object, using the allocator currently held by this object to supply memory. Optionally specify string to initialize the bsl::string created. This method first destroys the current value held by this object (even if the type currently held is bsl::string). This function does not participate in overload resolution unless the specified STRING_TYPE is bsl::string. The behavior is undefined unless string is valid UTF-8 (see bdlde::Utf8Util::isValid).

◆ makeString() [2/3]

void bdljsn::Json::makeString ( const bsl::string_view string)
inline

Create an instance of type bsl::string in this object, using the allocator currently held by this object to supply memory. Optionally specify string to initialize the bsl::string created. This method first destroys the current value held by this object (even if the type currently held is bsl::string). The behavior is undefined unless string is valid UTF-8 (see bdlde::Utf8Util::isValid).

◆ makeString() [3/3]

void bdljsn::Json::makeString ( const char *  string)
inline

◆ operator=() [1/21]

Json & bdljsn::Json::operator= ( bdldfp::Decimal64  rhs)
inline

◆ operator=() [2/21]

Json & bdljsn::Json::operator= ( bool  rhs)
inline

Assign to this object a value of type bool initialized from the specified rhs, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not bsl::string.

◆ operator=() [3/21]

Json & bdljsn::Json::operator= ( bslmf::MovableRef< Json rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The contents of rhs are moved (in constant time) to this Json object if allocator() == rhs.allocator(); otherwise they are copied. rhs is left in a valid but unspecified state.

◆ operator=() [4/21]

Json & bdljsn::Json::operator= ( bslmf::MovableRef< JsonArray rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The contents of rhs are moved (in constant time) to this Json object if allocator() == rhs.allocator(); otherwise, they are copied. rhs is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonArray.

◆ operator=() [5/21]

Json & bdljsn::Json::operator= ( bslmf::MovableRef< JsonNull )
inline

Assign to this object the singleton value of type JsonNull, and return a reference providing modifiable access to this object. rhs is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonNull.

◆ operator=() [6/21]

Json & bdljsn::Json::operator= ( bslmf::MovableRef< JsonNumber rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The contents of rhs are moved (in constant time) to this Json object if allocator() == rhs.allocator(); otherwise, they are copied. rhs is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonNumber.

◆ operator=() [7/21]

Json & bdljsn::Json::operator= ( bslmf::MovableRef< JsonObject rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The contents of rhs are moved (in constant time) to this Json object if allocator() == rhs.allocator(); otherwise, they are copied. rhs is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonObject.

◆ operator=() [8/21]

template<class STRING_TYPE >
bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value, Json >::type & bdljsn::Json::operator= ( BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE)  rhs)

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The contents of rhs are moved (in constant time) to this Json object if allocator() == rhs.allocator(); otherwise, they are copied. rhs is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not bsl::string. This function does not participate in overload resolution unless the specified STRING_TYPE is bsl::string. The behavior is undefined unless rhs is valid UTF-8 (see bdlde::Utf8Util::isValid).

◆ operator=() [9/21]

Json & bdljsn::Json::operator= ( bsls::Types::Int64  rhs)
inline

◆ operator=() [10/21]

Json & bdljsn::Json::operator= ( bsls::Types::Uint64  rhs)
inline

◆ operator=() [11/21]

Json & bdljsn::Json::operator= ( const bsl::string_view rhs)
inline

◆ operator=() [12/21]

Json & bdljsn::Json::operator= ( const char *  rhs)
inline

Assign to this object a value of type bsl::string initialized from the specified rhs, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not bsl::string. The behavior is undefined unless rhs is valid UTF-8 (see bdlde::Utf8Util::isValid).

◆ operator=() [13/21]

Json & bdljsn::Json::operator= ( const Json rhs)
inline

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. The value currently held by this variant is destroyed if that value's type is not the same as the type held by the rhs object.

◆ operator=() [14/21]

Json & bdljsn::Json::operator= ( const JsonArray rhs)
inline

Assign to this object a value of type JsonArray initialized from the specified rhs, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not JsonArray.

◆ operator=() [15/21]

Json & bdljsn::Json::operator= ( const JsonNull )
inline

Assign to this object the singleton value of type JsonNull, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not JsonNull.

◆ operator=() [16/21]

Json & bdljsn::Json::operator= ( const JsonNumber rhs)
inline

◆ operator=() [17/21]

Json & bdljsn::Json::operator= ( const JsonObject rhs)
inline

Assign to this object a value of type JsonObject initialized from the specified rhs, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not JsonObject.

◆ operator=() [18/21]

Json & bdljsn::Json::operator= ( double  rhs)
inline

◆ operator=() [19/21]

Json & bdljsn::Json::operator= ( float  rhs)
inline

Assign to this object a value of type JsonNumber initialized from the specified rhs, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not JsonNumber.

◆ operator=() [20/21]

Json & bdljsn::Json::operator= ( int  rhs)
inline

◆ operator=() [21/21]

Json & bdljsn::Json::operator= ( unsigned int  rhs)
inline

◆ operator[]() [1/4]

Json & bdljsn::Json::operator[] ( bsl::size_t  index)
inline

Return a reference providing modifiable access to the element at the specified index in the JsonArray held by this object. The behavior is undefined unless isArray() returns true and index < theArray().size().

◆ operator[]() [2/4]

const Json & bdljsn::Json::operator[] ( bsl::size_t  index) const
inline

Return a reference providing non-modifiable access to the element at the specified index in the JsonArray held by this object. The behavior is undefined unless isArray() returns true and index < theArray().size().

◆ operator[]() [3/4]

Json & bdljsn::Json::operator[] ( const bsl::string_view key)
inline

Return a reference providing modifiable access to the Json object associated with the specified key in the JsonObject held by this object; if the JsonObject does not already contain a Json object associated with key, first insert a new default-constructed Json object associated with key. The behavior is undefined unless isObject() returns true.

◆ operator[]() [4/4]

const Json & bdljsn::Json::operator[] ( const bsl::string_view key) const
inline

Return a reference providing non-modifiable access to the Json object associated with the specified key in this JsonObject. The behavior is undefined unless key is valid UTF-8 (see bdlde::Utf8Util::isValid) and this JsonObject already contains a Json object associated with key.

◆ print()

bsl::ostream & bdljsn::Json::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const

Write the value of this object to the specified output stream in a human-readable format, and return a reference to stream. Optionally specify an initial indentation level, whose absolute value is incremented recursively for nested objects. If level is specified, optionally specify spacesPerLevel, whose absolute value indicates the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect. Note that this human-readable format is not fully specified, and can change without notice.

◆ size()

bsl::size_t bdljsn::Json::size ( ) const
inline

Return the number of elements in the JsonObject or JsonArray held by this object. The behavior is undefined unless isArray() || isObject() evaluates to true.

◆ swap()

void bdljsn::Json::swap ( Json other)
inline

Exchange the value of this with that of the specified other. If an exception is thrown, both objects are left in valid but unspecified states. This operation guarantees O[1] complexity. The behavior is undefined unless this object was created with the same allocator as other.

◆ theArray() [1/2]

JsonArray & bdljsn::Json::theArray ( )
inline

Return a reference providing modifiable access to the value of type JsonArray held by this object. The behavior is undefined unless isArray() returns true.

◆ theArray() [2/2]

const JsonArray & bdljsn::Json::theArray ( ) const
inline

Return a reference providing non-modifiable access to the value of type JsonArray held by this object. The behavior is undefined unless isArray() returns true.

◆ theBoolean() [1/2]

bool & bdljsn::Json::theBoolean ( )
inline

Return a reference providing modifiable access to the value of type boolean held by this object. The behavior is undefined unless isBoolean() returns true.

◆ theBoolean() [2/2]

const bool & bdljsn::Json::theBoolean ( ) const
inline

Return a reference providing non-modifiable access to the value of type boolean held by this object. The behavior is undefined unless isBoolean() returns true.

◆ theNull() [1/2]

JsonNull & bdljsn::Json::theNull ( )
inline

Return a reference providing modifiable access to the value of type JsonNull held by this object. The behavior is undefined unless isNull() returns true.

◆ theNull() [2/2]

const JsonNull & bdljsn::Json::theNull ( ) const
inline

Return a reference providing non-modifiable access to the value of type JsonNull held by this object. The behavior is undefined unless isNull() returns true.

◆ theNumber() [1/2]

JsonNumber & bdljsn::Json::theNumber ( )
inline

Return a reference providing modifiable access to the value of type JsonNumber held by this object. The behavior is undefined unless isNumber() returns true.

◆ theNumber() [2/2]

const JsonNumber & bdljsn::Json::theNumber ( ) const
inline

Return a reference providing non-modifiable access to the value of type JsonNumber held by this object. The behavior is undefined unless isNumber() returns true.

◆ theObject() [1/2]

JsonObject & bdljsn::Json::theObject ( )
inline

Return a reference providing modifiable access to the value of type JsonObject held by this object. The behavior is undefined unless isObject() returns true.

◆ theObject() [2/2]

const JsonObject & bdljsn::Json::theObject ( ) const
inline

Return a reference providing non-modifiable access to the value of type JsonObject held by this object. The behavior is undefined unless isObject() returns true.

◆ theString()

const bsl::string & bdljsn::Json::theString ( ) const
inline

Return a reference providing non-modifiable access to the value of type JsonString held by this object. The behavior is undefined unless isString() returns true.

◆ type()

JsonType::Enum bdljsn::Json::type ( ) const
inline

Friends And Related Symbol Documentation

◆ hashAppend

template<class HASHALG >
void hashAppend ( HASHALG &  ,
const Json  
)
friend

Invoke the specified hashAlg on the attributes of the specified object.

◆ operator!=

bool operator!= ( const Json ,
const Json  
)
friend

Return false if the specified lhs and rhs objects have the same value, and true otherwise. Two Json objects lhs and rhs have the same value if they hold objects of the same type, and those objects have the same value.

◆ operator==

bool operator== ( const Json ,
const Json  
)
friend

Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two Json objects lhs and rhs have the same value if they hold objects of the same type, and those objects have the same value.

◆ swap

void swap ( Json ,
Json  
)
friend

Exchange the value of the specified a Json object with that of the specified b Json object. If an exception is thrown, both objects are left in valid but unspecified states. This operation guarantees O[1] complexity. The behavior is undefined unless a was created with the same allocator as b.


The documentation for this class was generated from the following file: