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

A wrapper around a message that provides convenient access to the message's data, type information, and the ability to mark the message as consumed. More...

#include <wrapper.hpp>

Public Member Functions

constexpr ConsumableMessageWrapper (const T &message, ConsumedMessagesRegistry<> &registry, size_t global_index) noexcept
 Constructs a ConsumableMessageWrapper.
constexpr ConsumableMessageWrapper (const ConsumableMessageWrapper &) noexcept=default
constexpr ConsumableMessageWrapper (ConsumableMessageWrapper &&) noexcept=default
constexpr ~ConsumableMessageWrapper () noexcept=default
constexpr ConsumableMessageWrapperoperator= (const ConsumableMessageWrapper &) noexcept=default
constexpr ConsumableMessageWrapperoperator= (ConsumableMessageWrapper &&) noexcept=default
constexpr const T & operator* () const noexcept
 Dereferences to the underlying message.
constexpr const T * operator-> () const noexcept
 Provides member access to the underlying message.
constexpr void Consume () const
 Marks the message as consumed.
bool IsConsumed () const noexcept
 Checks whether this message has been marked as consumed by the owning system.
constexpr std::string_view Name () const noexcept
 Gets the name of the message type.
constexpr MessageTypeIndex TypeIndex () const noexcept
 Gets the type index of the message.
constexpr size_t GlobalIndex () const noexcept
 Gets the global index of this message in the combined (previous + current) view.
constexpr const T & Unwrap () const noexcept
 Unwraps the message wrapper, returning a const reference to the underlying message.

Detailed Description

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

A wrapper around a message that provides convenient access to the message's data, type information, and the ability to mark the message as consumed.

It holds a const reference to the underlying message, a reference to the ConsumedMessagesRegistry, and the global index of the message within the combined (previous + current) view.

Marking a message as consumed writes into the per-system registry, which is later merged and applied at MessageManager::Update time.

Note
Thread-safe, except for the Consume method which is NOT thread-safe.
Template Parameters
TThe type of the message being wrapped. Must satisfy ConsumableMessageTrait.

Definition at line 29 of file wrapper.hpp.

Constructor & Destructor Documentation

◆ ConsumableMessageWrapper() [1/3]

template<ConsumableMessageTrait T>
helios::ecs::ConsumableMessageWrapper< T >::ConsumableMessageWrapper ( const T & message,
ConsumedMessagesRegistry<> & registry,
size_t global_index )
inlineconstexprnoexcept

Constructs a ConsumableMessageWrapper.

Intended to be called by ConsumableMessageReader; not part of the public construction API.

Parameters
messageConst reference to the message
registryReference to the per-system consumed messages registry
global_indexGlobal index of the message in the combined (previous + current) view

Definition at line 40 of file wrapper.hpp.

◆ ConsumableMessageWrapper() [2/3]

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

◆ ConsumableMessageWrapper() [3/3]

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

◆ ~ConsumableMessageWrapper()

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

Member Function Documentation

◆ Consume()

template<ConsumableMessageTrait T>
void helios::ecs::ConsumableMessageWrapper< T >::Consume ( ) const
inlineconstexpr

Marks the message as consumed.

The message will not be propagated to subsequent frames after MessageManager::Update merges all per-system consumed registries. Multiple calls are idempotent (sorted-unique insertion).

Definition at line 76 of file wrapper.hpp.

◆ GlobalIndex()

template<ConsumableMessageTrait T>
size_t helios::ecs::ConsumableMessageWrapper< T >::GlobalIndex ( ) const
inlinenodiscardconstexprnoexcept

Gets the global index of this message in the combined (previous + current) view.

Returns
Global index

Definition at line 110 of file wrapper.hpp.

◆ IsConsumed()

template<ConsumableMessageTrait T>
bool helios::ecs::ConsumableMessageWrapper< T >::IsConsumed ( ) const
inlinenodiscardnoexcept

Checks whether this message has been marked as consumed by the owning system.

Returns
True if the message has been consumed, false otherwise

Definition at line 85 of file wrapper.hpp.

◆ Name()

template<ConsumableMessageTrait T>
std::string_view helios::ecs::ConsumableMessageWrapper< T >::Name ( ) const
inlinenodiscardconstexprnoexcept

Gets the name of the message type.

Returns
A string view containing the name of the message type

Definition at line 93 of file wrapper.hpp.

◆ operator*()

template<ConsumableMessageTrait T>
const T & helios::ecs::ConsumableMessageWrapper< T >::operator* ( ) const
inlinenodiscardconstexprnoexcept

Dereferences to the underlying message.

Returns
A const reference to the underlying message data

Definition at line 60 of file wrapper.hpp.

◆ operator->()

template<ConsumableMessageTrait T>
const T * helios::ecs::ConsumableMessageWrapper< T >::operator-> ( ) const
inlineconstexprnoexcept

Provides member access to the underlying message.

Returns
A pointer to the underlying message data

Definition at line 68 of file wrapper.hpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ TypeIndex()

template<ConsumableMessageTrait T>
MessageTypeIndex helios::ecs::ConsumableMessageWrapper< T >::TypeIndex ( ) const
inlinenodiscardconstexprnoexcept

Gets the type index of the message.

Returns
A MessageTypeIndex representing the type index of the message

Definition at line 101 of file wrapper.hpp.

◆ Unwrap()

template<ConsumableMessageTrait T>
const T & helios::ecs::ConsumableMessageWrapper< T >::Unwrap ( ) const
inlinenodiscardconstexprnoexcept

Unwraps the message wrapper, returning a const reference to the underlying message.

Returns
A const reference to the underlying message data

Definition at line 119 of file wrapper.hpp.