RaggedTimeSeries
RaggedTimeSeries
Base template class for ragged time series data structures. More…
#include <RaggedTimeSeries.hpp>
Inherits from ObserverData
Public Classes
| Name | |
|---|---|
| struct | RaggedElement Element type for flattened iteration over ragged time series. |
Public Types
| Name | |
|---|---|
| using ModificationHandle< TData > | DataModifier Type alias for modification handle. |
Public Functions
| Name | |
|---|---|
| RaggedTimeSeries() =default | |
| virtual | ~RaggedTimeSeries() =default |
| RaggedTimeSeries(RaggedTimeSeries && ) =default | |
| RaggedTimeSeries & | operator=(RaggedTimeSeries && ) =default |
| RaggedTimeSeries(RaggedTimeSeries const & ) =delete | |
| RaggedTimeSeries & | operator=(RaggedTimeSeries const & ) =delete |
| template <std::ranges::input_range R> |
RaggedTimeSeries(R && time_data_pairs) |
| RaggedTimeSeries< TData > | createFilteredCopy(std::unordered_set< EntityId > const & entity_ids) const Create a filtered copy containing only entries with specified EntityIds. |
| RaggedTimeSeries< TData > | createTimeRangeCopy(TimeFrameIndex start_time, TimeFrameIndex end_time) const Create a filtered copy containing only entries in a time range. |
| void | setTimeFrame(std::shared_ptr< TimeFrame > time_frame) Set the time frame for this data structure. |
| std::shared_ptr< TimeFrame > | getTimeFrame() const Get the current time frame. |
| ImageSize | getImageSize() const Get the image size associated with this data. |
| void | setImageSize(ImageSize const & image_size) Set the image size for this data. |
| void | setIdentityContext(std::string const & data_key, EntityRegistry * registry) Set identity context for automatic EntityId maintenance. |
| void | rebuildAllEntityIds() Rebuild EntityIds for all entries using the current identity context. |
| void | addEntryAtTime(TimeFrameIndex time, TData const & data, EntityId entity_id, NotifyObservers notify) Add a data entry at a specific time with a specific entity ID. |
| template <typename DerivedTarget > std::size_t |
copyByEntityIds(DerivedTarget & target, std::unordered_set< EntityId > const & entity_ids, NotifyObservers notify) Copy entries with specific EntityIds to another RaggedTimeSeries. |
| template <typename DerivedTarget > std::size_t |
moveByEntityIds(DerivedTarget & target, std::unordered_set< EntityId > const & entity_ids, NotifyObservers notify) Move entries with specific EntityIds to another RaggedTimeSeries. |
| template <typename DerivedTarget > std::optional< std::size_t > |
mergeOverwriteTo(DerivedTarget & target, NotifyObservers notify) const Merge all entries from this series into the target with per-time overwrite. |
| std::optional< std::reference_wrapper< TData const > > | getDataByEntityId(EntityId entity_id) const Find the data associated with a specific EntityId. |
| std::optional< TimeFrameIndex > | getTimeByEntityId(EntityId entity_id) const Find the time frame index for a specific EntityId. |
| auto | getDataByEntityIds(std::span< EntityId const > entity_ids) const Get all data that match the given EntityIds as a lazy view. |
| auto | getDataByEntityIds(std::vector< EntityId > const & entity_ids) const Get all data that match the given EntityIds (vector overload). |
| std::optional< DataModifier > | getMutableData(EntityId entity_id, NotifyObservers notify) Get a mutable handle to data by EntityId. |
| bool | clearByEntityId(EntityId entity_id, NotifyObservers notify) Clear data by its EntityId. |
| size_t | clearByEntityIds(std::unordered_set< EntityId > const & entity_ids, NotifyObservers notify) Clear multiple data entries by their EntityIds in a single pass. |
| bool | clearAtTime(TimeIndexAndFrame const & time_index_and_frame, NotifyObservers notify) Clear all data at a specific time with timeframe conversion. |
| EntityId | addAtTime(TimeFrameIndex time, TData const & data, NotifyObservers notify) Add data at a specific time (by copying). |
| EntityId | addAtTime(TimeIndexAndFrame const & time_index_and_frame, TData const & data, NotifyObservers notify) Add data at a specific time with timeframe conversion (by copying). |
| EntityId | addAtTime(TimeFrameIndex time, TData && data, NotifyObservers notify) Add data at a specific time (by moving). |
| EntityId | addAtTime(TimeIndexAndFrame const & time_index_and_frame, TData && data, NotifyObservers notify) Add data at a specific time with timeframe conversion (by moving). |
| template <typename… TDataArgs> void |
emplaceAtTime(TimeFrameIndex time, TDataArgs &&… args) Construct a data entry in-place at a specific time. |
| void | addAtTime(TimeFrameIndex time, std::vector< TData > const & data_to_add, NotifyObservers notify) Add a batch of data at a specific time by copying them. |
| void | addAtTime(TimeFrameIndex time, std::vector< TData > && data_to_add, NotifyObservers notify) Add a batch of data at a specific time by moving them. |
| std::size_t | getTimeCount() const Get the number of distinct time frames with data. |
| std::size_t | getMaxEntriesAtAnyTime() const Get the maximum number of entries at any single time frame. |
| std::size_t | getTotalEntryCount() const Get the total number of entries across all time frames. |
| auto | getTimesWithData() const Get all times with data. |
| auto | getAtTime(TimeFrameIndex time) const |
| auto | getAtTime(TimeFrameIndex time, TimeFrame const & source_timeframe) const |
| auto | getAtTime(TimeIndexAndFrame const & time_index_and_frame) const |
| auto | getEntityIdsAtTime(TimeFrameIndex time) const |
| auto | getEntityIdsAtTime(TimeFrameIndex time, TimeFrame const & source_timeframe) const |
| auto | getElementsInRange(TimeFrameInterval const & interval) const Get data entries with their associated times as a zero-copy range within a TimeFrameInterval. |
| auto | getElementsInRange(TimeFrameInterval const & interval, TimeFrame const & source_timeframe) const Get a filtered view of elements within a TimeFrameInterval with timeframe conversion. |
| auto | elements() const A flattened view of (Time, DataEntry) pairs. |
| auto | elementsView() const A flattened view of RaggedElement objects (concept-compliant). |
| auto | flattened_data() const A flattened view of (Time, EntityId, TData) tuples. |
| auto | view() const Create a view of this time series. This works for RaggedTimeSeries and any derived class (like PointData). |
| RaggedStorageCache< TData > const & | getStorageCache() const Get the storage cache for fast-path iteration. |
| bool | isStorageContiguous() const Check if storage is currently using the owning backend. |
| RaggedStorageType | getStorageType() const Get the underlying storage type. |
| bool | isLazy() const Check if storage uses lazy evaluation. |
| std::shared_ptr< RaggedTimeSeries< TData > > | materialize() const |
| template std::shared_ptr< Derived > |
createFromView(ViewType view, std::shared_ptr< TimeFrame > time_frame, ImageSize image_size =ImageSize) Create RaggedTimeSeries from a lazy view. |
| template <std::ranges::input_range ViewType> std::shared_ptr< RaggedTimeSeries< TData > > |
createFromViewWithNewIds(ViewType view, std::shared_ptr< TimeFrame > time_frame, std::string const & data_key, EntityRegistry * registry, ImageSize image_size =ImageSize) Create RaggedTimeSeries from a lazy view with new EntityIds. |
Protected Functions
| Name | |
|---|---|
| EntityKind | getEntityKind() Get the EntityKind for this data type. |
| void | _ensureOwningStorage() Materialize View/Lazy storage to owning storage in-place. |
| void | _appendPreservedEntries(std::vector< std::tuple< TimeFrameIndex, TData, EntityId > > const & entries, NotifyObservers notify) Append multiple entries preserving EntityIds with a single cache update. |
| bool | _clearAtTime(TimeFrameIndex time, NotifyObservers notify) Clear all data at a specific time (internal helper). |
| void | _updateStorageCache() const Update the cached storage pointers. |
| void | _invalidateStorageCache() const Invalidate the storage cache. |
Protected Attributes
| Name | |
|---|---|
| RaggedStorageWrapper< TData > | _storage |
| RaggedStorageCache< TData > | _cached_storage |
| ImageSize | _image_size Image size metadata. |
| std::shared_ptr< TimeFrame > | _time_frame Associated time frame for temporal indexing. |
| std::string | _identity_data_key Data key for EntityRegistry lookups. |
| EntityRegistry * | _identity_registry Pointer to EntityRegistry for automatic EntityId management. |
Additional inherited members
Public Classes inherited from ObserverData
| Name | |
|---|---|
| struct | ObserverEntry Entry in the observer map. |
Public Types inherited from ObserverData
| Name | |
|---|---|
| using std::function< void()> | ObserverCallback Type alias for observer callback functions. |
| using int | CallbackID Type alias for callback identifiers. |
Public Functions inherited from ObserverData
| Name | |
|---|---|
| ObserverData(std::string name =“UnnamedObservable”) | |
| CallbackID | addObserver(ObserverCallback callback, std::string name =“Anonymous”) Register a new observer callback. |
| void | notifyObservers() Notify all registered observers. |
| void | removeObserver(CallbackID id) Remove a previously registered observer. |
Detailed Description
template <typename TData >
class RaggedTimeSeries;Base template class for ragged time series data structures.
Template Parameters:
RaggedTimeSeries provides a unified interface for time series data where multiple unique entries can exist at each timestamp. Each entry has a unique EntityId for tracking and manipulation.
This base class manages:
- Time series storage as a map from TimeFrameIndex to vectors of DataEntry
- Image size metadata
- TimeFrame association
- Identity context (data key and EntityRegistry) for automatic EntityId management
Derived classes (LineData, MaskData, PointData) specialize the template parameter TData and provide domain-specific operations.
Public Types Documentation
using DataModifier
using RaggedTimeSeries< TData >::DataModifier = ModificationHandle<TData>;Type alias for modification handle.
This provides a unified type for RAII-style modification handles. Derived classes can use this or define their own aliases for convenience.
Public Functions Documentation
function RaggedTimeSeries
RaggedTimeSeries() =defaultfunction ~RaggedTimeSeries
virtual ~RaggedTimeSeries() =defaultfunction RaggedTimeSeries
RaggedTimeSeries(
RaggedTimeSeries &&
) =defaultfunction operator=
RaggedTimeSeries & operator=(
RaggedTimeSeries &&
) =defaultfunction RaggedTimeSeries
RaggedTimeSeries(
RaggedTimeSeries const &
) =deletefunction operator=
RaggedTimeSeries & operator=(
RaggedTimeSeries const &
) =deletefunction RaggedTimeSeries
template <std::ranges::input_range R>
inline explicit RaggedTimeSeries(
R && time_data_pairs
)function createFilteredCopy
inline RaggedTimeSeries< TData > createFilteredCopy(
std::unordered_set< EntityId > const & entity_ids
) constCreate a filtered copy containing only entries with specified EntityIds.
Parameters:
- entity_ids Set of EntityIds to include in the filtered copy
See: getDataByEntityIds() for lazy zero-copy access to filtered data
Return: New RaggedTimeSeries containing only matching entries
This creates a new RaggedTimeSeries (with owning storage) containing only the entries matching the provided EntityIds. The returned series will have new EntityIds assigned if an identity context is set, or will preserve the original EntityIds if no registry is set.
Note: This creates a copy, not a view. For zero-copy iteration, use getDataByEntityIds() instead.
function createTimeRangeCopy
inline RaggedTimeSeries< TData > createTimeRangeCopy(
TimeFrameIndex start_time,
TimeFrameIndex end_time
) constCreate a filtered copy containing only entries in a time range.
Parameters:
- start_time Start of time range (inclusive)
- end_time End of time range (inclusive)
Return: New RaggedTimeSeries containing only entries in the time range
Creates a new RaggedTimeSeries (with owning storage) containing only entries within the specified time range [start, end] (inclusive).
function setTimeFrame
inline void setTimeFrame(
std::shared_ptr< TimeFrame > time_frame
)Set the time frame for this data structure.
Parameters:
- time_frame Shared pointer to the TimeFrame to associate with this data
function getTimeFrame
inline std::shared_ptr< TimeFrame > getTimeFrame() constGet the current time frame.
Return: Shared pointer to the associated TimeFrame, or nullptr if none is set
function getImageSize
inline ImageSize getImageSize() constGet the image size associated with this data.
Return: The current ImageSize
function setImageSize
inline void setImageSize(
ImageSize const & image_size
)Set the image size for this data.
Parameters:
- image_size The ImageSize to set
function setIdentityContext
inline void setIdentityContext(
std::string const & data_key,
EntityRegistry * registry
)Set identity context for automatic EntityId maintenance.
Parameters:
- data_key String key identifying this data in the EntityRegistry
- registry Pointer to the EntityRegistry (must remain valid)
Precondition: registry != nullptr
This establishes the connection to an EntityRegistry that will manage EntityIds for all entries in this data structure.
function rebuildAllEntityIds
inline void rebuildAllEntityIds()Rebuild EntityIds for all entries using the current identity context.
Precondition: Identity context should be set via setIdentityContext before calling
This method regenerates EntityIds for all data entries across all time frames. If no identity context is set (_identity_registry is nullptr), all EntityIds are reset to EntityId(0).
The EntityKind used depends on the derived class type:
function addEntryAtTime
inline void addEntryAtTime(
TimeFrameIndex time,
TData const & data,
EntityId entity_id,
NotifyObservers notify
)Add a data entry at a specific time with a specific entity ID.
Parameters:
- time The time to add the data at
- data The data to add
- entity_id The entity ID to assign to the entry
- notify If true, observers will be notified of the change
This method is used internally for move operations to preserve entity IDs. It directly adds an entry without generating a new EntityId.
function copyByEntityIds
template <typename DerivedTarget >
inline std::size_t copyByEntityIds(
DerivedTarget & target,
std::unordered_set< EntityId > const & entity_ids,
NotifyObservers notify
)Copy entries with specific EntityIds to another RaggedTimeSeries.
Parameters:
- target The target to copy entries to
- entity_ids Set of EntityIds to copy
- notify If true, the target will notify its observers after the operation
Template Parameters:
Return: The number of entries actually copied
Copies all entries that match the given EntityIds to the target. The copied entries will get new EntityIds in the target based on the target’s identity context. Uses the copy_by_entity_ids helper function which properly handles the differences in addAtTime APIs across derived classes.
function moveByEntityIds
template <typename DerivedTarget >
inline std::size_t moveByEntityIds(
DerivedTarget & target,
std::unordered_set< EntityId > const & entity_ids,
NotifyObservers notify
)Move entries with specific EntityIds to another RaggedTimeSeries.
Parameters:
- target The target to move entries to
- entity_ids Set of EntityIds to move
- notify If true, both source and target will notify their observers after the operation
Template Parameters:
Return: The number of entries actually moved
Moves all entries that match the given EntityIds to the target. The moved entries will keep the same EntityIds in the target and be removed from source. Uses the move_by_entity_ids helper function.
function mergeOverwriteTo
template <typename DerivedTarget >
inline std::optional< std::size_t > mergeOverwriteTo(
DerivedTarget & target,
NotifyObservers notify
) constMerge all entries from this series into the target with per-time overwrite.
Parameters:
- target The target to merge into
- notify If true, the target will notify its observers after the operation
Template Parameters:
Return: Number of entries copied on success; std::nullopt on precondition violation
Precondition:
targetmust not be the same object as*this[getTimeFrame()](/api_generated/Classes/classRaggedTimeSeries.md#function-gettimeframe)andtarget.getTimeFrame()must be non-null and refer to the same[TimeFrame](/api_generated/Classes/classTimeFrame.md)object (shared_ptridentity)
Postcondition:
- For every
tin[getTimesWithData()](/api_generated/Classes/classRaggedTimeSeries.md#function-gettimeswithdata), target content attequals source content att(same data and EntityIds) - Times present only in the target are unchanged
- The source is unchanged
For every time present in the source, any existing target entries at that time are removed and replaced with the source entries. Times present only in the target are left unchanged. Source EntityIds are preserved in the target. The source is not modified.
Cross-time removal via clearByEntityIds applies only to registered EntityIds (non-sentinel). [EntityId(0)](/api_generated/Classes/structEntityId.md) is treated as anonymous and is not used for global identity cleanup.
function getDataByEntityId
inline std::optional< std::reference_wrapper< TData const > > getDataByEntityId(
EntityId entity_id
) constFind the data associated with a specific EntityId.
Parameters:
- entity_id The EntityId to look up
Return: Optional containing a const reference to the data if found, std::nullopt otherwise
This method provides reverse lookup from EntityId to the actual data, supporting group-based visualization workflows.
function getTimeByEntityId
inline std::optional< TimeFrameIndex > getTimeByEntityId(
EntityId entity_id
) constFind the time frame index for a specific EntityId.
Parameters:
- entity_id The EntityId to look up
Return: Optional containing the TimeFrameIndex if found, std::nullopt otherwise
Returns the time frame associated with the given EntityId.
function getDataByEntityIds
inline auto getDataByEntityIds(
std::span< EntityId const > entity_ids
) constGet all data that match the given EntityIds as a lazy view.
Parameters:
- entity_ids Span of EntityIds to look up
Return: A lazy view yielding (EntityId, TData const&) pairs for found entities
Note: The returned view is lazy - lookups happen during iteration. The span must remain valid for the lifetime of the view.
This method returns a lazy range that performs O(1) lookups for each EntityId on iteration. Only found entities are yielded.
function getDataByEntityIds
inline auto getDataByEntityIds(
std::vector< EntityId > const & entity_ids
) constGet all data that match the given EntityIds (vector overload).
Parameters:
- entity_ids Vector of EntityIds to look up
Return: A lazy view yielding (EntityId, TData const&) pairs for found entities
Convenience overload that accepts a vector of EntityIds.
function getMutableData
inline std::optional< DataModifier > getMutableData(
EntityId entity_id,
NotifyObservers notify
)Get a mutable handle to data by EntityId.
Parameters:
- entity_id The EntityId to look up
- notify Whether to notify observers when the handle is destroyed
Return: Optional containing a DataModifier handle if found, std::nullopt otherwise
This method returns an RAII-style handle. The handle provides pointer-like access to the underlying TData (Line2D, Mask2D, Point2D
When the handle is destroyed (goes out of scope), the observers will be automatically notified if requested.
function clearByEntityId
inline bool clearByEntityId(
EntityId entity_id,
NotifyObservers notify
)Clear data by its EntityId.
Parameters:
- entity_id The EntityId of the data to clear
- notify Whether to notify observers after the operation
Return: true if the data was found and cleared, false otherwise
Removes the data entry associated with the given EntityId from the time series. If this results in an empty time frame, the time frame is also removed.
function clearByEntityIds
inline size_t clearByEntityIds(
std::unordered_set< EntityId > const & entity_ids,
NotifyObservers notify
)Clear multiple data entries by their EntityIds in a single pass.
Parameters:
- entity_ids Set of EntityIds to remove
- notify Whether to notify observers after the operation
Return: Number of entries actually removed
Bulk removal is O(n + k) total, far more efficient than calling clearByEntityId() k times which would be O(n * k).
function clearAtTime
inline bool clearAtTime(
TimeIndexAndFrame const & time_index_and_frame,
NotifyObservers notify
)Clear all data at a specific time with timeframe conversion.
Parameters:
- time_index_and_frame The time and timeframe to clear at
- notify Whether to notify observers after the operation
Return: true if data was found and cleared, false otherwise
Removes all data entries at the specified time. If the time is from a different timeframe, it will be converted to this data’s timeframe first.
function addAtTime
inline EntityId addAtTime(
TimeFrameIndex time,
TData const & data,
NotifyObservers notify
)Add data at a specific time (by copying).
Parameters:
- time The time to add the data at
- data The data to add (will be copied)
- notify Whether to notify observers after the operation
Return: Entity id assigned to the new entry, or EntityId(0) when no identity registry is set
This overload is called when you pass an existing lvalue (e.g., a named variable). It will create a copy of the data.
function addAtTime
inline EntityId addAtTime(
TimeIndexAndFrame const & time_index_and_frame,
TData const & data,
NotifyObservers notify
)Add data at a specific time with timeframe conversion (by copying).
Parameters:
- time_index_and_frame The time and timeframe to add at
- data The data to add (will be copied)
- notify Whether to notify observers after the operation
Return: Entity id assigned to the new entry, or EntityId(0) when no identity registry is set
function addAtTime
inline EntityId addAtTime(
TimeFrameIndex time,
TData && data,
NotifyObservers notify
)Add data at a specific time (by moving).
Parameters:
- time The time to add the data at
- data The data to add (will be moved)
- notify Whether to notify observers after the operation
Return: Entity id assigned to the new entry, or EntityId(0) when no identity registry is set
This overload is called when you pass an rvalue (e.g., a temporary object or the result of std::move()). It will move the data, avoiding a copy.
function addAtTime
inline EntityId addAtTime(
TimeIndexAndFrame const & time_index_and_frame,
TData && data,
NotifyObservers notify
)Add data at a specific time with timeframe conversion (by moving).
Parameters:
- time_index_and_frame The time and timeframe to add at
- data The data to add (will be moved)
- notify Whether to notify observers after the operation
Return: Entity id assigned to the new entry, or EntityId(0) when no identity registry is set
function emplaceAtTime
template <typename... TDataArgs>
inline void emplaceAtTime(
TimeFrameIndex time,
TDataArgs &&... args
)Construct a data entry in-place at a specific time.
Parameters:
- time The time to add the data at
- args The arguments to forward to TData’s constructor
Template Parameters:
- TDataArgs The types of arguments for TData’s constructor
This method perfectly forwards its arguments to the constructor of the TData (e.g., Line2D, Mask2D, Point2D
function addAtTime
inline void addAtTime(
TimeFrameIndex time,
std::vector< TData > const & data_to_add,
NotifyObservers notify
)Add a batch of data at a specific time by copying them.
Parameters:
- time The time to add the data at
- data_to_add Vector of data to add (will be copied)
- notify Whether to notify observers after the operation
Appends the data entries to any already existing at that time.
function addAtTime
inline void addAtTime(
TimeFrameIndex time,
std::vector< TData > && data_to_add,
NotifyObservers notify
)Add a batch of data at a specific time by moving them.
Parameters:
- time The time to add the data at
- data_to_add Vector of data to add (will be moved)
- notify Whether to notify observers after the operation
Appends the data entries to any already existing at that time. The input vector will be left in a state with “empty” data entries.
function getTimeCount
inline std::size_t getTimeCount() constGet the number of distinct time frames with data.
Return: The count of time frames containing at least one entry
function getMaxEntriesAtAnyTime
inline std::size_t getMaxEntriesAtAnyTime() constGet the maximum number of entries at any single time frame.
Return: The maximum number of entries at any time, or 0 if no data exists
Scans all time frames and returns the size of the largest vector of entries. This represents the maximum “width” of the ragged array structure.
function getTotalEntryCount
inline std::size_t getTotalEntryCount() constGet the total number of entries across all time frames.
Return: The total count of all entries
Sums the number of entries at each time frame to get the total count of all data entries in this time series.
function getTimesWithData
inline auto getTimesWithData() constGet all times with data.
Return: A view of TimeFrameIndex keys
Returns a view over the keys of the data map for zero-copy iteration.
function getAtTime
inline auto getAtTime(
TimeFrameIndex time
) constfunction getAtTime
inline auto getAtTime(
TimeFrameIndex time,
TimeFrame const & source_timeframe
) constfunction getAtTime
inline auto getAtTime(
TimeIndexAndFrame const & time_index_and_frame
) constfunction getEntityIdsAtTime
inline auto getEntityIdsAtTime(
TimeFrameIndex time
) constfunction getEntityIdsAtTime
inline auto getEntityIdsAtTime(
TimeFrameIndex time,
TimeFrame const & source_timeframe
) constfunction getElementsInRange
inline auto getElementsInRange(
TimeFrameInterval const & interval
) constGet data entries with their associated times as a zero-copy range within a TimeFrameInterval.
Parameters:
- interval The TimeFrameInterval specifying the range [start, end] (inclusive)
- interval The TimeFrameInterval specifying the range [start, end] (inclusive)
Return:
- A zero-copy view of time-data entries pairs for times within the specified interval
- A zero-copy filtered view of flattened_data() for times within the interval
Returns a filtered view of time-data entries pairs for times within the specified interval [start, end] (inclusive). This method provides zero-copy access to the underlying DataEntry
Get a filtered view of elements within a TimeFrameInterval
Returns a filtered view of (Time, EntityId, TData const&) tuples for times within the specified interval [start, end] (inclusive). This method provides zero-copy access to the underlying data.
function getElementsInRange
inline auto getElementsInRange(
TimeFrameInterval const & interval,
TimeFrame const & source_timeframe
) constGet a filtered view of elements within a TimeFrameInterval with timeframe conversion.
Parameters:
- interval The TimeFrameInterval in the source timeframe specifying the range [start, end] (inclusive)
- source_timeframe The timeframe that the interval is expressed in
Return: A zero-copy filtered view of flattened_data() for times within the converted interval
Converts the time range from the source timeframe to the target timeframe (this data’s timeframe) and returns a filtered view of (Time, EntityId, TData const&) tuples for times within the converted interval range. If the timeframes are the same, no conversion is performed. This method provides zero-copy access to the underlying data.
function elements
inline auto elements() constA flattened view of (Time, DataEntry) pairs.
See: elementsView() for concept-compliant iteration with RaggedElement
This creates a zero-overhead 1D view of all entities across all times. Crucially, it preserves the TimeFrameIndex for each entity.
Returns std::pair<[TimeFrameIndex](/api_generated/Classes/structTimeFrameIndex.md), [DataEntry](/api_generated/Classes/structDataEntry.md)<TData>> for backward compatibility with existing code that uses .first, .second, and structured bindings.
Usage: for(auto [time, entry] : ts.elements()) { ... }
function elementsView
inline auto elementsView() constA flattened view of RaggedElement objects (concept-compliant).
See:
- RaggedElement
- TimeSeriesConcepts.hpp for concept definitions
Return: A lazy range view of RaggedElement objects
This creates a zero-overhead 1D view of all entities across all times. Each element satisfies the TimeSeriesElement and EntityElement concepts, enabling use with generic time series algorithms.
Use this method when you need concept-compliant elements for generic algorithms. Use elements() when you need backward-compatible pair iteration.
Usage: ```cpp
for (auto elem : ts.elementsView()) { auto t = elem.time(); // TimeFrameIndex auto id = elem.id(); // EntityId auto& data = elem.data(); // TData const& }
### function flattened_data
```cpp
inline auto flattened_data() const
A flattened view of (Time, EntityId, TData) tuples.
Deprecated:
Use elementsView() instead for concept-compliant iteration
Helper that unpacks the data for easier structured binding.
function view
auto view() constCreate a view of this time series. This works for RaggedTimeSeries and any derived class (like PointData).
function getStorageCache
inline RaggedStorageCache< TData > const & getStorageCache() constGet the storage cache for fast-path iteration.
Return: RaggedStorageCache
Returns a cache structure that provides direct pointer access to underlying data when storage is contiguous (owning). For view-based storage, returns an invalid cache.
This is useful for performance-critical code that needs to iterate over all data with minimal overhead:
auto cache = ts.getStorageCache();
if (cache.isValid()) {
// Fast path: direct pointer access
for (size_t i = 0; i < cache.cache_size; ++i) {
auto time = cache.getTime(i);
auto const& data = cache.getData(i);
// ...
}
} else {
// Slow path: use elements() view
for (auto [time, entry] : ts.elements()) {
// ...
}
}function isStorageContiguous
inline bool isStorageContiguous() constCheck if storage is currently using the owning backend.
Return: true if storage owns its data (contiguous), false if it’s a view
When storage is owning (contiguous), direct pointer access is available via getStorageCache() for zero-overhead iteration.
function getStorageType
inline RaggedStorageType getStorageType() constGet the underlying storage type.
Return: RaggedStorageType enum indicating the storage backend
function isLazy
inline bool isLazy() constCheck if storage uses lazy evaluation.
Return: true if storage is lazy (values computed on-demand), false otherwise
function materialize
inline std::shared_ptr< RaggedTimeSeries< TData > > materialize() constfunction createFromView
template <typename Derived =RaggedTimeSeries<TData>,
std::ranges::random_access_range ViewType>
static inline std::shared_ptr< Derived > createFromView(
ViewType view,
std::shared_ptr< TimeFrame > time_frame,
ImageSize image_size =ImageSize{}
)Create RaggedTimeSeries from a lazy view.
Parameters:
- view Random-access range view yielding (TimeFrameIndex, EntityId, TData) tuples
- time_frame Shared time frame (reuse from base series for efficiency)
- image_size Optional image size metadata
Template Parameters:
- Derived Concrete series type to construct (defaults to RaggedTimeSeries
) - ViewType Random-access range type
See:
- materialize() to convert lazy storage to owning storage
- flattened_data() to get a view over an existing RaggedTimeSeries
Return: std::shared_ptr
Note:
- The view must remain valid for the lifetime of the returned RaggedTimeSeries. Capture by value in lambdas or ensure base series outlives the lazy series.
- For materialized (eager) storage, call .materialize() on the result
Creates a RaggedTimeSeries that computes values on-demand from a ranges view. The view must be a random-access range that yields tuples compatible with (TimeFrameIndex, EntityId, TData) or (TimeFrameIndex, EntityId, TData const&). No intermediate data is materialized - values are computed when accessed.
This enables efficient transform pipelines without intermediate allocations:
// Skeletonization without materializing intermediate results
auto transformed_view = mask_data.flattened_data()
| std::views::transform([](auto tuple) {
auto const& [time, eid, mask_ref] = tuple;
return std::make_tuple(time, eid, skeletonize(mask_ref.get()));
});
auto lazy_skeleton = RaggedTimeSeries<Line2D>::createFromView(
transformed_view,
mask_data.getTimeFrame(),
mask_data.getImageSize()
);
// Access computes skeletonization on-demand
auto skeleton = lazy_skeleton->getData(0);function createFromViewWithNewIds
template <std::ranges::input_range ViewType>
static inline std::shared_ptr< RaggedTimeSeries< TData > > createFromViewWithNewIds(
ViewType view,
std::shared_ptr< TimeFrame > time_frame,
std::string const & data_key,
EntityRegistry * registry,
ImageSize image_size =ImageSize{}
)Create RaggedTimeSeries from a lazy view with new EntityIds.
Parameters:
- view Random-access range view yielding (TimeFrameIndex, TData) pairs
- time_frame Shared time frame
- data_key Data key for EntityRegistry
- registry EntityRegistry for generating new EntityIds
- image_size Optional image size metadata
Template Parameters:
- ViewType Random-access range type yielding (TimeFrameIndex, TData) pairs
Return: std::shared_ptr<RaggedTimeSeries
Note: This materializes the view immediately since EntityIds must be generated at construction time. For lazy evaluation, use createFromView() with pre-assigned EntityIds.
Same as createFromView(), but generates new EntityIds for each element using the provided EntityRegistry. This is useful when creating transformed data that should have distinct entity identities from the source.
Protected Functions Documentation
function getEntityKind
static inline EntityKind getEntityKind()Get the EntityKind for this data type.
Return: The EntityKind corresponding to TData
This method uses if constexpr to determine the correct EntityKind based on the TData template parameter at compile time.
function _ensureOwningStorage
inline void _ensureOwningStorage()Materialize View/Lazy storage to owning storage in-place.
Mutation operations require owning storage. If the current backend is a view or lazy storage, replaces _storage with a materialized copy.
function _appendPreservedEntries
inline void _appendPreservedEntries(
std::vector< std::tuple< TimeFrameIndex, TData, EntityId > > const & entries,
NotifyObservers notify
)Append multiple entries preserving EntityIds with a single cache update.
Parameters:
- entries Entries to append in storage order
- notify If true, observers are notified after all entries are appended
Used by moveByEntityIds to avoid per-entry cache invalidation on the target.
function _clearAtTime
inline bool _clearAtTime(
TimeFrameIndex time,
NotifyObservers notify
)Clear all data at a specific time (internal helper).
Parameters:
- time The time to clear data at
- notify Whether to notify observers after the operation
Return: true if data was found and cleared, false otherwise
This is the implementation method that directly clears data at a given time without any timeframe conversion. It’s used by the public clearAtTime method and can be used by derived classes.
function _updateStorageCache
inline void _updateStorageCache() constUpdate the cached storage pointers.
Called after any modification to the storage to update the cache. If storage is contiguous (owning), the cache will be valid. If storage is non-contiguous (view), the cache will be invalid.
function _invalidateStorageCache
inline void _invalidateStorageCache() constInvalidate the storage cache.
Called before modifications to ensure cache is refreshed after.
Protected Attributes Documentation
variable _storage
RaggedStorageWrapper< TData > _storage;Storage for time series data using type-erased wrapper Default-constructs with OwningRaggedStorage backend
variable _cached_storage
RaggedStorageCache< TData > _cached_storage;Cached pointers for fast-path iteration when storage is contiguous This cache is invalidated when storage is modified
variable _image_size
ImageSize _image_size;Image size metadata.
variable _time_frame
std::shared_ptr< TimeFrame > _time_frame {nullptr};Associated time frame for temporal indexing.
variable _identity_data_key
std::string _identity_data_key;Data key for EntityRegistry lookups.
variable _identity_registry
EntityRegistry * _identity_registry {nullptr};Pointer to EntityRegistry for automatic EntityId management.
Updated on 2026-11-13 at 20:25:40 +0000