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

#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
 
typedef Container::value_type value_type
 
typedef Container::reference reference
 
typedef Container::const_reference const_reference
 
typedef Container::iterator iterator
 
typedef Container::const_iterator const_iterator
 
typedef Container::difference_type difference_type
 
typedef Container::size_type size_type
 

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)
 
JsonObjectoperator= (const JsonObject &rhs)
 
JsonObjectoperator= (bslmf::MovableRef< JsonObject > rhs)
 
Jsonoperator[] (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< INPUT_ITERATOR, bsl::string_view >::value, void >::type insert (INPUT_ITERATOR first, INPUT_ITERATOR last)
 
template<class VALUE >
bsl::pair< Iterator, bool > insert (const bsl::string_view &key, BSLS_COMPILERFEATURES_FORWARD_REF(VALUE) value)
 
void swap (JsonObject &other)
 
const Jsonoperator[] (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
 Return the number of elements in this JsonObject.
 
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 JsonObject &, const JsonObject &)
 
bool operator!= (const JsonObject &, const JsonObject &)
 
template<class HASHALG >
void hashAppend (HASHALG &, const JsonObject &)
 
void swap (JsonObject &, JsonObject &)
 

Detailed Description

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.

See bdljsn_json

Member Typedef Documentation

◆ const_iterator

◆ const_reference

◆ ConstIterator

◆ difference_type

◆ Iterator

◆ iterator

◆ IteratorAndStatus

◆ Member

◆ reference

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ JsonObject() [1/6]

bdljsn::JsonObject::JsonObject ( )
inline

◆ JsonObject() [2/6]

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

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.

◆ JsonObject() [3/6]

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

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.

◆ JsonObject() [4/6]

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

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.

◆ JsonObject() [5/6]

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

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.

◆ JsonObject() [6/6]

template<class INPUT_ITERATOR >
bdljsn::JsonObject::JsonObject ( INPUT_ITERATOR  first,
INPUT_ITERATOR  last,
bslma::Allocator basicAllocator = 0 
)
inline

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).

Member Function Documentation

◆ allocator()

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

◆ begin() [1/2]

JsonObject::Iterator bdljsn::JsonObject::begin ( )
inline

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.

◆ begin() [2/2]

JsonObject::ConstIterator bdljsn::JsonObject::begin ( ) const
inline

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/3]

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

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/3]

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

◆ BSLMF_NESTED_TRAIT_DECLARATION() [3/3]

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

◆ cbegin()

JsonObject::ConstIterator bdljsn::JsonObject::cbegin ( ) const
inline

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.

◆ cend()

JsonObject::ConstIterator bdljsn::JsonObject::cend ( ) const
inline

Return an iterator providing non-modifiable access to the past-the-end position in the sequence of Member objects maintained by this JsonObject.

◆ clear()

void bdljsn::JsonObject::clear ( )
inline

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.

◆ contains()

bool bdljsn::JsonObject::contains ( const bsl::string_view key) const
inline

Return true if there is a Member object in this JsonObject with a key equivalent to the specified key, and return false otherwise.

◆ empty()

bool bdljsn::JsonObject::empty ( ) const
inline

Return true if this JsonObject contains no elements, and false otherwise.

◆ end() [1/2]

JsonObject::Iterator bdljsn::JsonObject::end ( )
inline

Return an iterator providing modifiable access to the past-the-end position in the sequence of Member objects maintained by this JsonObject.

◆ end() [2/2]

JsonObject::ConstIterator bdljsn::JsonObject::end ( ) const
inline

◆ erase() [1/3]

bsl::size_t bdljsn::JsonObject::erase ( const bsl::string_view key)
inline

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.

◆ erase() [2/3]

JsonObject::Iterator bdljsn::JsonObject::erase ( ConstIterator  position)
inline

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.

◆ erase() [3/3]

JsonObject::Iterator bdljsn::JsonObject::erase ( Iterator  position)
inline

◆ find() [1/2]

JsonObject::Iterator bdljsn::JsonObject::find ( const bsl::string_view key)
inline

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.

◆ find() [2/2]

JsonObject::ConstIterator bdljsn::JsonObject::find ( const bsl::string_view key) const
inline

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.

◆ insert() [1/4]

bsl::pair< JsonObject::Iterator, bool > bdljsn::JsonObject::insert ( bslmf::MovableRef< Member member)
inline

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).

◆ insert() [2/4]

template<class VALUE >
bsl::pair< JsonObject::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).

◆ insert() [3/4]

bsl::pair< JsonObject::Iterator, bool > bdljsn::JsonObject::insert ( const Member member)
inline

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 (possibly 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 false 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).

◆ insert() [4/4]

template<class INPUT_ITERATOR >
bsl::enable_if<!bsl::is_convertible< INPUT_ITERATOR, bsl::string_view >::value, void >::type bdljsn::JsonObject::insert ( INPUT_ITERATOR  first,
INPUT_ITERATOR  last 
)
inline

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).

◆ operator=() [1/2]

JsonObject & bdljsn::JsonObject::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 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.

◆ operator=() [2/2]

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

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object.

◆ operator[]() [1/2]

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

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).

◆ operator[]() [2/2]

const Json & bdljsn::JsonObject::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::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.

◆ size()

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

◆ swap()

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

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.

Friends And Related Symbol Documentation

◆ hashAppend

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

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

◆ operator!=

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.

◆ operator==

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.

◆ swap

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.


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