Quick Links: |
#include <bdljsn_json.h>
Public Types | |
typedef bsl::vector< Json > ::iterator | Iterator |
typedef bsl::vector< Json > ::const_iterator | ConstIterator |
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) | |
JsonArray (std::initializer_list< Json > elements, bslma::Allocator *basicAllocator=0) | |
JsonArray & | operator= (const JsonArray &rhs) |
JsonArray & | operator= (bslmf::MovableRef< JsonArray > rhs) |
JsonArray & | operator= (std::initializer_list< Json > initializer) |
void | assign (std::initializer_list< Json > initializer) |
Json & | operator[] (bsl::size_t index) |
template<class INPUT_ITERATOR > | |
void | assign (INPUT_ITERATOR first, INPUT_ITERATOR last) |
Iterator | begin () |
Iterator | end () |
Json & | front () |
Json & | back () |
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 Json & | operator[] (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 Json & | front () const |
const Json & | back () const |
bool | empty () const |
bsl::size_t | size () const |
bslma::Allocator * | allocator () const BSLS_KEYWORD_NOEXCEPT |
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 &) |
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).
typedef bsl::vector<Json>::iterator bdljsn::JsonArray::Iterator |
typedef bsl::vector<Json>::const_iterator bdljsn::JsonArray::ConstIterator |
bdljsn::JsonArray::JsonArray | ( | ) |
bdljsn::JsonArray::JsonArray | ( | bslma::Allocator * | basicAllocator | ) | [explicit] |
Create an empty JsonArray
. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used.
bdljsn::JsonArray::JsonArray | ( | const JsonArray & | original, | |
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdljsn::JsonArray::JsonArray | ( | bslmf::MovableRef< JsonArray > | original | ) |
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.
bdljsn::JsonArray::JsonArray | ( | bslmf::MovableRef< JsonArray > | original, | |
bslma::Allocator * | basicAllocator | |||
) |
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.
bdljsn::JsonArray::JsonArray | ( | INPUT_ITERATOR | first, | |
INPUT_ITERATOR | last, | |||
bslma::Allocator * | basicAllocator = 0 | |||
) |
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
.
bdljsn::JsonArray::JsonArray | ( | std::initializer_list< Json > | elements, | |
bslma::Allocator * | basicAllocator = 0 | |||
) |
bdljsn::JsonArray::BSLMF_NESTED_TRAIT_DECLARATION | ( | JsonArray | , | |
bslma::UsesBslmaAllocator | ||||
) |
bdljsn::JsonArray::BSLMF_NESTED_TRAIT_DECLARATION | ( | JsonArray | , | |
bslmf::IsBitwiseMoveable | ||||
) |
bdljsn::JsonArray::BSLMF_NESTED_TRAIT_DECLARATION | ( | JsonArray | , | |
bdlb::HasPrintMethod | ||||
) |
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.
JsonArray& bdljsn::JsonArray::operator= | ( | bslmf::MovableRef< JsonArray > | 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 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.
void bdljsn::JsonArray::assign | ( | std::initializer_list< Json > | initializer | ) |
Json& bdljsn::JsonArray::operator[] | ( | bsl::size_t | index | ) |
void bdljsn::JsonArray::assign | ( | INPUT_ITERATOR | first, | |
INPUT_ITERATOR | last | |||
) |
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
.
Iterator bdljsn::JsonArray::begin | ( | ) |
Return an iterator providing modifiable access to the first element in this JsonArray, or the past-the-end iterator if this 'JsonArray
is empty.
Iterator bdljsn::JsonArray::end | ( | ) |
Return the past-the-end iterator providing modifiable access to this JsonArray
.
Json& bdljsn::JsonArray::front | ( | ) |
Json& bdljsn::JsonArray::back | ( | ) |
void bdljsn::JsonArray::clear | ( | ) |
Iterator bdljsn::JsonArray::erase | ( | bsl::size_t | index | ) |
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())
.
Iterator bdljsn::JsonArray::erase | ( | ConstIterator | position | ) |
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())
.
Iterator bdljsn::JsonArray::erase | ( | ConstIterator | first, | |
ConstIterator | last | |||
) |
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).
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()]
.
Iterator bdljsn::JsonArray::insert | ( | bsl::size_t | index, | |
bslmf::MovableRef< Json > | json | |||
) |
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).
Iterator bdljsn::JsonArray::insert | ( | bsl::size_t | index, | |
INPUT_ITERATOR | first, | |||
INPUT_ITERATOR | last | |||
) |
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, where 'i
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
.
Iterator bdljsn::JsonArray::insert | ( | ConstIterator | position, | |
const Json & | json | |||
) |
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).
Iterator bdljsn::JsonArray::insert | ( | ConstIterator | position, | |
bslmf::MovableRef< Json > | json | |||
) |
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).
Iterator bdljsn::JsonArray::insert | ( | ConstIterator | position, | |
INPUT_ITERATOR | first, | |||
INPUT_ITERATOR | last | |||
) |
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
.
void bdljsn::JsonArray::popBack | ( | ) |
void bdljsn::JsonArray::pushBack | ( | const Json & | json | ) |
void bdljsn::JsonArray::pushBack | ( | bslmf::MovableRef< Json > | json | ) |
void bdljsn::JsonArray::resize | ( | bsl::size_t | count | ) |
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()
.
void bdljsn::JsonArray::resize | ( | bsl::size_t | count, | |
const Json & | json | |||
) |
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()
.
void bdljsn::JsonArray::swap | ( | JsonArray & | 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::JsonArray::operator[] | ( | bsl::size_t | index | ) | const |
ConstIterator bdljsn::JsonArray::begin | ( | ) | const |
ConstIterator bdljsn::JsonArray::cbegin | ( | ) | const |
ConstIterator bdljsn::JsonArray::end | ( | ) | const |
ConstIterator bdljsn::JsonArray::cend | ( | ) | const |
Return the past-the-end iterator providing non-modifiable access to this JsonArray
.
const Json& bdljsn::JsonArray::front | ( | ) | const |
const Json& bdljsn::JsonArray::back | ( | ) | const |
bool bdljsn::JsonArray::empty | ( | ) | const |
Return true
if this JsonArray
has size 0, and false
otherwise.
bsl::size_t bdljsn::JsonArray::size | ( | ) | const |
Return the number of elements in this JsonArray
.
bslma::Allocator* bdljsn::JsonArray::allocator | ( | ) | const |
Return the allocator used by this object to allocate memory.
bsl::size_t bdljsn::JsonArray::maxSize | ( | ) | const |
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.
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.
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
.
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
.
void hashAppend | ( | HASHALG & | , | |
const JsonArray & | ||||
) | [friend] |
Invoke the specified hashAlg
on the attributes of the specified object
.
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.