|
SofaBuffers C/C++ 0.12.0
API Documentation
|
Fixed-capacity, heap-free string of up to N characters.
More...
#include <sofab.hpp>
Public Types | |
| using | value_type = char |
Character type (mirrors std::string). | |
| using | size_type = std::size_t |
Size type (mirrors std::string). | |
Public Member Functions | |
| FixedString () noexcept=default | |
| Construct an empty string. | |
| FixedString (const char *s) noexcept | |
Construct from a NUL-terminated C string (clamped to N, see assign). | |
| FixedString (std::string_view sv) noexcept | |
Construct from a string view (clamped to N, see assign). | |
| FixedString & | operator= (const char *s) noexcept |
Assign from a NUL-terminated C string (clamped to N, see assign). | |
| FixedString & | operator= (std::string_view sv) noexcept |
Assign from a string view (clamped to N, see assign). | |
| FixedString & | assign (std::string_view sv) noexcept |
Replace the contents with sv, clamped to N bytes. | |
| void | set_len (std::size_t n) noexcept |
| Decode hook: set the logical length and (re)place the trailing NUL. | |
| char * | data () noexcept |
| Mutable pointer to the character buffer (decode target). | |
| const char * | data () const noexcept |
| Const pointer to the character buffer. | |
| const char * | c_str () const noexcept |
| NUL-terminated view of the contents. | |
| std::size_t | size () const noexcept |
| Number of characters currently stored. | |
| std::size_t | length () const noexcept |
| Alias of size. | |
| bool | empty () const noexcept |
| True if the string is empty. | |
| char & | operator[] (std::size_t i) noexcept |
Access the character at i (no bounds checking). | |
| const char & | operator[] (std::size_t i) const noexcept |
Access the character at i (no bounds checking). | |
| char * | begin () noexcept |
| Iterator to the first character. | |
| char * | end () noexcept |
| Iterator past the last character. | |
| const char * | begin () const noexcept |
| Const iterator to the first character. | |
| const char * | end () const noexcept |
| Const iterator past the last character. | |
| void | clear () noexcept |
| Reset to an empty string. | |
| std::string_view | view () const noexcept |
| Non-owning view over the current characters. | |
| operator std::string_view () const noexcept | |
Implicit conversion to std::string_view. | |
| bool | operator== (std::string_view rhs) const noexcept |
| Equality against any string view-like operand. | |
| bool | operator!= (std::string_view rhs) const noexcept |
| Inequality against any string view-like operand. | |
Static Public Member Functions | |
| static constexpr std::size_t | capacity () noexcept |
Maximum number of characters (the template parameter N). | |
| static constexpr std::size_t | max_size () noexcept |
| Alias of capacity. | |
Fixed-capacity, heap-free string of up to N characters.
A drop-in, embedded-friendly stand-in for std::string on both the encode and decode paths. The characters live in an inline std::array, so an instance allocates nothing, never throws (an over-long value is clamped to N bytes at a UTF-8 character boundary, see assign), and compiles cleanly under -fno-exceptions / -fno-rtti. Because the buffer never moves, an instance is a valid address-stable decode target for the deferred IStreamImpl decoder (bytes bound now, filled by a later IStreamImpl::feed pass).
The storage is N+1 bytes: one extra slot always holds a trailing NUL so c_str and the std::string_view encode path remain valid even at full length N. The buffer is zero-initialised, so the NUL is present from construction and is re-placed by every length-changing operation.
std::string path exactly, so this type keeps a stable surface for it:s.set_len(_size); if (_size) is.read(s); — set_len fixes the logical length (and terminating NUL) before the read binds the buffer, and IStreamImpl::read fills data() over size() bytes;os.write(id, s); — the implicit operator std::string_view routes it through the existing string encode branch, byte-for-byte identical to the same-content std::string.| N | Maximum number of characters (excluding the reserved NUL slot). |
| using sofab::FixedString< N >::size_type = std::size_t |
| using sofab::FixedString< N >::value_type = char |
|
defaultnoexcept |
Construct an empty string.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Replace the contents with sv, clamped to N bytes.
The assignment-time clamp is a documented contract of the static storage (the generator's allow_dynamic: false): a value longer than N is cut, not refused, before any encoder sees it. The cut never lands inside a UTF-8 character – it moves back to the start of the character that would not fit whole, so the kept prefix is valid UTF-8 whenever sv is.
| sv | Source characters (may contain embedded NULs). |
*this. Definition at line 391 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
Implicit conversion to std::string_view.
Gives a cheap non-owning view and makes the existing string encode branch (OStreamImpl::write) match a FixedString automatically.
Definition at line 471 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Decode hook: set the logical length and (re)place the trailing NUL.
Called by generated decode before binding the buffer: it fixes size() to the field length (clamped to N) and writes the NUL at buf_[len_]. The subsequent IStreamImpl::read binds exactly size() bytes via sofab_istream_read_string_noterm, which fills [0, size()) and never touches buf_[len_], so the NUL survives and c_str stays valid. Re-decoding a shorter value re-terminates here.
| n | Requested logical length (clamped to N). |
Definition at line 414 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |