Skip to main content

RaggedStorageWrapper

RaggedStorageWrapper

Type-erased storage wrapper using virtual dispatch. More…

#include <RaggedStorage.hpp>

Public Functions

Name
template <typename StorageImpl >
RaggedStorageWrapper(StorageImpl storage)
Construct wrapper from any storage implementation.
RaggedStorageWrapper()
RaggedStorageWrapper(RaggedStorageWrapper && ) =default
RaggedStorageWrapper & operator=(RaggedStorageWrapper && ) =default
RaggedStorageWrapper(RaggedStorageWrapper const & ) =delete
RaggedStorageWrapper & operator=(RaggedStorageWrapper const & ) =delete
size_t size() const
bool empty() const
TimeFrameIndex getTime(size_t idx) const
TData const & getData(size_t idx) const
EntityId getEntityId(size_t idx) const
std::optional< size_t > findByEntityId(EntityId id) const
std::pair< size_t, size_t > getTimeRange(TimeFrameIndex time) const
size_t getTimeCount() const
RaggedStorageType getStorageType() const
bool isView() const
RaggedStorageCache< TData > tryGetCache() const
Try to get cached pointers for fast-path iteration.
void append(TimeFrameIndex time, TData && data, EntityId entity_id)
Append a new entry (move version).
void append(TimeFrameIndex time, TData const & data, EntityId entity_id)
Append a new entry (copy version).
void reserve(size_t capacity)
Reserve capacity for expected number of entries.
void clear()
Clear all data.
bool removeByEntityId(EntityId entity_id)
Remove entry by EntityId.
size_t removeByEntityIds(std::unordered_set< EntityId > const & entity_ids)
Remove multiple entries by EntityId in a single O(n + k) pass.
size_t removeAtTime(TimeFrameIndex time)
Remove all entries at a specific time.
TData & getMutableData(size_t idx)
Get mutable reference to data (use with caution).
std::map< TimeFrameIndex, std::pair< size_t, size_t > > const & timeRanges() const
Get the time ranges map for iteration (owning storage only).
template <typename StorageType >
StorageType *
tryGet()
Try to get underlying storage as specific type.
template <typename StorageType >
StorageType const *
tryGet() const

Detailed Description

template <typename TData >
class RaggedStorageWrapper;

Type-erased storage wrapper using virtual dispatch.

Template Parameters:

This wrapper provides a uniform interface for any storage backend while hiding the concrete storage type. Unlike RaggedStorageVariant (which uses std::variant and requires a closed set of types), this wrapper can hold any storage type including future lazy transform storage that has unbounded template parameters.

The trade-off is virtual dispatch overhead per access. However, the tryGetCache() optimization allows iterators to bypass virtual dispatch when storage is contiguous (OwningRaggedStorage), achieving zero-overhead iteration for the common case.

Design rationale (from AnalogTimeSeries::DataStorageWrapper):

  • Lazy transforms like [LazyViewStorage](/api_generated/Classes/classLazyViewStorage.md)<ViewType> cannot be stored in std::variant because ViewType is unbounded
  • Type erasure allows open extension without modifying the wrapper
  • Cache optimization mitigates virtual dispatch overhead for hot paths

Public Functions Documentation

function RaggedStorageWrapper

template <typename StorageImpl >
inline explicit RaggedStorageWrapper(
    StorageImpl storage
)

Construct wrapper from any storage implementation.

Parameters:

  • storage Storage implementation (will be moved)

Template Parameters:

  • StorageImpl Concrete storage type (must satisfy storage interface)

The storage is moved into a heap-allocated wrapper that provides virtual dispatch to the actual storage methods.

function RaggedStorageWrapper

inline RaggedStorageWrapper()

function RaggedStorageWrapper

RaggedStorageWrapper(
    RaggedStorageWrapper && 
) =default

function operator=

RaggedStorageWrapper & operator=(
    RaggedStorageWrapper && 
) =default

function RaggedStorageWrapper

RaggedStorageWrapper(
    RaggedStorageWrapper const & 
) =delete

function operator=

RaggedStorageWrapper & operator=(
    RaggedStorageWrapper const & 
) =delete

function size

inline size_t size() const

function empty

inline bool empty() const

function getTime

inline TimeFrameIndex getTime(
    size_t idx
) const

function getData

inline TData const & getData(
    size_t idx
) const

function getEntityId

inline EntityId getEntityId(
    size_t idx
) const

function findByEntityId

inline std::optional< size_t > findByEntityId(
    EntityId id
) const

function getTimeRange

inline std::pair< size_t, size_t > getTimeRange(
    TimeFrameIndex time
) const

function getTimeCount

inline size_t getTimeCount() const

function getStorageType

inline RaggedStorageType getStorageType() const

function isView

inline bool isView() const

function tryGetCache

inline RaggedStorageCache< TData > tryGetCache() const

Try to get cached pointers for fast-path iteration.

Return: RaggedStorageCache Valid if contiguous, invalid otherwise

If the underlying storage is contiguous, returns a valid cache with direct pointers for zero-overhead iteration. Otherwise, returns an invalid cache and callers must use virtual dispatch.

function append

inline void append(
    TimeFrameIndex time,
    TData && data,
    EntityId entity_id
)

Append a new entry (move version).

Parameters:

  • time The TimeFrameIndex for this entry
  • data The data to store (will be moved)
  • entity_id The EntityId for this entry

Exceptions:

  • std::runtime_error if storage is not owning

Only valid for owning storage. Throws if storage is a view.

function append

inline void append(
    TimeFrameIndex time,
    TData const & data,
    EntityId entity_id
)

Append a new entry (copy version).

Only valid for owning storage. Throws if storage is a view.

function reserve

inline void reserve(
    size_t capacity
)

Reserve capacity for expected number of entries.

Only valid for owning storage.

function clear

inline void clear()

Clear all data.

Only valid for owning storage.

function removeByEntityId

inline bool removeByEntityId(
    EntityId entity_id
)

Remove entry by EntityId.

Parameters:

Return: true if found and removed, false otherwise

Only valid for owning storage.

function removeByEntityIds

inline size_t removeByEntityIds(
    std::unordered_set< EntityId > const & entity_ids
)

Remove multiple entries by EntityId in a single O(n + k) pass.

Parameters:

  • entity_ids Set of EntityIds to remove

Return: Number of entries actually removed

Only valid for owning storage.

function removeAtTime

inline size_t removeAtTime(
    TimeFrameIndex time
)

Remove all entries at a specific time.

Parameters:

Return: Number of entries removed

Only valid for owning storage.

function getMutableData

inline TData & getMutableData(
    size_t idx
)

Get mutable reference to data (use with caution).

Parameters:

  • idx Flat index in [0, size())

Return: Mutable reference to data

Modifications through this reference do not trigger cache invalidation. Only valid for owning storage.

function timeRanges

inline std::map< TimeFrameIndex, std::pair< size_t, size_t > > const & timeRanges() const

Get the time ranges map for iteration (owning storage only).

Return: Const reference to time ranges map, or throws if not owning

function tryGet

template <typename StorageType >
inline StorageType * tryGet()

Try to get underlying storage as specific type.

Template Parameters:

  • StorageType Expected concrete storage type

Return: Pointer to underlying storage, or nullptr

Returns nullptr if the underlying storage is not the requested type. Use sparingly - prefer the virtual interface for most operations.

function tryGet

template <typename StorageType >
inline StorageType const * tryGet() const

Updated on 2026-11-13 at 20:25:40 +0000