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

Queue for managing multiple message types using type-erased contiguous storage. More...

#include <queue.hpp>

Public Types

using size_type = MessageStorage::size_type
using allocator_type = MessageStorage::allocator_type

Public Member Functions

constexpr MessageQueue ()=default
constexpr MessageQueue (const allocator_type &alloc)
 Constructs an MessageQueue with a custom allocator.
constexpr MessageQueue (std::pmr::memory_resource *resource)
 Constructs a MessageQueue from a PMR memory resource.
 MessageQueue (std::nullptr_t)=delete
constexpr MessageQueue (const MessageQueue &)=default
constexpr MessageQueue (MessageQueue &&) noexcept=default
constexpr ~MessageQueue ()=default
constexpr MessageQueueoperator= (const MessageQueue &)=default
constexpr MessageQueueoperator= (MessageQueue &&) noexcept=default
template<MessageTrait T>
constexpr void Register ()
 Registers an message type with the queue.
constexpr void Register (MessageTypeIndex type_index)
 Ensures storage exists for the given runtime type index.
constexpr void ClearAll () noexcept
 Clears all messages from the queue maintaining all registered types.
template<MessageTrait T>
constexpr void Clear () noexcept
 Clears messages of a specific type.
constexpr void Clear (MessageTypeIndex type_index) noexcept
 Clears messages of a specific type by runtime type index.
constexpr void ResetAll () noexcept
 Resets the queue by clearing all messages and unregistering all types.
template<MessageTrait T>
constexpr void Reset () noexcept
 Resets a specific message type by clearing its messages and unregistering the type.
template<typename OtherAllocator>
constexpr void Merge (const MessageQueue< OtherAllocator > &other)
 Merges messages from another MessageQueue into this one.
template<typename OtherAllocator>
constexpr void Merge (MessageQueue< OtherAllocator > &&other)
 Merges messages from another MessageQueue into this one.
template<MessageTrait T>
void Enqueue (T &&message)
 Enqueues an message into the queue.
template<std::ranges::input_range R>
requires MessageTrait<std::ranges::range_value_t<R>>
void EnqueueBulk (R &&messages)
 Enqueues multiple messages in bulk.
template<MessageTrait T>
void RemoveIndices (std::span< const size_type > sorted_indices)
 Removes messages at the given sorted indices for a specific message type.
void RemoveIndices (MessageTypeIndex type_index, std::span< const size_type > sorted_indices)
 Removes messages at the given sorted indices for a specific type.
constexpr void Swap (MessageQueue &other) noexcept
 Swaps the contents of this queue with another.
template<MessageTrait T>
constexpr bool IsRegistered () const noexcept
 Checks if an message type is registered.
constexpr bool IsRegistered (MessageTypeIndex type_index) const noexcept
 Checks if an message type is registered by runtime type index.
constexpr bool HasMessages () const noexcept
 Checks if any messages exist in the queue across all types.
template<MessageTrait T>
constexpr bool HasMessages () const noexcept
 Checks if messages of a specific type exist in the queue.
template<MessageTrait T>
constexpr auto Messages () const noexcept -> std::span< const T >
 Gets a const span of all messages of a specific type.
template<MessageTrait T>
constexpr auto Messages () noexcept -> std::span< T >
 Gets a mutable span of all messages of a specific type.
constexpr size_type TypeCount () const noexcept
 Gets the number of message types stored.
constexpr size_type MessageCount () const noexcept
 Gets the total number of messages stored across all types.
template<MessageTrait T>
constexpr size_type MessageCount () const noexcept
 Gets the total number of messages stored for a specific message type.
constexpr size_type MessageCount (MessageTypeIndex type_index) const noexcept
 Gets the number of messages for a type by runtime type index.

Friends

template<typename OtherAllocator>
class MessageQueue
constexpr void swap (MessageQueue &lhs, MessageQueue &rhs) noexcept
 Swaps the contents of two message queues.

Detailed Description

template<typename Allocator = std::allocator<std::byte>>
class helios::ecs::MessageQueue< Allocator >

