DLL-boundary-safe owned contiguous sequence of std::byte.
More...
#include <StormByte/binary_data.hxx>
Public Types | |
| using | value_type = std::byte |
| Element type. | |
| using | size_type = std::size_t |
| STL size typedef; size() returns StormByte::ByteSize. | |
| using | difference_type = std::ptrdiff_t |
| Iterator difference. | |
| using | reference = std::byte & |
| Mutable reference to an element. | |
| using | const_reference = const std::byte & |
| Const reference to an element. | |
| using | pointer = std::byte * |
| Mutable pointer and iterator. | |
| using | const_pointer = const std::byte * |
| Const pointer and iterator. | |
| using | iterator = std::byte * |
| Contiguous mutable iterator. | |
| using | const_iterator = const std::byte * |
| Contiguous const iterator. | |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| Reverse iterator. | |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
| Const reverse iterator. | |
Public Member Functions | |
| BinaryData () noexcept | |
| Construct an empty sequence. | |
| BinaryData (const StormByte::ByteSize &count, std::byte value) | |
Construct count bytes filled with value. | |
| BinaryData (const StormByte::ByteSize &count) | |
Construct count zeroed bytes. | |
| BinaryData (std::span< const std::byte > bytes) | |
| Copy bytes from a contiguous span. | |
| BinaryData (const std::byte *bytes, const StormByte::ByteSize &count) | |
Copy count bytes starting at bytes. | |
| BinaryData (std::initializer_list< std::byte > list) | |
| Copy from an initializer list. | |
| BinaryData (std::string_view sv) | |
| Copy character bytes from a string view (no trailing NUL). | |
| BinaryData (const char *s) | |
| Copy character bytes from a C string (no trailing NUL). | |
| BinaryData (const std::vector< std::byte > &bytes) | |
| Copy bytes from a caller-owned vector onto Base's heap. | |
| BinaryData (std::vector< std::byte > &&bytes) | |
Copy bytes from a caller-owned vector onto Base's heap, then empty bytes. | |
| template<Type::ByteInputRange R> | |
| BinaryData (const R &range) | |
| Copy from an input range of byte-convertible values. | |
| template<Type::ByteInputRange R> | |
| BinaryData (R &&range) | |
| Consume an rvalue range. | |
| BinaryData (const BinaryData &other) | |
| Copy construct. | |
| BinaryData (BinaryData &&other) noexcept | |
| Move construct. | |
| ~BinaryData () noexcept | |
| Destroy the sequence on Base's heap. | |
| BinaryData & | operator= (const BinaryData &other) |
| Copy assign. | |
| BinaryData & | operator= (BinaryData &&other) noexcept |
| Move assign. | |
| BinaryData & | operator= (std::initializer_list< std::byte > list) |
| Replace contents with an initializer list. | |
| bool | operator== (const BinaryData &other) const noexcept |
| Equality of byte contents. | |
| bool | operator!= (const BinaryData &other) const noexcept |
| Inequality of byte contents. | |
| std::strong_ordering | operator<=> (const BinaryData &other) const noexcept |
Three-way lexicographical comparison (same order as std::vector). | |
| bool | operator== (std::span< const std::byte > bytes) const noexcept |
| Equality with a byte span. | |
| bool | operator!= (std::span< const std::byte > bytes) const noexcept |
| Inequality with a byte span. | |
| std::strong_ordering | operator<=> (std::span< const std::byte > bytes) const noexcept |
| Three-way comparison with a byte span. | |
| iterator | begin () noexcept |
| Mutable iterator to the first byte. | |
| const_iterator | begin () const noexcept |
| Const iterator to the first byte. | |
| iterator | end () noexcept |
| Mutable iterator one past the last byte. | |
| const_iterator | end () const noexcept |
| Const iterator one past the last byte. | |
| const_iterator | cbegin () const noexcept |
| Const iterator to the first byte. | |
| const_iterator | cend () const noexcept |
| Const iterator one past the last byte. | |
| reverse_iterator | rbegin () noexcept |
| Mutable reverse iterator to the last byte. | |
| reverse_iterator | rend () noexcept |
| Mutable reverse iterator to before the first byte. | |
| const_reverse_iterator | rbegin () const noexcept |
| Const reverse iterator to the last byte. | |
| const_reverse_iterator | rend () const noexcept |
| Const reverse iterator to before the first byte. | |
| const_reverse_iterator | crbegin () const noexcept |
| Const reverse iterator to the last byte. | |
| const_reverse_iterator | crend () const noexcept |
| Const reverse iterator to before the first byte. | |
| StormByte::ByteSize | size () const noexcept |
| Occupied length in bytes. | |
| StormByte::ByteSize | max_size () const noexcept |
| Implementation maximum size in bytes. | |
| StormByte::ByteSize | capacity () const noexcept |
| Allocated capacity in bytes. | |
| bool | empty () const noexcept |
| Whether the sequence holds no bytes. | |
| void | reserve (const StormByte::ByteSize &new_cap) |
Request capacity of at least new_cap bytes. | |
| void | resize (const StormByte::ByteSize &new_size) |
Resize to new_size bytes. | |
| void | resize (const StormByte::ByteSize &new_size, std::byte value) |
Resize to new_size bytes. | |
| void | shrink_to_fit () |
| Release unused capacity when the implementation allows it. | |
| void | clear () noexcept |
| Drop every byte. | |
| std::byte & | operator[] (const StormByte::ByteSize &index) noexcept |
| Unchecked mutable subscript. | |
| const std::byte & | operator[] (const StormByte::ByteSize &index) const noexcept |
| Unchecked const subscript. | |
| std::byte & | at (const StormByte::ByteSize &index) |
| Checked mutable subscript. | |
| const std::byte & | at (const StormByte::ByteSize &index) const |
| Checked const subscript. | |
| std::byte & | front () |
| First byte. | |
| const std::byte & | front () const |
| First byte. | |
| std::byte & | back () |
| Last byte. | |
| const std::byte & | back () const |
| Last byte. | |
| std::byte * | data () noexcept |
Mutable pointer to the first byte, or nullptr when empty. | |
| const std::byte * | data () const noexcept |
Const pointer to the first byte, or nullptr when empty. | |
| std::span< std::byte > | span () noexcept |
| Mutable view of the occupied bytes. | |
| std::span< const std::byte > | span () const noexcept |
| Const view of the occupied bytes. | |
| operator std::span< std::byte > () noexcept | |
| Implicit mutable span conversion. | |
| operator std::span< const std::byte > () const noexcept | |
| Implicit const span conversion. | |
| STORMBYTE_FORCE_INLINE | operator std::vector< std::byte > () const & |
Copy bytes onto the caller CRT as a std::vector. | |
| STORMBYTE_FORCE_INLINE | operator std::vector< std::byte > () && |
| Copy bytes onto the caller CRT, then release this object's storage. | |
| void | assign (const StormByte::ByteSize &count, std::byte value) |
Replace contents with count copies of value. | |
| void | assign (std::span< const std::byte > bytes) |
Replace contents with a copy of bytes. | |
| void | assign (std::initializer_list< std::byte > list) |
| Replace contents with an initializer list. | |
| template<typename InputIt > | |
| void | assign (InputIt first, InputIt last) |
Replace contents with the range [first, last). | |
| void | append (std::span< const std::byte > bytes) |
Append a copy of bytes. | |
| void | append (const std::byte *bytes, const StormByte::ByteSize &count) |
Append count bytes starting at bytes. | |
| void | append (const BinaryData &other) |
Append a copy of other. | |
| void | append (BinaryData &&other) |
Append other, then empty it. | |
| BinaryData & | operator+= (std::span< const std::byte > bytes) |
Append a copy of bytes. | |
| BinaryData & | operator+= (const BinaryData &other) |
Append a copy of other. | |
| BinaryData & | operator+= (BinaryData &&other) |
Append other, then empty it. | |
| void | push_back (std::byte value) |
| Append one byte. | |
| template<typename T > | |
| reference | emplace_back (T &&value) |
| Append a byte constructed in place. | |
| void | pop_back () |
| Remove the last byte. | |
| iterator | insert (const_iterator pos, std::byte value) |
Insert one byte before pos. | |
| iterator | insert (const_iterator pos, const StormByte::ByteSize &count, std::byte value) |
Insert count copies of value before pos. | |
| iterator | insert (const_iterator pos, std::initializer_list< std::byte > list) |
Insert an initializer list before pos. | |
| iterator | insert (const_iterator pos, std::span< const std::byte > bytes) |
Insert a span before pos. | |
| template<typename InputIt > | |
| iterator | insert (const_iterator pos, InputIt first, InputIt last) |
Insert the range [first, last) before pos. | |
| iterator | erase (const_iterator pos) |
Erase the byte at pos. | |
| iterator | erase (const_iterator first, const_iterator last) |
Erase [first, last). | |
| void | swap (BinaryData &other) noexcept |
Exchange storage with other. | |
| CString | HexDump () const |
| Hexadecimal dump of the occupied bytes, sixteen bytes per row. | |
| CString | HexDump (Size columns) const |
| Hexadecimal dump of the occupied bytes. | |
DLL-boundary-safe owned contiguous sequence of std::byte.
std::vector<std::byte> in a public signature that can cross a shared-library boundary (Windows DLL, or mismatched libc++ / libstdc++ on Unix).A std::vector constructed in the application and mutated inside a StormByte shared library — or returned and destroyed on the other side — allocates and frees with two heaps. That is undefined behaviour whenever the two sides do not share one CRT.
BinaryData owns its bytes on Base's heap. Allocation, growth and destruction run in this library. The header exposes contiguous std::byte* iterators, std::span views and a vector-like API so <algorithm> and std::ranges keep working.
Occupied length, capacity and byte offsets are ByteSize. HexDump column width is Size (a count of columns, not a payload).
Member names are lowercase to match std::vector.
std::vector std::vector and copied out to a caller-owned std::vector. The rvalue overloads look like a move: the source is emptied after the copy. They are not a heap steal. BinaryData storage is allocated and freed by Base; std::vector storage is allocated and freed by the caller CRT. Donating the pointer across those heaps would reintroduce the boundary this type exists to close. Peak usage is two copies during the transfer; afterwards the emptied side can release its allocation.| using StormByte::BinaryData::const_iterator = const std::byte* |
Contiguous const iterator.
| using StormByte::BinaryData::const_pointer = const std::byte* |
Const pointer and iterator.
| using StormByte::BinaryData::const_reference = const std::byte& |
Const reference to an element.
| using StormByte::BinaryData::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Const reverse iterator.
| using StormByte::BinaryData::difference_type = std::ptrdiff_t |
Iterator difference.
| using StormByte::BinaryData::iterator = std::byte* |
Contiguous mutable iterator.
| using StormByte::BinaryData::pointer = std::byte* |
Mutable pointer and iterator.
| using StormByte::BinaryData::reference = std::byte& |
Mutable reference to an element.
| using StormByte::BinaryData::reverse_iterator = std::reverse_iterator<iterator> |
Reverse iterator.
| using StormByte::BinaryData::size_type = std::size_t |
STL size typedef; size() returns StormByte::ByteSize.
| using StormByte::BinaryData::value_type = std::byte |
Element type.
|
noexcept |
Construct an empty sequence.
| StormByte::BinaryData::BinaryData | ( | const StormByte::ByteSize & | count, |
| std::byte | value | ||
| ) |
Construct count bytes filled with value.
| count | Element count. |
| value | Fill byte. |
|
explicit |
Construct count zeroed bytes.
| count | Element count. |
|
explicit |
Copy bytes from a contiguous span.
| bytes | Source view (not owned). |
| StormByte::BinaryData::BinaryData | ( | const std::byte * | bytes, |
| const StormByte::ByteSize & | count | ||
| ) |
Copy count bytes starting at bytes.
| bytes | Source pointer; may be null when count is zero. |
| count | Byte count. |
| StormByte::BinaryData::BinaryData | ( | std::initializer_list< std::byte > | list | ) |
Copy from an initializer list.
| list | Source bytes. |
|
explicit |
Copy character bytes from a string view (no trailing NUL).
| sv | Source characters. |
Copy character bytes from a C string (no trailing NUL).
| s | Source; a null pointer yields an empty sequence. |
|
explicit |
Copy bytes from a caller-owned vector onto Base's heap.
| bytes | Source. Remains valid and unchanged. |
|
explicit |
Copy bytes from a caller-owned vector onto Base's heap, then empty bytes.
| bytes | Source. Cleared and shrunk after the copy. |
Copy from an input range of byte-convertible values.
| R | Range type satisfying StormByte::Type::ByteInputRange. |
| range | Source range. |
|
explicit |
Consume an rvalue range.
Moves when R is an rvalue BinaryData.
| R | Range type satisfying StormByte::Type::ByteInputRange. |
| range | Source range. |
| StormByte::BinaryData::BinaryData | ( | const BinaryData & | other | ) |
Copy construct.
Allocation runs in Base.
| other | Source sequence. |
|
noexcept |
Move construct.
other is left empty.
| other | Source sequence. |
|
noexcept |
Destroy the sequence on Base's heap.
| void StormByte::BinaryData::append | ( | BinaryData && | other | ) |
Append other, then empty it.
| other | Source sequence. Empty afterwards when it is not *this. |
*this is empty. | void StormByte::BinaryData::append | ( | const BinaryData & | other | ) |
Append a copy of other.
| other | Source sequence. |
| void StormByte::BinaryData::append | ( | const std::byte * | bytes, |
| const StormByte::ByteSize & | count | ||
| ) |
Append count bytes starting at bytes.
| bytes | Source pointer; may be null when count is zero. |
| count | Byte count. |
Append a copy of bytes.
| bytes | Source view. |
| void StormByte::BinaryData::assign | ( | const StormByte::ByteSize & | count, |
| std::byte | value | ||
| ) |
Replace contents with count copies of value.
| count | New size. |
| value | Fill byte. |
Replace contents with the range [first, last).
| InputIt | Input iterator whose value converts to std::byte. |
| first | Start of the source range. |
| last | End of the source range. |
| void StormByte::BinaryData::assign | ( | std::initializer_list< std::byte > | list | ) |
Replace contents with an initializer list.
| list | Source bytes. |
Replace contents with a copy of bytes.
| bytes | Source view. |
| std::byte & StormByte::BinaryData::at | ( | const StormByte::ByteSize & | index | ) |
Checked mutable subscript.
| index | Byte offset. |
index. | StormByte::OutOfBoundsError | When index is not less than size(). |
| const std::byte & StormByte::BinaryData::at | ( | const StormByte::ByteSize & | index | ) | const |
Checked const subscript.
| index | Byte offset. |
index. | StormByte::OutOfBoundsError | When index is not less than size(). |
| std::byte & StormByte::BinaryData::back | ( | ) |
Last byte.
| const std::byte & StormByte::BinaryData::back | ( | ) | const |
Last byte.
|
noexcept |
Const iterator to the first byte.
data() when non-empty; a valid empty iterator otherwise.
|
noexcept |
Mutable iterator to the first byte.
data() when non-empty; a valid empty iterator otherwise.
|
noexcept |
Allocated capacity in bytes.
|
noexcept |
Const iterator to the first byte.
|
noexcept |
Const iterator one past the last byte.
|
noexcept |
Drop every byte.
Capacity may remain.
|
noexcept |
Const reverse iterator to the last byte.
|
noexcept |
Const reverse iterator to before the first byte.
|
noexcept |
Const pointer to the first byte, or nullptr when empty.
|
noexcept |
Mutable pointer to the first byte, or nullptr when empty.
| BinaryData::reference StormByte::BinaryData::emplace_back | ( | T && | value | ) |
Append a byte constructed in place.
| T | Value convertible to the integer stored in std::byte. |
| value | Argument forwarded into std::byte. |
|
noexcept |
Whether the sequence holds no bytes.
true when size() is zero.
|
noexcept |
Const iterator one past the last byte.
data() + size.
|
noexcept |
Mutable iterator one past the last byte.
data() + size. | iterator StormByte::BinaryData::erase | ( | const_iterator | first, |
| const_iterator | last | ||
| ) |
Erase [first, last).
| first | Start of the range. |
| last | End of the range. |
| iterator StormByte::BinaryData::erase | ( | const_iterator | pos | ) |
Erase the byte at pos.
| pos | Byte to erase. |
| std::byte & StormByte::BinaryData::front | ( | ) |
First byte.
| const std::byte & StormByte::BinaryData::front | ( | ) | const |
First byte.
| CString StormByte::BinaryData::HexDump | ( | ) | const |
Hexadecimal dump of the occupied bytes, sixteen bytes per row.
Same as HexDump() with 16 columns.
Hexadecimal dump of the occupied bytes.
Each line is an 8-digit offset, columns bytes as hex, and the same bytes as ASCII (non-printable shown as '.'). columns is a row width, not a byte length: it is Size, not ByteSize. 0 prints every byte on one line (still with offset and ASCII).
| columns | Bytes per row; 0 means a single row. |
| iterator StormByte::BinaryData::insert | ( | const_iterator | pos, |
| const StormByte::ByteSize & | count, | ||
| std::byte | value | ||
| ) |
Insert count copies of value before pos.
| pos | Insertion point. |
| count | Number of bytes. |
| value | Fill byte. |
pos when count is zero. | BinaryData::iterator StormByte::BinaryData::insert | ( | const_iterator | pos, |
| InputIt | first, | ||
| InputIt | last | ||
| ) |
Insert the range [first, last) before pos.
| InputIt | Input iterator whose value converts to std::byte. |
| pos | Insertion point. |
| first | Start of the source range. |
| last | End of the source range. |
pos when the range is empty. | iterator StormByte::BinaryData::insert | ( | const_iterator | pos, |
| std::byte | value | ||
| ) |
Insert one byte before pos.
| pos | Insertion point. |
| value | Byte to insert. |
| iterator StormByte::BinaryData::insert | ( | const_iterator | pos, |
| std::initializer_list< std::byte > | list | ||
| ) |
Insert an initializer list before pos.
| pos | Insertion point. |
| list | Source bytes. |
pos when list is empty. | iterator StormByte::BinaryData::insert | ( | const_iterator | pos, |
| std::span< const std::byte > | bytes | ||
| ) |
Insert a span before pos.
| pos | Insertion point. |
| bytes | Source view. |
pos when bytes is empty.
|
noexcept |
Implementation maximum size in bytes.
|
noexcept |
Implicit const span conversion.
|
noexcept |
Implicit mutable span conversion.
|
inlineexplicit |
Copy bytes onto the caller CRT, then release this object's storage.
std::vector. Peak usage is two copies during the transfer; *this is empty afterwards.
|
inlineexplicit |
Copy bytes onto the caller CRT as a std::vector.
*this is unchanged. STORMBYTE_FORCE_INLINE so the vector is not allocated inside this DLL.
|
noexcept |
Inequality of byte contents.
| other | Other sequence. |
|
noexcept |
Inequality with a byte span.
| bytes | View to compare. |
| BinaryData & StormByte::BinaryData::operator+= | ( | BinaryData && | other | ) |
Append other, then empty it.
| other | Source sequence. |
*this. | BinaryData & StormByte::BinaryData::operator+= | ( | const BinaryData & | other | ) |
Append a copy of other.
| other | Source sequence. |
*this. | BinaryData & StormByte::BinaryData::operator+= | ( | std::span< const std::byte > | bytes | ) |
Append a copy of bytes.
| bytes | Source view. |
*this.
|
noexcept |
Three-way lexicographical comparison (same order as std::vector).
| other | Other sequence. |
std::strong_ordering.
|
noexcept |
Three-way comparison with a byte span.
| bytes | View to compare. |
std::strong_ordering.
|
noexcept |
Move assign.
other is left empty.
| other | Source sequence. |
*this. | BinaryData & StormByte::BinaryData::operator= | ( | const BinaryData & | other | ) |
Copy assign.
Allocation runs in Base.
| other | Source sequence. |
*this. | BinaryData & StormByte::BinaryData::operator= | ( | std::initializer_list< std::byte > | list | ) |
Replace contents with an initializer list.
| list | Source bytes. |
*this.
|
noexcept |
Equality of byte contents.
| other | Other sequence. |
true when sizes and bytes match.
|
noexcept |
Equality with a byte span.
| bytes | View to compare. |
true when sizes and bytes match.
|
noexcept |
Unchecked const subscript.
| index | Byte offset. |
index.
|
noexcept |
Unchecked mutable subscript.
| index | Byte offset. |
index. | void StormByte::BinaryData::pop_back | ( | ) |
Remove the last byte.
| void StormByte::BinaryData::push_back | ( | std::byte | value | ) |
Append one byte.
| value | Byte to append. |
|
noexcept |
Const reverse iterator to the last byte.
const_reverse_iterator(end()).
|
noexcept |
Mutable reverse iterator to the last byte.
reverse_iterator(end()).
|
noexcept |
Const reverse iterator to before the first byte.
const_reverse_iterator(begin()).
|
noexcept |
Mutable reverse iterator to before the first byte.
reverse_iterator(begin()). | void StormByte::BinaryData::reserve | ( | const StormByte::ByteSize & | new_cap | ) |
Request capacity of at least new_cap bytes.
| new_cap | Requested capacity. |
| void StormByte::BinaryData::resize | ( | const StormByte::ByteSize & | new_size | ) |
Resize to new_size bytes.
Appended bytes are zero.
| new_size | New size. |
| void StormByte::BinaryData::resize | ( | const StormByte::ByteSize & | new_size, |
| std::byte | value | ||
| ) |
Resize to new_size bytes.
Appended bytes are value.
| new_size | New size. |
| value | Fill for new bytes. |
| void StormByte::BinaryData::shrink_to_fit | ( | ) |
Release unused capacity when the implementation allows it.
|
noexcept |
Occupied length in bytes.
|
noexcept |
|
noexcept |
|
noexcept |
Exchange storage with other.
| other | Other sequence. |