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

#include <bdljsn_json.h>

Public Types

typedef Elements::iterator Iterator
 
typedef Elements::const_iterator ConstIterator
 
typedef Elements::value_type value_type
 
typedef Elements::reference reference
 
typedef Elements::const_reference const_reference
 
typedef Elements::iterator iterator
 
typedef Elements::const_iterator const_iterator
 
typedef Elements::difference_type difference_type
 
typedef Elements::size_type size_type
 

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (JsonArray, bslma::UsesBslmaAllocator)
 
 BSLMF_NESTED_TRAIT_DECLARATION (JsonArray, bslmf::IsBitwiseMoveable)
 
 BSLMF_NESTED_TRAIT_DECLARATION (JsonArray, bdlb::HasPrintMethod)
 
 JsonArray ()
 
 JsonArray (bslma::Allocator *basicAllocator)
 
 JsonArray (const JsonArray &original, bslma::Allocator *basicAllocator=0)
 
 JsonArray (bslmf::MovableRef< JsonArray > original) BSLS_KEYWORD_NOEXCEPT
 
 JsonArray (bslmf::MovableRef< JsonArray > original, bslma::Allocator *basicAllocator)
 
template<class INPUT_ITERATOR >
 JsonArray (INPUT_ITERATOR first, INPUT_ITERATOR last, bslma::Allocator *basicAllocator=0)
 
JsonArrayoperator= (const JsonArray &rhs)
 
JsonArrayoperator= (bslmf::MovableRef< JsonArray > rhs)
 
Jsonoperator[] (bsl::size_t index)
 
template<class INPUT_ITERATOR >
void assign (INPUT_ITERATOR first, INPUT_ITERATOR last)
 
Iterator begin ()
 
Iterator end ()
 
Jsonfront ()
 
Jsonback ()
 
void clear ()
 
Iterator erase (bsl::size_t index)
 
Iterator erase (ConstIterator position)
 
Iterator erase (ConstIterator first, ConstIterator last)
 
Iterator insert (bsl::size_t index, const Json &json)
 
Iterator insert (bsl::size_t index, bslmf::MovableRef< Json > json)
 
template<class INPUT_ITERATOR >
Iterator insert (bsl::size_t index, INPUT_ITERATOR first, INPUT_ITERATOR last)
 
Iterator insert (ConstIterator position, const Json &json)
 
Iterator insert (ConstIterator position, bslmf::MovableRef< Json > json)
 
template<class INPUT_ITERATOR >
Iterator insert (ConstIterator position, INPUT_ITERATOR first, INPUT_ITERATOR last)
 
void popBack ()
 
void pushBack (const Json &json)
 
void pushBack (bslmf::MovableRef< Json > json)
 
void resize (bsl::size_t count)
 
void resize (bsl::size_t count, const Json &json)
 
void swap (JsonArray &other)
 
const Jsonoperator[] (bsl::size_t index) 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
 
const Jsonfront () const
 
const Jsonback () const
 
bool empty () const
 Return true if this JsonArray has size 0, and false otherwise.
 
bsl::size_t size () const
 Return the number of elements in this JsonArray.
 
bslma::Allocatorallocator () const BSLS_KEYWORD_NOEXCEPT
 Return the allocator used by this object to allocate memory.
 
bsl::size_t maxSize () const BSLS_KEYWORD_NOEXCEPT
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 

Friends

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

Detailed Description

This type is designed to replicate much of the standard sequence container interface, eliding interfaces that are less relevant for a non-generic container. Note that a bsl::vector is chosen for the implementation because our implementation permits the element type to be incomplete (when just spelling the type name).

See bdljsn_json

Member Typedef Documentation

◆ const_iterator

◆ const_reference

◆ ConstIterator

◆ difference_type

◆ Iterator

◆ iterator

◆ reference

◆ size_type

◆ value_type

Constructor & Destructor Documentation

◆ JsonArray() [1/6]

bdljsn::JsonArray::JsonArray ( )
inline

◆ JsonArray() [2/6]

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

Create an empty JsonArray. Optionally specify a basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used.

◆ JsonArray() [3/6]

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

Create a JsonArray having the same value as the specified original object. Optionally specify basicAllocator to supply memory. If basicAllocator is not specified, the allocator associated with original is propagated for use in the newly-created JsonArray.

◆ JsonArray() [4/6]

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

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

◆ JsonArray() [5/6]

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

Create a JsonArray having the same value as the specified original object that uses the specified basicAllocator to supply memory. The contents of original are moved (in constant time) to the new JsonArray object if basicAllocator == original.allocator(), and are move-inserted (in linear time) using basicAllocator otherwise. original is left in a valid but unspecified state.

◆ JsonArray() [6/6]

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

Create a JsonArray and insert (in order) each Json object in the range starting at the specified first element, and ending immediately before the specified last element. Optionally specify basicAllocator used to supply memory. If basicAllocator is not specified, the currently installed default allocator is used. Throw bsl::length_error if the number of elements in [first .. last) exceeds the value returned by the method maxSize. 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 Json, and Json must be emplace-constructible form *i, where i is a dereferenceable iterator in the range [first .. last). The behavior is undefined unless first and last refer to a range of valid values where first is at a position at or before last.

Member Function Documentation

◆ allocator()

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

◆ assign()

template<class INPUT_ITERATOR >
void bdljsn::JsonArray::assign ( INPUT_ITERATOR  first,
INPUT_ITERATOR  last 
)
inline

Assign to this object the value resulting from first clearing this JsonArray and then inserting (in order) each Json object in the range starting at the specified first element, and ending immediately before the specified last element. If an exception is thrown, *this is left in a valid but unspecified state. Throw bsl::length_error if distance(first,last) > maxSize(). 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 Json, and Json must be emplace-constructible form *i, where i is a dereferenceable iterator in the range [first .. last). The behavior is undefined unless first and last refer to a range of valid values where first is at a position at or before last.

◆ back() [1/2]

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

Return a reference providing modifiable access to the last element in this JsonArray. The behavior is undefined unless this JsonArray is not empty.

◆ back() [2/2]

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

Return a reference providing non-modifiable access to the last element in this JsonArray. The behavior is undefined unless this JsonArray is not empty.

◆ begin() [1/2]

JsonArray::Iterator bdljsn::JsonArray::begin ( )
inline

Return an iterator providing modifiable access to the first element in this JsonArray, or the past-the-end iterator if thisJsonArray' is empty.

◆ begin() [2/2]

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

◆ BSLMF_NESTED_TRAIT_DECLARATION() [1/3]

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

◆ BSLMF_NESTED_TRAIT_DECLARATION() [2/3]

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

◆ BSLMF_NESTED_TRAIT_DECLARATION() [3/3]

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

◆ cbegin()

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

Return an iterator providing non-modifiable access to the first element in this JsonArray, and the past-the-end iterator if this JsonArray is empty.

◆ cend()

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

Return the past-the-end iterator providing non-modifiable access to this JsonArray.

◆ clear()

void bdljsn::JsonArray::clear ( )
inline

Remove all elements from this JsonArray making its size 0. Note that although this JsonArray is empty after this method returns, it preserves the same capacity it had before the method was called.

◆ empty()

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

◆ end() [1/2]

JsonArray::Iterator bdljsn::JsonArray::end ( )
inline

Return the past-the-end iterator providing modifiable access to this JsonArray.

◆ end() [2/2]

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

◆ erase() [1/3]

JsonArray::Iterator bdljsn::JsonArray::erase ( bsl::size_t  index)
inline

Remove from this JsonArray the element at the specified index, and return an iterator providing modifiable access to the element immediately following the removed element, or the position returned by the method end if the removed element was the last in the sequence. The behavior is undefined unless index is in the range [0 .. size()).

◆ erase() [2/3]

JsonArray::Iterator bdljsn::JsonArray::erase ( ConstIterator  first,
ConstIterator  last 
)
inline