Queue for managing multiple message types using type-erased contiguous storage.

Messages are stored in a MultiTypeBuffer, which provides per-type contiguous storage.

Note
Not thread-safe.
Template Parameters
AllocatorAllocator type for internal storage (default: std::allocator<std::byte>)

Definition at line 26 of file queue.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Allocator = std::allocator<std::byte>>
using helios::ecs::MessageQueue< Allocator >::allocator_type = MessageStorage::allocator_type

Definition at line 34 of file queue.hpp.

◆ size_type

template<typename Allocator = std::allocator<std::byte>>
using helios::ecs::MessageQueue< Allocator >::size_type = MessageStorage::size_type

Definition at line 33 of file queue.hpp.

Constructor & Destructor Documentation

◆ MessageQueue() [1/6]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::MessageQueue ( )
constexprdefault

◆ MessageQueue() [2/6]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::MessageQueue ( const allocator_type & alloc)
inlineexplicitconstexpr

Constructs an MessageQueue with a custom allocator.

Parameters
allocAllocator instance

Definition at line 42 of file queue.hpp.

◆ MessageQueue() [3/6]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::MessageQueue ( std::pmr::memory_resource * resource)
inlineexplicitconstexpr

Constructs a MessageQueue from a PMR memory resource.

Enabled only when allocator_type is constructible from std::pmr::memory_resource*.

Parameters
resourceMemory resource used to construct allocator

Definition at line 51 of file queue.hpp.

◆ MessageQueue() [4/6]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::MessageQueue ( std::nullptr_t )
delete

◆ MessageQueue() [5/6]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::MessageQueue ( const MessageQueue< Allocator > & )
constexprdefault

◆ MessageQueue() [6/6]

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::MessageQueue ( MessageQueue< Allocator > && )
constexprdefaultnoexcept

◆ ~MessageQueue()

template<typename Allocator = std::allocator<std::byte>>
helios::ecs::MessageQueue< Allocator >::~MessageQueue ( )
constexprdefault

Member Function Documentation

◆ Clear() [1/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
void helios::ecs::MessageQueue< Allocator >::Clear ( )
inlineconstexprnoexcept

Clears messages of a specific type.

Template Parameters
TMessage type

Definition at line 93 of file queue.hpp.

◆ Clear() [2/2]

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::MessageQueue< Allocator >::Clear ( MessageTypeIndex type_index)
inlineconstexprnoexcept

Clears messages of a specific type by runtime type index.

Parameters
type_indexType index of messages to clear

Definition at line 101 of file queue.hpp.

◆ ClearAll()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::MessageQueue< Allocator >::ClearAll ( )
inlineconstexprnoexcept

Clears all messages from the queue maintaining all registered types.

Definition at line 86 of file queue.hpp.

◆ Enqueue()

template<typename Allocator>
template<MessageTrait T>
void helios::ecs::MessageQueue< Allocator >::Enqueue ( T && message)
inline

Enqueues an message into the queue.

Warning
Triggers assertion if message type is not registered.
Template Parameters
TMessage type
Parameters
messageMessage to enqueue

Definition at line 312 of file queue.hpp.

◆ EnqueueBulk()

template<typename Allocator>
requires MessageTrait<std::ranges::range_value_t<R>>
template<std::ranges::input_range R>
requires MessageTrait<std::ranges::range_value_t<R>>
void helios::ecs::MessageQueue< Allocator >::EnqueueBulk ( R && messages)
inline

Enqueues multiple messages in bulk.

Warning
Triggers assertion if message type is not registered.
Template Parameters
RRange type
Parameters
messagesRange of messages to enqueue

Definition at line 323 of file queue.hpp.

◆ HasMessages() [1/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
bool helios::ecs::MessageQueue< Allocator >::HasMessages ( ) const
inlinenodiscardconstexprnoexcept

Checks if messages of a specific type exist in the queue.

Template Parameters
TMessage type
Returns
True if messages of type T exist, false otherwise or if the type is not registered

Definition at line 238 of file queue.hpp.

◆ HasMessages() [2/2]

template<typename Allocator = std::allocator<std::byte>>
bool helios::ecs::MessageQueue< Allocator >::HasMessages ( ) const
inlinenodiscardconstexprnoexcept

Checks if any messages exist in the queue across all types.

Returns
True if at least one message exists, false otherwise

Definition at line 227 of file queue.hpp.

◆ IsRegistered() [1/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
bool helios::ecs::MessageQueue< Allocator >::IsRegistered ( ) const
inlinenodiscardconstexprnoexcept

Checks if an message type is registered.

Template Parameters
TMessage type
Returns
True if the message type is registered, false otherwise

Definition at line 209 of file queue.hpp.

◆ IsRegistered() [2/2]

template<typename Allocator = std::allocator<std::byte>>
bool helios::ecs::MessageQueue< Allocator >::IsRegistered ( MessageTypeIndex type_index) const
inlinenodiscardconstexprnoexcept

Checks if an message type is registered by runtime type index.

Parameters
type_indexType index to check
Returns
True if the message type is registered, false otherwise

Definition at line 218 of file queue.hpp.

◆ Merge() [1/2]

template<typename Allocator = std::allocator<std::byte>>
template<typename OtherAllocator>
void helios::ecs::MessageQueue< Allocator >::Merge ( const MessageQueue< OtherAllocator > & other)
inlineconstexpr

Merges messages from another MessageQueue into this one.

For each type in other, messages are appended to the corresponding storage in this queue. After merging, other is left in a valid but empty state.

Template Parameters
OtherAllocatorAllocator template of the other queue
Parameters
otherMessageQueue to merge from

Definition at line 128 of file queue.hpp.

◆ Merge() [2/2]

template<typename Allocator = std::allocator<std::byte>>
template<typename OtherAllocator>
void helios::ecs::MessageQueue< Allocator >::Merge ( MessageQueue< OtherAllocator > && other)
inlineconstexpr

Merges messages from another MessageQueue into this one.

Rvalue overload that consumes the source queue.

Template Parameters
OtherAllocatorAllocator template of the other queue
Parameters
otherMessageQueue to merge from

Definition at line 139 of file queue.hpp.

◆ MessageCount() [1/3]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
size_type helios::ecs::MessageQueue< Allocator >::MessageCount ( ) const
inlinenodiscardconstexprnoexcept

Gets the total number of messages stored for a specific message type.

Template Parameters
TMessage type
Returns
Total message count or 0 if the type is not registered

Definition at line 289 of file queue.hpp.

◆ MessageCount() [2/3]

template<typename Allocator = std::allocator<std::byte>>
size_type helios::ecs::MessageQueue< Allocator >::MessageCount ( ) const
inlinenodiscardconstexprnoexcept

Gets the total number of messages stored across all types.

Returns
Total message count or 0 if no types are registered

Definition at line 278 of file queue.hpp.

◆ MessageCount() [3/3]

template<typename Allocator = std::allocator<std::byte>>
size_type helios::ecs::MessageQueue< Allocator >::MessageCount ( MessageTypeIndex type_index) const
inlinenodiscardconstexprnoexcept

Gets the number of messages for a type by runtime type index.

Parameters
type_indexType index to query
Returns
Number of messages, or 0 if the type is not registered

Definition at line 298 of file queue.hpp.

◆ Messages() [1/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
auto helios::ecs::MessageQueue< Allocator >::Messages ( ) const -> std::span< const T >
inlinenodiscardconstexprnoexcept

Gets a const span of all messages of a specific type.

Template Parameters
TMessage type
Returns
Span of const messages, or empty span if type is not registered or has no messages

Definition at line 249 of file queue.hpp.

◆ Messages() [2/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
auto helios::ecs::MessageQueue< Allocator >::Messages ( ) -> std::span< T >
inlinenodiscardconstexprnoexcept

Gets a mutable span of all messages of a specific type.

Template Parameters
TMessage type
Returns
Span of messages, or empty span if type is not registered or has no messages

Definition at line 261 of file queue.hpp.

◆ operator=() [1/2]

template<typename Allocator = std::allocator<std::byte>>
MessageQueue & helios::ecs::MessageQueue< Allocator >::operator= ( const MessageQueue< Allocator > & )
constexprdefault

◆ operator=() [2/2]

template<typename Allocator = std::allocator<std::byte>>
MessageQueue & helios::ecs::MessageQueue< Allocator >::operator= ( MessageQueue< Allocator > && )
constexprdefaultnoexcept

◆ Register() [1/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
void helios::ecs::MessageQueue< Allocator >::Register ( )
inlineconstexpr

Registers an message type with the queue.

Template Parameters
TMessage type

Definition at line 69 of file queue.hpp.

◆ Register() [2/2]

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::MessageQueue< Allocator >::Register ( MessageTypeIndex type_index)
inlineconstexpr

Ensures storage exists for the given runtime type index.

Used when the concrete type is not available at call-site (e.g., during Update re-registration). If the type index is already registered, this is a no-op.

Parameters
type_indexRuntime type index

Definition at line 80 of file queue.hpp.

◆ RemoveIndices() [1/2]

template<typename Allocator>
void helios::ecs::MessageQueue< Allocator >::RemoveIndices ( MessageTypeIndex type_index,
std::span< const size_type > sorted_indices )
inline

Removes messages at the given sorted indices for a specific type.

Erases messages at the provided sorted, deduplicated indices from back to front to avoid index invalidation. No additional allocation is performed.

Warning
Triggers assertion if type_index is not registered.
Parameters
type_indexType index of the message type
sorted_indicesSpan of sorted, unique global indices to remove

Definition at line 331 of file queue.hpp.

◆ RemoveIndices() [2/2]

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
void helios::ecs::MessageQueue< Allocator >::RemoveIndices ( std::span< const size_type > sorted_indices)
inline

Removes messages at the given sorted indices for a specific message type.

Warning
Triggers assertion if message type is not registered.
Template Parameters
TMessage type
Parameters
sorted_indicesSpan of sorted, unique global indices to remove

Definition at line 170 of file queue.hpp.

◆ Reset()

template<typename Allocator = std::allocator<std::byte>>
template<MessageTrait T>
void helios::ecs::MessageQueue< Allocator >::Reset ( )
inlineconstexprnoexcept

Resets a specific message type by clearing its messages and unregistering the type.

Template Parameters
TMessage type

Definition at line 115 of file queue.hpp.

◆ ResetAll()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::MessageQueue< Allocator >::ResetAll ( )
inlineconstexprnoexcept

Resets the queue by clearing all messages and unregistering all types.

Definition at line 107 of file queue.hpp.

◆ Swap()

template<typename Allocator = std::allocator<std::byte>>
void helios::ecs::MessageQueue< Allocator >::Swap ( MessageQueue< Allocator > & other)
inlineconstexprnoexcept

Swaps the contents of this queue with another.

Parameters
otherAnother MessageQueue to swap with

Definition at line 190 of file queue.hpp.

◆ TypeCount()

template<typename Allocator = std::allocator<std::byte>>
size_type helios::ecs::MessageQueue< Allocator >::TypeCount ( ) const
inlinenodiscardconstexprnoexcept

Gets the number of message types stored.

Returns
Number of distinct message types

Definition at line 270 of file queue.hpp.

◆ MessageQueue

template<typename Allocator = std::allocator<std::byte>>
template<typename OtherAllocator>
friend class MessageQueue
friend

Definition at line 305 of file queue.hpp.

◆ swap

template<typename Allocator = std::allocator<std::byte>>
void swap ( MessageQueue< Allocator > & lhs,
MessageQueue< Allocator > & rhs )
friend

Swaps the contents of two message queues.

Parameters
lhsFirst MessageQueue
rhsSecond MessageQueue

Definition at line 199 of file queue.hpp.