Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
helios::ecs::ConsumableMessageReader< T > Class Template Referencefinal

Type-safe, zero-copy reader for consumable messages with consume support. More...

#include <reader.hpp>

Inheritance diagram for helios::ecs::ConsumableMessageReader< T >:
helios::ecs::MessageReaderBase< ConsumableMessageReader< T >, T, ConsumableMessageWrapperIter< T > >

Public Types

using value_type = ConsumableMessageWrapper<T>
using size_type = MessageManager::size_type
using const_iterator = ConsumableMessageWrapperIter<T>
using iterator = const_iterator
Public Types inherited from helios::ecs::MessageReaderBase< ConsumableMessageReader< T >, T, ConsumableMessageWrapperIter< T > >
using value_type
using size_type
using iterator
using const_iterator

Public Member Functions

constexpr ConsumableMessageReader (std::span< const T > previous, std::span< const T > current, ConsumedMessagesRegistry<> &consumed_registry) noexcept
 Constructs a ConsumableMessageReader from explicit spans and a consumed registry.
constexpr ConsumableMessageReader (const MessageManager &manager, ConsumedMessagesRegistry<> &consumed_registry) noexcept
 Constructs a ConsumableMessageReader from the message manager and a per-system consumed registry.
 ConsumableMessageReader (ConsumableMessageReader &)=delete
constexpr ConsumableMessageReader (ConsumableMessageReader &&) noexcept=default
constexpr ~ConsumableMessageReader () noexcept=default
ConsumableMessageReaderoperator= (ConsumableMessageReader &)=delete
constexpr ConsumableMessageReaderoperator= (ConsumableMessageReader &&) noexcept=default
constexpr void ConsumeAll () const
 Marks all messages as consumed.
template<typename Pred>
requires std::predicate<Pred, const T&>
constexpr size_type ConsumeIf (const Pred &predicate) const
 Marks all messages matching a predicate as consumed.
constexpr auto PreviousMessages () const noexcept -> std::span< const T >
 Gets the messages from the previous frame.
constexpr auto CurrentMessages () const noexcept -> std::span< const T >
 Gets the messages from the current frame.
constexpr const_iterator begin () const noexcept
 Returns a const iterator to the first message in the combined view.
constexpr const_iterator end () const noexcept
 Returns a const iterator past the last message in the combined view.
template<typename Pred>
requires std::predicate<Pred, const T&>
constexpr auto ConsumeIf (const Pred &predicate) const -> size_type
Public Member Functions inherited from helios::ecs::MessageReaderBase< ConsumableMessageReader< T >, T, ConsumableMessageWrapperIter< T > >
constexpr MessageReaderBase () noexcept=default
constexpr ~MessageReaderBase () noexcept=default
MessageReaderBaseoperator= (const MessageReaderBase &)=delete
constexpr void ForEach (const Action &action) const
 Applies an action to every message (unwrapped const T&).
constexpr auto Collect () const -> std::vector< T >
 Collects all messages (previous + current) into a vector of raw T values.
constexpr auto CollectWith (const Alloc &alloc) const -> std::vector< T, Alloc >
 Collects all messages into a vector of raw T values using a custom allocator.
constexpr void ReadInto (OutIt out) const
 Reads all messages into an output iterator.
constexpr auto Filter (Pred predicate) const noexcept(noexcept(GetDerived().begin().Filter(std::move(predicate)))) -> utils::FilterAdapter< iterator, Pred >
 Returns a lazy filter adapter over the wrapped message sequence.
constexpr auto Map (Func transform) const noexcept(noexcept(GetDerived().begin().Map(std::move(transform)))) -> utils::MapAdapter< iterator, Func >
 Returns a lazy map adapter over the wrapped message sequence.
constexpr auto Take (size_t count) const noexcept(noexcept(GetDerived().begin().Take(count))) -> utils::TakeAdapter< iterator >
 Returns a lazy adapter yielding at most count wrappers.
constexpr auto Skip (size_t count) const noexcept(noexcept(GetDerived().begin().Skip(count))) -> utils::SkipAdapter< iterator >
 Returns a lazy adapter that skips the first count wrappers.
constexpr auto TakeWhile (Pred predicate) const noexcept(noexcept(GetDerived().begin().TakeWhile(std::move(predicate)))) -> utils::TakeWhileAdapter< iterator, Pred >
 Returns a lazy adapter that yields wrappers while predicate is true.
constexpr auto SkipWhile (Pred predicate) const noexcept(noexcept(GetDerived().begin().SkipWhile(std::move(predicate)))) -> utils::SkipWhileAdapter< iterator, Pred >
 Returns a lazy adapter that skips wrappers while predicate is true.
constexpr auto Enumerate () const noexcept(noexcept(GetDerived().begin().Enumerate())) -> utils::EnumerateAdapter< iterator >
 Returns a lazy adapter that pairs each wrapper with its zero-based index.
constexpr auto Inspect (Func inspector) const noexcept(noexcept(GetDerived().begin().Inspect(std::move(inspector)))) -> utils::InspectAdapter< iterator, Func >
 Returns a lazy adapter that calls inspector on each wrapper as a side-effect.