Remove from this JsonArray the sequence of elements starting at the specified first position and ending before the specified last position, and return an iterator providing modifiable access to the element immediately following the last removed element, or the position returned by the method end if the removed elements were last in the sequence. The behavior is undefined unless first is an iterator in the range [cbegin() .. cend()] (both endpoints included) and last is an iterator in the range [first .. cend()] (both endpoints included).

◆ erase() [3/3]

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

Remove from this JsonArray the element at the specified position, and return an iterator providing modifiable access to the element immediately following the removed element, or the position returned by the method end if the removed element was the last in the sequence. The behavior is undefined unless position is an iterator in the range [cbegin() .. cend()).

◆ front() [1/2]

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

Return a reference providing modifiable access to the first element in this JsonArray. The behavior is undefined unless this JsonArray is not empty.

◆ front() [2/2]

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

Return a reference providing non-modifiable access to the first element in this JsonArray. The behavior is undefined unless this JsonArray is not empty.

◆ insert() [1/6]

JsonArray::Iterator bdljsn::JsonArray::insert ( bsl::size_t  index,
bslmf::MovableRef< Json json 
)
inline

Insert at the specified index in this JsonArray the specified move-insertable json, and return an iterator referring to the newly inserted element. json is left in a valid but unspecified state. If an exception is thrown, this is unaffected. Throw bsl::length_error if size() == maxSize(). The behavior is undefined unless index is in the range [0 .. size()] (both endpoints included).

◆ insert() [2/6]

JsonArray::Iterator bdljsn::JsonArray::insert ( bsl::size_t  index,
const Json json 
)
inline

Insert at the specified index in this JsonArray a copy of the specified json, and return an iterator referring to the newly inserted element. If an exception is thrown, *this is unaffected. Throw bsl::length_error if size() == maxSize(). The behavior is undefined unless index is in the range [0 .. size()].

◆ insert() [3/6]

template<class INPUT_ITERATOR >
JsonArray::Iterator bdljsn::JsonArray::insert ( bsl::size_t  index,
INPUT_ITERATOR  first,
INPUT_ITERATOR  last 
)
inline

Insert at the specified index in this JsonArray the values in the range starting at the specified first element, and ending immediately before the specified last element. Return an iterator referring to the first newly inserted element. If an exception is thrown, *this is unaffected. Throw bsl::length_error if size() + distance(first, last) > maxSize(). 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 Json, and Json must be emplace-constructible from *i into this JsonArray, wherei' is a dereferenceable iterator in the range [first .. last). The behavior is undefined unless index is in the range [0 .. size()] (both endpoints included), and first and last refer to a range of valid values where first is at a position at or before last.

◆ insert() [4/6]

JsonArray::Iterator bdljsn::JsonArray::insert ( ConstIterator  position,
bslmf::MovableRef< Json json 
)
inline

Insert at the specified position in this JsonArray the specified move-insertable json, and return an iterator referring to the newly inserted element. json is left in a valid but unspecified state. If an exception is thrown, this is unaffected. Throw bsl::length_error if size() == maxSize(). The behavior is undefined unless position is an iterator in the range [begin() .. end()] (both endpoints included).

◆ insert() [5/6]

JsonArray::Iterator bdljsn::JsonArray::insert ( ConstIterator  position,
const Json json 
)
inline

Insert at the specified position in this JsonArray a copy of the specified json, and return an iterator referring to the newly inserted element. If an exception is thrown, *this is unaffected. Throw bsl::length_error if size() == maxSize(). The behavior is undefined unless position is an iterator in the range [begin() .. end()] (both endpoints included).

◆ insert() [6/6]

template<class INPUT_ITERATOR >
JsonArray::Iterator bdljsn::JsonArray::insert ( ConstIterator  position,
INPUT_ITERATOR  first,
INPUT_ITERATOR  last 
)
inline

