Quick Links: |
#include <bdljsn_json.h>
Public Types | |
typedef Container::value_type | Member |
typedef Container::const_iterator | ConstIterator |
typedef Container::iterator | Iterator |
typedef bsl::pair< Iterator, bool > | IteratorAndStatus |
Public Member Functions | |
BSLMF_NESTED_TRAIT_DECLARATION (JsonObject, bslma::UsesBslmaAllocator) | |
BSLMF_NESTED_TRAIT_DECLARATION (JsonObject, bslmf::IsBitwiseMoveable) | |
BSLMF_NESTED_TRAIT_DECLARATION (JsonObject, bdlb::HasPrintMethod) | |
JsonObject () | |
JsonObject (bslma::Allocator *basicAllocator) | |
JsonObject (const JsonObject &original, bslma::Allocator *basicAllocator=0) | |
JsonObject (bslmf::MovableRef< JsonObject > original) BSLS_KEYWORD_NOEXCEPT | |
JsonObject (bslmf::MovableRef< JsonObject > original, bslma::Allocator *basicAllocator) | |
template<class INPUT_ITERATOR > | |
JsonObject (INPUT_ITERATOR first, INPUT_ITERATOR last, bslma::Allocator *basicAllocator=0) | |
JsonObject (std::initializer_list< Member > members, bslma::Allocator *basicAllocator=0) | |
JsonObject & | operator= (const JsonObject &rhs) |
JsonObject & | operator= (bslmf::MovableRef< JsonObject > rhs) |
JsonObject & | operator= (std::initializer_list< Member > members) |
Json & | operator[] (const bsl::string_view &key) |
Iterator | begin () BSLS_KEYWORD_NOEXCEPT |
Iterator | end () BSLS_KEYWORD_NOEXCEPT |
void | clear () BSLS_KEYWORD_NOEXCEPT |
bsl::size_t | erase (const bsl::string_view &key) |
Iterator | erase (Iterator position) |
Iterator | erase (ConstIterator position) |
Iterator | find (const bsl::string_view &key) |
bsl::pair< Iterator, bool > | insert (const Member &member) |
bsl::pair< Iterator, bool > | insert (bslmf::MovableRef< Member > member) |
template<class INPUT_ITERATOR > | |
bsl::enable_if < bsl::is_convertible < typename bsl::iterator_traits < INPUT_ITERATOR > ::value_type::first_type, const bsl::string >::value &&bsl::is_convertible < typename bsl::iterator_traits < INPUT_ITERATOR > ::value_type::second_type, bdljsn::Json >::value, void > ::type | insert (INPUT_ITERATOR first, INPUT_ITERATOR last) |
void | insert (std::initializer_list< Member > members) |
template<class VALUE > | |
bsl::pair< Iterator, bool > | insert (const bsl::string_view &key, BSLS_COMPILERFEATURES_FORWARD_REF(VALUE) value) |
void | swap (JsonObject &other) |
const Json & | operator[] (const bsl::string_view &key) const |
ConstIterator | begin () const BSLS_KEYWORD_NOEXCEPT |
ConstIterator | cbegin () const BSLS_KEYWORD_NOEXCEPT |
ConstIterator | end () const BSLS_KEYWORD_NOEXCEPT |
ConstIterator | cend () const BSLS_KEYWORD_NOEXCEPT |
bool | contains (const bsl::string_view &key) const |
bool | empty () const BSLS_KEYWORD_NOEXCEPT |
ConstIterator | find (const bsl::string_view &key) const |
bsl::size_t | size () const BSLS_KEYWORD_NOEXCEPT |
bslma::Allocator * | allocator () const BSLS_KEYWORD_NOEXCEPT |
bsl::ostream & | print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const |
Friends | |
bool | operator== (const JsonObject &, const JsonObject &) |
bool | operator!= (const JsonObject &, const JsonObject &) |
template<class HASHALG > | |
void | hashAppend (HASHALG &, const JsonObject &) |
void | swap (JsonObject &, JsonObject &) |
This type is designed to replicate much of the standard associative container interface, eliding interfaces that are less relevant for a non-generic container, like hasher and comparator access, emplacement, nodes, capacity management, etc.
typedef bsl::pair<Iterator, bool> bdljsn::JsonObject::IteratorAndStatus |
bdljsn::JsonObject::JsonObject | ( | ) |
bdljsn::JsonObject::JsonObject | ( | bslma::Allocator * | basicAllocator | ) | [explicit] |
Create an empty JsonObject
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used to supply memory.
bdljsn::JsonObject::JsonObject | ( | const JsonObject & | original, | |
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create a JsonObject
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.
bdljsn::JsonObject::JsonObject | ( | bslmf::MovableRef< JsonObject > | original | ) |
Create a JsonObject
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 JsonObject
. original
is left in a valid but unspecified state.
bdljsn::JsonObject::JsonObject | ( | bslmf::MovableRef< JsonObject > | original, | |
bslma::Allocator * | basicAllocator | |||
) |
Create a JsonObject
having the same value as the specified original
. Use the specified basicAllocator
to supply memory. If basicAllocator == original.allocator()
the value of original
will be moved (in constant time) to the newly-created JsonObject
, and original
will be left in a valid but unspecified state. Otherwise, original
is copied, and basicAllocator
used to supply memory.
bdljsn::JsonObject::JsonObject | ( | INPUT_ITERATOR | first, | |
INPUT_ITERATOR | last, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create an empty JsonObject
, and then create a Json
object for each iterator in the range starting at the specified first
iterator and ending immediately before the specified last
iterator, by converting from the object referred to by each iterator. Insert into this JsonObject
each such object, ignoring those having a key that appears earlier in the sequence. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is not supplied, the currently installed default allocator is used to supply memory. The (template parameter) type INPUT_ITERATOR
shall meet the requirements of an input iterator defined in the C++11 standard [24.2.3] providing access to values of a type convertible to Member
. The behavior is undefined unless first
and last
refer to a sequence of valid values where first
is at a position at or before last
, and all keys of all Member
objects inserted are valid UTF-8 (see bdlde::Utf8Util::isValid
).
bdljsn::JsonObject::JsonObject | ( | std::initializer_list< Member > | members, | |
bslma::Allocator * | basicAllocator = 0 | |||
) |
IMPLICIT: Create an empty JsonObject
, and then create a Json
object for each in the range specified by members
argument, ignoring elements having a key that appears earlier in the sequence. 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 the keys of all Member
objects in members
are valid UTF-8 (see bdlde::Utf8Util::isValid
).
bdljsn::JsonObject::BSLMF_NESTED_TRAIT_DECLARATION | ( | JsonObject | , | |
bslma::UsesBslmaAllocator | ||||
) |
bdljsn::JsonObject::BSLMF_NESTED_TRAIT_DECLARATION | ( | JsonObject | , | |
bslmf::IsBitwiseMoveable | ||||
) |
bdljsn::JsonObject::BSLMF_NESTED_TRAIT_DECLARATION | ( | JsonObject | , | |
bdlb::HasPrintMethod | ||||
) |
JsonObject& bdljsn::JsonObject::operator= | ( | const JsonObject & | rhs | ) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object.
JsonObject& bdljsn::JsonObject::operator= | ( | bslmf::MovableRef< JsonObject > | 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 JsonObject
if allocator() == rhs.allocator()
; otherwise, all elements in this container are either destroyed or move-assigned to, and each additional element in rhs
, if any, is move-inserted into this JsonObject
. rhs
is left in a valid but unspecified state.
JsonObject& bdljsn::JsonObject::operator= | ( | std::initializer_list< Member > | members | ) |
Assign to this object the value resulting from first clearing this JsonObject
and then inserting (in order) each Member
object in the specified members
initializer list. Return a reference to `*this`. If an exception is thrown, *this
is left in a valid but unspecified state.
Json& bdljsn::JsonObject::operator[] | ( | const bsl::string_view & | key | ) |
Return a reference providing modifiable access to the Json
object associated with the specified key
in this JsonObject
; if this 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 key
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
Iterator bdljsn::JsonObject::begin | ( | ) |
Return an iterator providing modifiable access to the first Member
object in the sequence of Member
objects maintained by this JsonObject
, or the end
iterator if this JsonObject
is empty.
Iterator bdljsn::JsonObject::end | ( | ) |
Return an iterator providing modifiable access to the past-the-end position in the sequence of Member
objects maintained by this JsonObject
.
void bdljsn::JsonObject::clear | ( | ) |
Remove all entries from this JsonObject
. Note that this JsonObject
will be empty after calling this method, but allocated memory may be retained for future use.
bsl::size_t bdljsn::JsonObject::erase | ( | const bsl::string_view & | key | ) |
Remove from this JsonObject
the Member
object having the specified key
, if it exists, and return 1; otherwise (there is no object with a key equivalent to key
in this JsonObject
) return 0 with no other effect. This method invalidates only iterators and references to the removed element and previously saved values of the end()
iterator, and preserves the relative order of the elements not removed.
Iterator bdljsn::JsonObject::erase | ( | ConstIterator | position | ) |
Remove from this unordered map the value_type
object at the specified position
, and return an iterator referring to the element immediately following the removed element, or to the past-the-end position if the removed element was the last element in the sequence of elements maintained by this unordered map. This method invalidates only iterators and references to the removed element and previously saved values of the end()
iterator, and preserves the relative order of the elements not removed. The behavior is undefined unless position
refers to a value_type
object in this unordered map.
Iterator bdljsn::JsonObject::find | ( | const bsl::string_view & | key | ) |
Return an iterator providing modifiable access to the Member
object in this JsonObject
with a key equivalent to the specified key
, if such an entry exists, and the past-the-end iterator (end
) otherwise.
Insert the specified member
into this JsonObject
if the key (the first
element) of the object referred to by value
does not already exist in this JsonObject
; otherwise, this method has no effect. Return a pair
whose first
member is an iterator referring to the (possibley newly inserted) value_type
object in this JsonObject
whose key is equivalent to that of the object to be inserted, and whose second
member is true
if a new value was inserted, and flase
if a value having an equivalent key was already present. The behavior is undefined unless member.first
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
bsl::pair<Iterator, bool> bdljsn::JsonObject::insert | ( | bslmf::MovableRef< Member > | member | ) |
Insert the specified member
into this JsonObject
if the key (the first
element) of the object referred to by member
does not already exist in this JsonObject
; otherwise, this method has no effect. Return a pair
whose first
member is an iterator referring to the (possibly newly inserted) member
object in this JsonObject
whose key is the equivalent to that of the object to be inserted, and whose second
member is true
if a new value was inserted, and false
otherwise. The behavior is undefined unless member.first
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
bsl::enable_if< bsl::is_convertible<typename bsl::iterator_traits< INPUT_ITERATOR>::value_type::first_type, const bsl::string>::value && bsl::is_convertible<typename bsl::iterator_traits< INPUT_ITERATOR>::value_type::second_type, bdljsn::Json>::value, void>::type bdljsn::JsonObject::insert | ( | INPUT_ITERATOR | first, | |
INPUT_ITERATOR | last | |||
) |
Create a member
object for each iterator in the range starting at the specified first
iterator and ending immediately before the specified last
iterator, by converting from the object referred to by each iterator. Insert into this JsonObject
each such object whose key is not already contained. The (template parameter) type INPUT_ITERATOR
shall meet the requirements of an input iterator defined in the C++11 standard [24.2.3] providing access to values of a type convertible to Member
. The behavior is undefined unless first
and last
refer to a sequence of value values where first
is at a position at or before last
. The behavior is undefined unless the keys of all Member
objects inserted are valid UTF-8 (see bdlde::Utf8Util::isValid
).
void bdljsn::JsonObject::insert | ( | std::initializer_list< Member > | members | ) |
Create a Member
object for each element in the specified members
. Insert into this JsonObject
each such object whose key is not already contained. The behavior is undefined unless the keys of all Member
objects inserted are valid UTF-8 (see bdlde::Utf8Util::isValid
).
bsl::pair<Iterator, bool> bdljsn::JsonObject::insert | ( | const bsl::string_view & | key, | |
BSLS_COMPILERFEATURES_FORWARD_REF(VALUE) | value | |||
) |
Insert into this JsonObject
a Member
constructed from the specified key
and the specified value
, respectively, if key
does not already exist in this JsonObject
; otherwise, this method has no effect. Return a pair
whose first
member is an iterator referring to the (possibly newly inserted) Member
object in this JsonObject
whose key is the equivalent to that of the object to be inserted, and whose second
member is true
if a new value was inserted, and false
otherwise. The behavior is undefined unless key
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
void bdljsn::JsonObject::swap | ( | JsonObject & | other | ) |
Exchange the value of this object with that of the specified other
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 this object was created with the same allocator as other
.
const Json& bdljsn::JsonObject::operator[] | ( | const bsl::string_view & | key | ) | const |
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 assicated with key
.
ConstIterator bdljsn::JsonObject::begin | ( | ) | const |
ConstIterator bdljsn::JsonObject::cbegin | ( | ) | const |
Return an iterator providing non-modifiable access to the first Member
object in the sequence of Member
objects maintained by this JsonObject
, or the end
iterator if this JsonObject
is empty.
ConstIterator bdljsn::JsonObject::end | ( | ) | const |
ConstIterator bdljsn::JsonObject::cend | ( | ) | const |
Return an iterator providing non-modifiable access to the past-the-end position in the sequence of Member
objects maintained by this JsonObject
.
bool bdljsn::JsonObject::contains | ( | const bsl::string_view & | key | ) | const |
Return true
if there is a Member
object in this JsonObject
with a key equivalent to the specified key
, and return false
otherwise.
bool bdljsn::JsonObject::empty | ( | ) | const |
Return true
if this JsonObject
contains no elements, and false
otherwise.
ConstIterator bdljsn::JsonObject::find | ( | const bsl::string_view & | key | ) | const |
Return an iterator providing non-modifiable access to the Member
object in this JsonObject
with a key equivalent to the specified key
, if such an entry exists, and the past-the-end iterator (end
) otherwise.
bsl::size_t bdljsn::JsonObject::size | ( | ) | const |
Return the number of elements in this JsonObject
.
bslma::Allocator* bdljsn::JsonObject::allocator | ( | ) | const |
Return the allocator used by this object to allocate memory.
bsl::ostream& bdljsn::JsonObject::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.
bool operator== | ( | const JsonObject & | , | |
const JsonObject & | ||||
) | [friend] |
Return true
if the specified lhs
and rhs
objects have the same value, and false
otherwise. Two JsonObject
objects have the same value if they have the same number of Member
objects, and for each Member
object that is contained in lhs
there is a key-value pair contained in rhs
having the same value, and vice versa.
bool operator!= | ( | const JsonObject & | , | |
const JsonObject & | ||||
) | [friend] |
Return false
if the specified lhs
and rhs
objects have the same value, and true
otherwise. Two JsonObject
objects have the same value if they have the same number of Member
objects, and for each Member
object that is contained in lhs
there is a key-value pair contained in rhs
having the same value, and vice versa.
void hashAppend | ( | HASHALG & | , | |
const JsonObject & | ||||
) | [friend] |
Invoke the specified hashAlg
on the attributes of the specified object
.
void swap | ( | JsonObject & | , | |
JsonObject & | ||||
) | [friend] |
Exchange the value of the specified a
JsonObject
with that of the specified b
JsonObject
. This function provides the no-throw exception-safety guarantee. This operation has O[1] complexity if a
was created with the same allocator as b
; otherwise, it has O[n+m] complexity, where n and m are the number of elements in a
and b
, respectively.