libfly
6.2.2
C++20 utility library for Linux, macOS, and Windows
|
#include <json_iterator.hpp>
Public Types | |
enum class | Position : std::uint8_t { Begin , End } |
using | iterator_category = std::bidirectional_iterator_tag |
using | value_type = JsonType |
using | difference_type = typename JsonType::difference_type |
using | reference = std::conditional_t< is_const_iterator, typename JsonType::const_reference, typename JsonType::reference > |
using | pointer = std::conditional_t< is_const_iterator, typename JsonType::const_pointer, typename JsonType::pointer > |
Public Member Functions | |
JsonIterator ()=default | |
JsonIterator (pointer json, Position position) noexcept(false) | |
JsonIterator (const NonConstJsonIterator &iterator) noexcept | |
JsonIterator & | operator= (const NonConstJsonIterator &iterator) noexcept |
reference | operator* () const |
pointer | operator-> () const |
reference | operator[] (difference_type offset) const |
bool | operator== (const JsonIterator &iterator) const |
bool | operator!= (const JsonIterator &iterator) const |
bool | operator< (const JsonIterator &iterator) const |
bool | operator<= (const JsonIterator &iterator) const |
bool | operator> (const JsonIterator &iterator) const |
bool | operator>= (const JsonIterator &iterator) const |
JsonIterator | operator++ (int) |
JsonIterator & | operator++ () |
JsonIterator | operator-- (int) |
JsonIterator & | operator-- () |
JsonIterator & | operator+= (difference_type offset) |
JsonIterator & | operator-= (difference_type offset) |
JsonIterator | operator+ (difference_type offset) const |
JsonIterator | operator- (difference_type offset) const |
difference_type | operator- (const JsonIterator &iterator) const |
const json_object_type::key_type & | key () const |
reference | value () const |
Friends | |
template<typename J > | |
JsonIterator< J > | operator+ (typename JsonIterator< J >::difference_type offset, const JsonIterator< J > &iterator) |
Class to provide iterator access to a Json instance. Both const and non-const iterators are supported.
For Json object instances, this class satisfies the requirements of a BidirectionalIterator. For Json array instances, this class satisfies the requirements of a RandomAccessIterator. All other Json types are not supported.
Iterators may be default constructed, copy constructed, or constructed from a Json instance. A requirement of iterators is to allow constructing a const iterator from a non-const iterator (and to forbid the other direction). To achieve this, the standard copy constructor and assignment operator are left implicitly defined. Overloads are explictly defined which accept non-const iterators. These allow constructing const iterators from const iterators, non-const iterators from non-const iterators, and const iterators from non- const iterators.
Iterators are protected against some classes of undefined behavior. If any of the below conditions are met, an exception will be raised:
1. Dereferencing an empty or past-the-end iterator. 2. Creating an iterator which escapes the range [begin, end] of the Json instance. 3. Performing RandomAccessIterator operations on a BidirectionalIterator.
There is not yet protection against an iterator-invalidating operation on the Json instance. For example, the following will not raise an exception:
fly::Json json {1, 2, 3}; auto it = json.begin(); json = {4, 5, 6}; bool b = it->empty(); // Undefined behavior
using fly::detail::JsonIterator< JsonType >::iterator_category = std::bidirectional_iterator_tag |
Aliases for canonical STL iterator member types.
|
strong |
Enumeration to indicate the initial position of the iterator.
|
default |
Default constructor. Initializes the iterator to an empty value.
|
noexcept |
Constructor to initialize the iterator to be pointed at the beginning or end of a Json instance.
json | A pointer to the Json instance. |
position | The initial position of the iterator. |
JsonIteratorException | If the Json instance is not iterable. |
|
noexcept |
Conversion copy constructor. Allows constructing a const or non-const iterator from a non-const iterator.
iterator | The iterator instance to copy. |
const json_object_type::key_type & fly::detail::JsonIterator< JsonType >::key |
Retrieve a reference to the key of the Json instance pointed to by this iterator. Only valid for Json object types.
JsonIteratorException | If the Json instance is not an object. |
NullJsonException | If the iterator is empty or past-the-end. |
bool fly::detail::JsonIterator< JsonType >::operator!= | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Unequality comparison operator.
iterator | The iterator instance to compare. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
auto fly::detail::JsonIterator< JsonType >::operator* |
Retrieve a reference to the Json instance pointed to by this iterator.
NullJsonException | If the iterator is empty or past-the-end. |
auto fly::detail::JsonIterator< JsonType >::operator+ | ( | difference_type | offset | ) | const |
Addition operator. Retrieve an iterator pointed at the Json instance some offset earlier or later in the sequence. Invalid for Json object types.
offset | The offset to retrieve. |
JsonIteratorException | If the Json instance is an object. |
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the iterator at the offset escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator++ |
Pre-increment operator. Sets the instance pointed to by this iterator to the next instance in the sequence.
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the next iterator escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator++ | ( | int | ) |
Post-increment operator. Sets the instance pointed to by this iterator to the next instance in the sequence.
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the next iterator escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator+= | ( | difference_type | offset | ) |
Addition operator. Sets the Json instance pointed to by this iterator to some offset earlier or later in the sequence. Invalid for Json object types.
offset | The offset by which to increment the iterator. |
JsonIteratorException | If the Json instance is an object. |
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the iterator at the offset escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator- | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Difference operator. Compute the distance between this iterator and another. Invalid for Json object types.
iterator | The iterator instance to compare. |
JsonIteratorException | If the Json instance is an object. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
auto fly::detail::JsonIterator< JsonType >::operator- | ( | difference_type | offset | ) | const |
Subtraction operator. Retrieve an iterator pointed at the Json instance some offset earlier or later in the sequence. Invalid for Json object types.
offset | The offset to retrieve. |
JsonIteratorException | If the Json instance is an object. |
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the iterator at the offset escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator-- |
Pre-decrement operator. Sets the instance pointed to by this iterator to the previous instance in the sequence.
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the previous iterator escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator-- | ( | int | ) |
Post-decrement operator. Sets the instance pointed to by this iterator to the previous instance in the sequence.
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the previous iterator escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator-= | ( | difference_type | offset | ) |
Subtraction operator. Sets the Json instance pointed to by this iterator to some offset earlier or later in the sequence. Invalid for Json object types.
offset | The offset by which to decrement the iterator. |
JsonIteratorException | If the Json instance is an object. |
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the iterator at the offset escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::operator-> |
Retrieve a pointer to the Json instance pointed to by this iterator.
NullJsonException | If the iterator is empty or past-the-end. |
bool fly::detail::JsonIterator< JsonType >::operator< | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Less-than comparison operator. Invalid for Json object types.
iterator | The iterator instance to compare. |
JsonIteratorException | If the Json instance is an object. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
bool fly::detail::JsonIterator< JsonType >::operator<= | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Less-than-or-equal-to comparison operator. Invalid for Json object types.
iterator | The iterator instance to compare. |
JsonIteratorException | If the Json instance is an object. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
|
noexcept |
Conversion assignment operator. Allows initializing a const or non-const iterator from a non-const iterator.
iterator | The iterator instance to copy. |
bool fly::detail::JsonIterator< JsonType >::operator== | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Equality comparison operator.
iterator | The iterator instance to compare. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
bool fly::detail::JsonIterator< JsonType >::operator> | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Greater-than comparison operator. Invalid for Json object types.
iterator | The iterator instance to compare. |
JsonIteratorException | If the Json instance is an object. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
bool fly::detail::JsonIterator< JsonType >::operator>= | ( | const JsonIterator< JsonType > & | iterator | ) | const |
Greater-than-or-equal-to comparison operator. Invalid for Json object types.
iterator | The iterator instance to compare. |
JsonIteratorException | If the Json instance is an object. |
BadJsonComparisonException | If the two iterators are not for the same Json instance. |
NullJsonException | If either iterator is empty. |
auto fly::detail::JsonIterator< JsonType >::operator[] | ( | difference_type | offset | ) | const |
Retrieve a reference to the Json instance at some offset earlier or later than the instance pointed to by this iterator. Invoking operator[0] is equivalent to invoking operator*. Invalid for Json object types.
offset | The offset to retrieve. |
JsonIteratorException | If the Json instance is an object. |
NullJsonException | If the iterator at the offset is empty or past-the-end. |
OutOfRangeJsonException | If the iterator at the offset escapes the Json instance's valid range. |
auto fly::detail::JsonIterator< JsonType >::value |
Retrieve a reference to the Json instance pointed to by this iterator.
NullJsonException | If the iterator is empty or past-the-end. |
|
friend |
Addition operator. Retrieve an iterator pointed at the Json instance some offset earlier or later in the sequence. Invalid for Json object types.
offset | The offset to retrieve. |
JsonIteratorException | If the Json instance is an object. |
NullJsonException | If the iterator is empty. |
OutOfRangeJsonException | If the iterator at the offset escapes the Json instance's valid range. |