Insert at the specified position in this JsonArray the values in the range starting at the specified first element, and ending immediately before the specified last element. Return an iterator referring to the first newly inserted element. If an exception is thrown, *this is unaffected. Throw bsl::length_error if size() + distance(first, last) > maxSize(). 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 value_type, and value_type must be emplace-constructible from *i into this JsonArray, where i is a dereferenceable iterator in the range [first .. last). The behavior is undefined unless position is an iterator in the range [begin() .. end()] (both endpoints included), and first and last refer to a range of valid values where first is at a position at or before last.

◆ maxSize()

bsl::size_t bdljsn::JsonArray::maxSize ( ) const
inline

Return a theoretical upper bound on the largest number of elements that this JsonArray could possibly hold. Note that there is no guarantee that the JsonArray can successfully grow to the returned size, or even close to that size without running out of resources. Also note that requests to create a JsonArray longer than this number of elements are guaranteed to raise a bsl::length_error exception.

◆ operator=() [1/2]

JsonArray & bdljsn::JsonArray::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 JsonArray if allocator() == rhs.allocator(); otherwise, all elements in this JsonArray are either destroyed or move-assigned to and each additional element in rhs is move-inserted into this JsonArray. rhs is left in a valid but unspecified state.

◆ operator=() [2/2]

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

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. If an exception is thrown, *this is left in a valid but unspecified state.

◆ operator[]() [1/2]

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

Return a reference providing modifiable access to the element at the specified index in this JsonArray. The behavior is undefined unless index < size().

◆ operator[]() [2/2]

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

Return a reference providing non-modifiable access to the element at the specified index in this JsonArray. The behavior is undefined unless index < size().

◆ popBack()

void bdljsn::JsonArray::popBack ( )
inline

Erase the last element from this JsonArray. The behavior is undefined if this JsonArray is empty.

◆ print()

bsl::ostream & bdljsn::JsonArray::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.

◆ pushBack() [1/2]

void bdljsn::JsonArray::pushBack ( bslmf::MovableRef< Json json)
inline

Append to the end of this JsonArray the specified move-insertable Json. value is left in a valid but unspecified state. If an exception is thrown, *this is unaffected. Throw bsl::length_error if size() == maxSize().

◆ pushBack() [2/2]

void bdljsn::JsonArray::pushBack ( const Json json)
inline

Append to the end of this JsonArray a copy of the specified json. If an exception is thrown, *this is unaffected. Throw bsl::length_error if size() == maxSize().

◆ resize() [1/2]

void bdljsn::JsonArray::resize ( bsl::size_t  count)
inline

Change the size of this JsonArray to the specified count. If count < size(), the elements in the range [count .. size()) are erased, and this function does not throw. If count > size(), the (newly created) elements in the range [size() .. count) are default-constructed Json objects, and if an exception is thrown, *this is unaffected. Throw bsl::length_error if count > maxSize().

◆ resize() [2/2]

void bdljsn::JsonArray::resize ( bsl::size_t  count,
const Json json 
)
inline

Change the size of this JsonArray to the specified count, inserting copies of the specified json at the end if count > size(). If count < size(), the elements in the range [count .. size()) are erased json is ignored, and this method does not throw. If count > size() and an exception is thrown, *this is unaffected. Throw bsl::length_error if count > maxSize().

◆ size()

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

◆ swap()

void bdljsn::JsonArray::swap ( JsonArray 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 JsonArray  
)
friend

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

◆ operator!=

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

Return false if the specified lhs and rhs objects have the same value, and true otherwise. Two JsonArray objects lhs and rhs have the same value if they have the same number of elements, and each element in the ordered sequence of elements of lhs has the same value as the corresponding element in the ordered sequence of elements of rhs.

◆ operator==

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

Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two JsonArray objects lhs and rhs have the same value if they have the same number of elements, and each element in the ordered sequence of elements of lhs has the same value as the corresponding element in the ordered sequence of elements of rhs.

◆ swap

void swap ( JsonArray ,
JsonArray  
)
friend

Exchange the value of the specified a JsonArray with that of the specified b JsonArray. 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: