xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::cbor::RangeIterator Class Referencefinal

An object that can be used to keep track of the elements when decoding a CBOR array or map. More...

#include <xentara/utils/cbor/RangeIterator.hpp>

Classes

struct  DummyValue
 A dummy value type. More...
 

Public Types

using value_type = DummyValue
 The value type.
 
using difference_type = std::ptrdiff_t
 Dummy type for non-existend difference type.
 
using reference = DummyValue
 A “reference” to a value, which is not an actual reference, but the value itself.
 
using pointer = void
 void type denoting that this class has no pointer type.
 
using iterator_concept = std::input_iterator_tag
 The iterator concept.
 
using iterator_category = iterator_concept
 The iterator category, for use in pre-C++20 code.
 

Public Member Functions

constexpr RangeIterator () noexcept=default
 Default constructor.
 
constexpr RangeIterator (std::default_sentinel_t) noexcept
 Conversion constructor for a sentinel.
 
auto operator== (const RangeIterator &rhs) const noexcept -> bool
 Equality operator.
 
auto operator++ () -> RangeIterator &
 Pre-increment operator.
 
auto operator++ (int) -> DummyValue
 Post-increment operator.
 
auto operator* () noexcept -> DummyValue
 Indirection operator.
 

Related Symbols

(Note that these are not member symbols.)

auto begin (RangeIterator iterator) -> RangeIterator
 Gets a begin iterator for a CBOR range iterator.
 
auto end (RangeIterator) -> std::default_sentinel_t
 Gets an end iterator for a standard path iterator.
 

Detailed Description

An object that can be used to keep track of the elements when decoding a CBOR array or map.

This object has begin() and end() functions to allows it to be used like a stream iterator. However, the object is not used to actually decode the entries, but only to keep track of whether all the entries have been read yet.

See also
Array::iterate()
Map::iterate()

Member Typedef Documentation

◆ difference_type

Dummy type for non-existend difference type.

◆ iterator_category

The iterator category, for use in pre-C++20 code.

◆ iterator_concept

◆ pointer

void type denoting that this class has no pointer type.

◆ reference

A “reference” to a value, which is not an actual reference, but the value itself.

◆ value_type

Constructor & Destructor Documentation

◆ RangeIterator() [1/2]

constexpr xentara::utils::cbor::RangeIterator::RangeIterator ( )
constexprdefaultnoexcept

Default constructor.

This constructor creates an invalid iterator. It is suitable as a sentinel for algorithms that require the sentinel to be of the same type as the iterator.

◆ RangeIterator() [2/2]

constexpr xentara::utils::cbor::RangeIterator::RangeIterator ( std::default_sentinel_t  )
constexprnoexcept

Conversion constructor for a sentinel.

This constructor creates an invalid iterator suitable for use as a sentinel for algorithms that require the sentinel to be of the same type as the iterator.

Member Function Documentation

◆ operator*()

auto xentara::utils::cbor::RangeIterator::operator* ( ) -> DummyValue
noexcept

Indirection operator.

Precondition
Must not be called on an exhaused iterator
Returns
A dummy value object.

◆ operator++() [1/2]

auto xentara::utils::cbor::RangeIterator::operator++ ( ) -> RangeIterator &

Pre-increment operator.

Moves the iterator forward by one position. If the array or map has indefinite length, this operator checks for and consumes the stop code (“break”).

Precondition
Must not be called on an exhaused iterator
Exceptions
std::runtime_errorThe array or map has indefinite length, and an error occurred consuming the stop code

◆ operator++() [2/2]

auto xentara::utils::cbor::RangeIterator::operator++ ( int  ) -> DummyValue

Post-increment operator.

Moves the iterator forward by one position. If the array or map has indefinite length, this operator checks for and consumes the stop code (“break”).

Precondition
Must not be called on an exhaused iterator
Returns
A dummy value object.
Exceptions
std::runtime_errorThe array or map has indefinite length, and an error occurred consuming the stop code

◆ operator==()

auto xentara::utils::cbor::RangeIterator::operator== ( const RangeIterator rhs) const -> bool
noexcept

Equality operator.

This operator is intended to be used to check for the end of an array or map in algorithms that do not support std::default_sentinel_t, but use an invalid iterator as sentinel instead.

This method does not check the position of the iterator within the array or map. Any valid iterator will compare equal to any other valid iterator. An iterator that has gone past the end of the array or map will compare equal to a default constructed iterator, or an iterator that was constructed from std::default_sentinel.

Friends And Related Symbol Documentation

◆ begin()

auto begin ( RangeIterator  iterator) -> RangeIterator
related

Gets a begin iterator for a CBOR range iterator.

This function enables the use of RangeIterator in range-based for loops

Parameters
iteratorThe iterator to iterate over
Returns
Simply returns a copy of the iterator

◆ end()

auto end ( RangeIterator  ) -> std::default_sentinel_t
related

Gets an end iterator for a standard path iterator.

This function enables the use of RangeIterator in range-based for loops

Returns
The global default sentinel