xentara-utils v2.0.4
The Xentara Utility Library
|
Header of an array, without the actual elements. More...
#include <xentara/utils/cbor/Array.hpp>
Public Member Functions | |
constexpr | Array () noexcept=default |
Default constructor. | |
constexpr | Array (std::size_t size) |
Constructor for an array with a known length. | |
constexpr | Array (IndefiniteTag tag) noexcept |
Constructor for an indefinite length array. | |
constexpr auto | indefinite () const noexcept -> bool |
Checks whether the array has an indefinite length. | |
constexpr auto | size () const noexcept -> std::size_t |
Gets the length of the array. | |
constexpr auto | suggestCapacity () const noexcept -> std::size_t |
Suggests a capacity that can be used to reserve space in an std::vector or similar. | |
constexpr auto | empty () const noexcept -> bool |
Checks whether the array is empty. | |
auto | iterate (std::reference_wrapper< Decoder > decoder) const -> RangeIterator |
Creates an iterator for help in decoding the elements of the array. | |
Header of an array, without the actual elements.
This object can be used to insert and extract CBOR arrays. This object only encodes and decodes the array header, consisting of the major type and the length. The array elements and (for indefinite length arrays) the stop code must be extracted and inserted separately.
|
constexprdefaultnoexcept |
Default constructor.
This constructor creates an empty array.
|
constexpr |
Constructor for an array with a known length.
size The length of the array
std::length_error | The size is larger than supported. The largest possible std::size_t value is not supported because it is used to represent indefinite length arrays. |
|
constexprnoexcept |
Constructor for an indefinite length array.
tag | Always pass kIndefinite as this parameter |
|
constexprnoexcept |
Checks whether the array is empty.
Returns true if the array has length 0, or false if the length is greater 0, or if the array is indefinite length.
This function cannot determine whether arrays of indefinite length are empty, because that would require looking ahead into the JSON data that comes after the marker.
|
constexprnoexcept |
Checks whether the array has an indefinite length.
auto xentara::utils::cbor::Array::iterate | ( | std::reference_wrapper< Decoder > | decoder | ) | const -> RangeIterator |
Creates an iterator for help in decoding the elements of the array.
The returned iterator is not used to actually decode the individual elements, but only to keep track of whether all the elements have been read. The only thing the iterator decodes itself is the stop code (“beak”) at the end of an array with indefinite length.
To read an array of strings from a CBOR decoder, you can use the following code, for example:
std::runtime_error | The array has indefinite length, and an error occurred checking for the stop code at the beginning of the data. |
|
constexprnoexcept |
Gets the length of the array.
|
constexprnoexcept |
Suggests a capacity that can be used to reserve space in an std::vector or similar.
This function can be used in preparation to decoding the array elements into a collection that supports preallocation, like e.g. std::vector. Calling reserve() on the collection with the return value of this function will reserve space for all the elements if the element count is known. If the array has indefinite length, then suggestCapacity() will return 0, and no preallocation will take place.