|
SofaBuffers C/C++ 0.12.0
API Documentation
|
Fixed-capacity, heap-free sequence of up to N elements of type T.
More...
#include <sofab.hpp>
Public Types | |
| using | value_type = T |
Element type (mirrors std::vector). | |
| using | size_type = std::size_t |
Size type (mirrors std::vector). | |
Public Member Functions | |
| InlineVector () noexcept=default | |
| Construct an empty sequence. | |
| InlineVector (std::initializer_list< T > init) noexcept | |
Construct from a brace-enclosed list of elements (clamped to N; extra elements are dropped). | |
| InlineVector & | operator= (std::initializer_list< T > init) noexcept |
Replace the contents from a brace-enclosed list (clamped to N; extra elements are dropped). | |
| InlineVector & | assign (std::initializer_list< T > init) noexcept |
Replace the contents from a brace-enclosed list (clamped to N; extra elements are dropped). | |
| std::size_t | size () const noexcept |
| Number of elements currently stored. | |
| bool | empty () const noexcept |
| True if the sequence is empty. | |
| void | reserve (std::size_t) noexcept |
| No-op (inline storage never reallocates); present for API parity. | |
| void | clear () noexcept |
| Reset to an empty sequence (logical length only). | |
| void | resize (std::size_t n) noexcept |
Set the logical length to n, value-initializing what changes. | |
| T & | emplace_back () noexcept |
| Append a default-constructed element and return a reference to it. | |
| void | push_back (const T &v) noexcept |
Append a copy of v; once at capacity N, v is dropped. | |
| void | push_back (T &&v) noexcept |
Append v by move; dropped once at capacity N (see above). | |
| T & | back () noexcept |
| Reference to the last element. | |
| const T & | back () const noexcept |
| Const reference to the last element. | |
| T & | operator[] (std::size_t i) noexcept |
Access the element at i (no bounds checking). | |
| const T & | operator[] (std::size_t i) const noexcept |
Access the element at i (no bounds checking). | |
| T * | data () noexcept |
| Mutable pointer to the underlying storage. | |
| const T * | data () const noexcept |
| Const pointer to the underlying storage. | |
| T * | begin () noexcept |
| Iterator to the first element. | |
| T * | end () noexcept |
| Iterator past the last element. | |
| const T * | begin () const noexcept |
| Const iterator to the first element. | |
| const T * | end () const noexcept |
| Const iterator past the last element. | |
| bool | operator== (const InlineVector &o) const noexcept |
| Content equality (same logical length and elements). | |
| bool | operator!= (const InlineVector &o) const noexcept |
| Negated operator==. | |
Static Public Member Functions | |
| static constexpr std::size_t | capacity () noexcept |
Maximum number of elements (the template parameter N). | |
| static constexpr std::size_t | max_size () noexcept |
| Alias of capacity. | |
Fixed-capacity, heap-free sequence of up to N elements of type T.
The embedded-friendly counterpart of std::vector<T> for the sequence fields the fixed-capacity profile lowers without a heap: arrays of strings, blobs, structs/unions or nested arrays. Elements live in an inline std::array, so the storage never reallocates and a bound-then-filled element (the deferred IStreamImpl decoder) stays address-stable — strictly safer than a std::vector + reserve.
A logical length (size, <= N) is tracked separately from the capacity N: an array shorter than its schema count holds only size elements. This is why the type is neither a plain std::array<T,N> (always length N) nor a heap-backed std::vector.
v = {a, b, c} silently filled the storage while leaving the logical length at 0 — the field then encoded as empty. The initializer_list constructor/assignment below make the type a non-aggregate, so that brace-init now sets size correctly instead of corrupting the wire.| T | Element type. |
| N | Maximum number of elements. |
|
defaultnoexcept |
Construct an empty sequence.
|
inlinenoexcept |
Construct from a brace-enclosed list of elements (clamped to N; extra elements are dropped).
The presence of this constructor makes InlineVector a non-aggregate: v = {a, b, c} routes here and sets size, instead of aggregate brace-init filling the storage while leaving the length at 0.
| init | Source elements (excess beyond N is dropped). |
Definition at line 725 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Append a default-constructed element and return a reference to it.
The next inline slot is (re)set to T{} and bound; once at capacity N the last slot is reused so a decode never writes out of bounds.
Definition at line 811 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
Negated operator==.
Definition at line 872 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Append a copy of v; once at capacity N, v is dropped.
The assignment-time clamp of the static storage: elements past N are left out and the ones already held are kept, so a filled container holds the first N values it was given. (emplace_back, the decode-side binder, reuses the last slot instead.)
Definition at line 826 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Set the logical length to n, value-initializing what changes.
The std::vector member of the container API this type mirrors, and the one IStreamImpl::readArray and the wrapper-array collectors probe for: readArray resizes a resizable destination and value-initializes a fixed-extent one, and without this method an InlineVector matched neither — it fell to the fixed-extent branch, which assigned a default-constructed container and so set the logical length to 0. The decode then bound an empty span and dropped the array silently. With resize present, readArray keeps ownership of the tag / bound / reset / bind order it documents, for inline storage too.
Slots that enter or leave the logical range are set to T{}, so the elements a shorter value no longer covers cannot be observed through a later grow. n above the capacity N is clamped to N — the callers that can reject an over-capacity count do so before resizing (readArray checks the schema count first), and a heap-free container has nowhere to put the excess.
| n | New logical length. |
Definition at line 787 of file sofab.hpp.
|
inlinenoexcept |