constexpr auto StepBy (size_t step) const noexcept(noexcept(GetDerived().begin().StepBy(step))) -> utils::StepByAdapter< iterator >
 Returns a lazy adapter that yields every step-th wrapper.
constexpr auto Chain (Iter first, Iter last) const noexcept(noexcept(GetDerived().begin().Chain(std::move(first), std::move(last)))) -> utils::ChainAdapter< iterator, Iter >
 Returns a lazy adapter that chains another range of wrappers.
constexpr auto Reverse () const noexcept(noexcept(GetDerived().begin().Reverse())) -> utils::ReverseAdapter< iterator >
 Returns a lazy adapter that yields wrappers in reverse order.
constexpr auto Slide (size_t window_size) const noexcept(noexcept(GetDerived().begin().Slide(window_size))) -> utils::SlideAdapter< iterator >
 Returns a lazy adapter that yields windows of window_size wrappers.
constexpr auto Stride (size_t stride) const noexcept(noexcept(GetDerived().begin().Stride(stride))) -> utils::StrideAdapter< iterator >
 Returns a lazy adapter that yields every stride-th wrapper.
constexpr auto Zip (Iter first, Iter last) const noexcept(noexcept(GetDerived().begin().Zip(std::move(first), std::move(last)))) -> utils::ZipAdapter< iterator, Iter >
 Returns a lazy adapter that yields pairs of wrappers from two ranges.
constexpr Acc Fold (Acc init, const Folder &folder) const
 Left-folds all messages with an accumulator.
constexpr auto Find (const Pred &predicate) const -> std::optional< value_type >
 Returns a pointer to the first message matching a predicate.
constexpr size_type CountIf (const Pred &predicate) const
 Counts messages matching a predicate.
constexpr auto Partition (const Pred &predicate) const -> std::pair< std::vector< value_type >, std::vector< value_type > >
 Partitions wrapped messages into matching and non-matching groups.
constexpr auto MaxBy (const KeyFunc &key_func) const -> std::optional< value_type >
 Finds the wrapped message with the maximum extracted key.
constexpr auto MinBy (const KeyFunc &key_func) const -> std::optional< value_type >
 Finds the wrapped message with the minimum extracted key.
constexpr auto GroupBy (const KeyFunc &key_func) const -> std::unordered_map< std::decay_t< std::invoke_result_t< KeyFunc, const value_type & > >, std::vector< value_type > >
 Groups wrapped messages by a key extracted from each wrapper.
constexpr bool Any (const Pred &predicate) const
 Checks if any message matches a predicate.
constexpr bool All (const Pred &predicate) const
 Checks if all messages match a predicate.
constexpr bool None (const Pred &predicate) const
 Checks if no messages match a predicate.
constexpr bool Empty () const noexcept
 Checks if there are no messages.
constexpr size_type Count () const noexcept
 Returns the total number of messages (previous + current).

Friends

class MessageReaderBase< ConsumableMessageReader< T >, T, ConsumableMessageWrapperIter< T > >

Detailed Description

template<ConsumableMessageTrait T>
class helios::ecs::ConsumableMessageReader< T >

Type-safe, zero-copy reader for consumable messages with consume support.

Provides a read-only view over the combined (previous + current) message queues for a specific message type. Messages are accessed via spans directly into the underlying TypedBuffer storage — no copying is performed.

Consumed messages are not filtered during iteration within the same frame. They are removed at the next MessageManager::Update call.

Note
Thread-safe, but beware that ConsumableMessageWrapper's Consume() method is NOT thread-safe.
Template Parameters
TMessage type satisfying ConsumableMessageTrait
// Wrapper iteration — with consume support
for (auto wrapper : reader) {
if ((*wrapper).priority > 5) {
wrapper.Consume();
}
}
// Lazy adapter chaining — operates on ConsumableMessageWrapper<T>
reader.Filter([](const auto& w) { return (*w).amount > 10; })
.ForEach([](const auto& w) { w.Consume(); });
// Direct span access
auto prev = reader.PreviousMessages();
auto curr = reader.CurrentMessages();

Definition at line 875 of file reader.hpp.

Member Typedef Documentation

◆ const_iterator

template<ConsumableMessageTrait T>
using helios::ecs::ConsumableMessageReader< T >::const_iterator = ConsumableMessageWrapperIter<T>

Definition at line 884 of file reader.hpp.

◆ iterator

template<ConsumableMessageTrait T>
using helios::ecs::ConsumableMessageReader< T >::iterator = const_iterator

Definition at line 885 of file reader.hpp.

◆ size_type

template<ConsumableMessageTrait T>
using helios::ecs::ConsumableMessageReader< T >::size_type = MessageManager::size_type

Definition at line 883 of file reader.hpp.

◆ value_type

template<ConsumableMessageTrait T>
using helios::ecs::ConsumableMessageReader< T >::value_type = ConsumableMessageWrapper<T>

Definition at line 882 of file reader.hpp.

Constructor & Destructor Documentation

◆ ConsumableMessageReader() [1/4]

template<ConsumableMessageTrait T>
helios::ecs::ConsumableMessageReader< T >::ConsumableMessageReader ( std::span< const T > previous,
std::span< const T > current,
ConsumedMessagesRegistry<> & consumed_registry )
inlineconstexprnoexcept

Constructs a ConsumableMessageReader from explicit spans and a consumed registry.

Parameters
previousSpan of messages from the previous frame
currentSpan of messages from the current frame
consumed_registryMutable reference to the per-system consumed messages registry

Definition at line 895 of file reader.hpp.

◆ ConsumableMessageReader() [2/4]

template<ConsumableMessageTrait T>
helios::ecs::ConsumableMessageReader< T >::ConsumableMessageReader ( const MessageManager & manager,
ConsumedMessagesRegistry<> & consumed_registry )
inlineconstexprnoexcept

Constructs a ConsumableMessageReader from the message manager and a per-system consumed registry.

Parameters
managerConst reference to the message manager
consumed_registryMutable reference to the per-system consumed messages registry

Definition at line 907 of file reader.hpp.

◆ ConsumableMessageReader() [3/4]

template<ConsumableMessageTrait T>
helios::ecs::ConsumableMessageReader< T >::ConsumableMessageReader ( ConsumableMessageReader< T > & )
delete

◆ ConsumableMessageReader() [4/4]

template<ConsumableMessageTrait T>
helios::ecs::ConsumableMessageReader< T >::ConsumableMessageReader ( ConsumableMessageReader< T > && )
constexprdefaultnoexcept

◆ ~ConsumableMessageReader()

template<ConsumableMessageTrait T>
helios::ecs::ConsumableMessageReader< T >::~ConsumableMessageReader ( )
constexprdefaultnoexcept

Member Function Documentation

◆ begin()

template<ConsumableMessageTrait T>
const_iterator helios::ecs::ConsumableMessageReader< T >::begin ( ) const
inlinenodiscardconstexprnoexcept

Returns a const iterator to the first message in the combined view.

Returns
Const iterator to the beginning

Definition at line 958 of file reader.hpp.

◆ ConsumeAll()

template<ConsumableMessageTrait T>
void helios::ecs::ConsumableMessageReader< T >::ConsumeAll ( ) const
constexpr

Marks all messages as consumed.

Definition at line 1024 of file reader.hpp.

◆ ConsumeIf() [1/2]

template<ConsumableMessageTrait T>
template<typename Pred>
requires std::predicate<Pred, const T&>
size_type helios::ecs::ConsumableMessageReader< T >::ConsumeIf ( const Pred & predicate) const
constexpr

Marks all messages matching a predicate as consumed.

Template Parameters
PredPredicate type (const T&) -> bool
Parameters
predicatePredicate function
Returns
Number of messages marked as consumed

◆ ConsumeIf() [2/2]

template<ConsumableMessageTrait T>
template<typename Pred>
requires std::predicate<Pred, const T&>
auto helios::ecs::ConsumableMessageReader< T >::ConsumeIf ( const Pred & predicate) const -> size_type
constexpr

Definition at line 1035 of file reader.hpp.

◆ CurrentMessages()

template<ConsumableMessageTrait T>
auto helios::ecs::ConsumableMessageReader< T >::CurrentMessages ( ) const -> std::span< const T >
inlinenodiscardconstexprnoexcept

Gets the messages from the current frame.

Returns
Span of const messages from the current queue

Definition at line 949 of file reader.hpp.

◆ end()

template<ConsumableMessageTrait T>
const_iterator helios::ecs::ConsumableMessageReader< T >::end ( ) const
inlinenodiscardconstexprnoexcept

Returns a const iterator past the last message in the combined view.

Returns
Const iterator to the end

Definition at line 966 of file reader.hpp.

◆ operator=() [1/2]

template<ConsumableMessageTrait T>
ConsumableMessageReader & helios::ecs::ConsumableMessageReader< T >::operator= ( ConsumableMessageReader< T > && )
constexprdefaultnoexcept

◆ operator=() [2/2]

template<ConsumableMessageTrait T>
ConsumableMessageReader & helios::ecs::ConsumableMessageReader< T >::operator= ( ConsumableMessageReader< T > & )
delete

◆ PreviousMessages()

template<ConsumableMessageTrait T>
auto helios::ecs::ConsumableMessageReader< T >::PreviousMessages ( ) const -> std::span< const T >
inlinenodiscardconstexprnoexcept

Gets the messages from the previous frame.

Returns
Span of const messages from the previous queue

Definition at line 940 of file reader.hpp.

◆ MessageReaderBase< ConsumableMessageReader< T >, T, ConsumableMessageWrapperIter< T > >

template<ConsumableMessageTrait T>
friend class MessageReaderBase< ConsumableMessageReader< T >, T, ConsumableMessageWrapperIter< T > >
friend

Definition at line 840 of file reader.hpp.