Pixie
Loading...
Searching...
No Matches
pixie::StorageBase< Impl > Class Template Reference

CRTP facade for byte-addressable storage. More...

#include <storage.h>

Inheritance diagram for pixie::StorageBase< Impl >:
pixie::SerializationBase< Impl >

Public Types

using position_type = std::uint64_t
 Monotonic logical byte position used to address storage ranges.
 

Public Member Functions

std::size_t size_bytes () const
 Return the logical exposed storage size in bytes.
 
std::size_t size_bits () const
 Return the exposed storage size in bits.
 
bool empty () const
 Check whether the storage is empty.
 
position_type begin_position () const
 Return the first logical byte position currently exposed.
 
position_type end_position () const
 Return the position one past the last logical byte exposed.
 
bool contains (position_type position, std::size_t count_bytes) const
 Return whether a complete logical range is currently exposed.
 
std::span< const std::byte > as_bytes () const
 Return a contiguous read-only view of all logical exposed bytes.
 
SplitSpan< std::byte > segments ()
 Return all logical bytes as one or two writable physical spans.
 
SplitSpan< const std::byte > segments () const
 Return all logical bytes as one or two physical spans.
 
SplitSpan< std::byte > segments (position_type position, std::size_t count_bytes)
 Return a checked writable logical byte range as one or two spans.
 
SplitSpan< const std::byte > segments (position_type position, std::size_t count_bytes) const
 Return a checked logical byte range as one or two physical spans.
 
std::span< const std::uint16_t > as_words16 () const
 Return a read-only view as 16-bit words.
 
std::span< const std::uint64_t > as_words64 () const
 Return a read-only view as 64-bit words.
 
auto view () const
 Return a non-owning read-only view of all exposed bytes.
 
auto view (std::size_t offset_bytes, std::size_t count_bytes) const
 Return a non-owning read-only byte subrange.
 
void serialize_impl (BinaryWriter &writer) const
 Serialize the exposed bytes with a 64-bit little-endian size prefix.
 
void resize (std::size_t size_bits)
 Resize mutable storage to hold at least size_bits bits.
 
auto writable_bytes ()
 Return writable storage bytes.
 
auto writable_words16 ()
 Return writable storage as 16-bit words.
 
auto writable_words64 ()
 Return writable storage as 64-bit words.
 
std::size_t allocated_bytes () const
 Return bytes reserved by an owning storage implementation.
 
void shrink_to_fit ()
 Request release of unused reserved storage.
 
- Public Member Functions inherited from pixie::SerializationBase< Impl >
void serialize (BinaryWriter &writer) const
 Serialize this value through its concrete implementation.
 

Additional Inherited Members

- Static Public Member Functions inherited from pixie::SerializationBase< Impl >
static Impl deserialize (BinaryReader &reader, Context &&... context)
 Restore exactly Derived and advance reader on success.
 
static Impl deserialize (std::span< const std::byte > &data, Context &&... context)
 Restore exactly Derived and advance a mutable byte span.
 

Detailed Description

template<class Impl>
class pixie::StorageBase< Impl >

CRTP facade for byte-addressable storage.

Impl must provide size_bytes_impl() and the following required extension points.

Required: begin_position_impl() const
Returns the absolute logical position of the first exposed byte as a position_type. The result may advance when an implementation evicts bytes, but positions of retained bytes do not change.
Required: end_position_impl() const
Returns the absolute logical position one past the last exposed byte as a position_type. It must be at least begin_position_impl(), and their difference must be representable by std::size_t and equal size_bytes_impl().
Required: segments_impl(position, count_bytes) const
Accepts a position_type and a std::size_t and returns SplitSpan<const std::byte> containing exactly the bytes in [position, position + count_bytes). The physical spans are ordered by logical position and their combined size equals count_bytes. Before calling this hook, the facade verifies without overflow that position is in the closed range from begin_position_impl() through end_position_impl() and that count_bytes <= end_position_impl() - position; an empty range at the end position is valid. The returned spans borrow the implementation's backing storage. The implementation must document the backing storage's ownership requirements and the operations that invalidate its spans.
Optional: segments_impl(position, count_bytes)
A mutable implementation may provide this extension point to enable writable segment access. It accepts the same parameter types as the const overload and returns SplitSpan<std::byte>. It has the same range, ordering, size, lifetime, and invalidation contract as the const overload, and writes through the returned spans modify the corresponding logical bytes. If the implementation also provides prepare_segments_impl(position, count_bytes), the facade calls that hook before validating the range. The preparation hook must make the complete requested range available or throw without changing the implementation.
Template Parameters
ImplConcrete storage implementation.

Member Function Documentation

◆ as_words16()

template<class Impl>
std::span< const std::uint16_t > pixie::StorageBase< Impl >::as_words16 ( ) const
inline

Return a read-only view as 16-bit words.

Exceptions
std::invalid_argumentif the data is misaligned or its size is not divisible by the word size.

◆ as_words64()

template<class Impl>
std::span< const std::uint64_t > pixie::StorageBase< Impl >::as_words64 ( ) const
inline

Return a read-only view as 64-bit words.

Exceptions
std::invalid_argumentif the data is misaligned or its size is not divisible by the word size.

◆ segments() [1/4]

template<class Impl>
SplitSpan< std::byte > pixie::StorageBase< Impl >::segments ( )
inline

Return all logical bytes as one or two writable physical spans.

Available only for mutable storage implementations. Mutating or resizing the storage may invalidate the returned descriptor.

◆ segments() [2/4]

template<class Impl>
SplitSpan< const std::byte > pixie::StorageBase< Impl >::segments ( ) const
inline

Return all logical bytes as one or two physical spans.

Contiguous storage returns one segment. A ring-backed storage can return its tail followed by its head without allocation or copying.

◆ segments() [3/4]

template<class Impl>
SplitSpan< std::byte > pixie::StorageBase< Impl >::segments ( position_type position,
std::size_t count_bytes )
inline

Return a checked writable logical byte range as one or two spans.

An implementation with a preparation hook may make a future range available before checking it. Any newly exposed bytes remain the caller's responsibility to initialize.

Parameters
positionFirst logical byte position in the range.
count_bytesNumber of logical bytes in the range.
Exceptions
std::out_of_rangeif the range cannot be made available.

◆ segments() [4/4]

template<class Impl>
SplitSpan< const std::byte > pixie::StorageBase< Impl >::segments ( position_type position,
std::size_t count_bytes ) const
inline

Return a checked logical byte range as one or two physical spans.

Parameters
positionFirst logical byte position in the range.
count_bytesNumber of logical bytes in the range.
Exceptions
std::out_of_rangeif the range is outside this storage.

◆ size_bytes()

template<class Impl>
std::size_t pixie::StorageBase< Impl >::size_bytes ( ) const
inline

Return the logical exposed storage size in bytes.

An owning implementation may reserve or pad more memory; use allocated_bytes() when that physical allocation size is required.

◆ view()

template<class Impl>
auto pixie::StorageBase< Impl >::view ( std::size_t offset_bytes,
std::size_t count_bytes ) const
inline

Return a non-owning read-only byte subrange.

Parameters
offset_bytesFirst byte in the view.
count_bytesNumber of bytes in the view.
Exceptions
std::out_of_rangeif the subrange is outside this storage.

The documentation for this class was generated from the following file: