CommandHandlerRegistry Class
Registry that maps CommandType types to handler instances via function pointers. More...
Declaration
Public Member Functions Index
template <typename CommandType, typename OwningT> | |
| void | registerHandler (OwningT &owner) |
|
Registers an object as the handler for a specific command type. More... | |
template <typename... CommandType, typename OwningT> | |
| void | handleCommands (OwningT &owner) |
template <typename CommandType> | |
| bool | has () const noexcept |
|
Checks if a handler is registered for the specified command type. More... | |
template <typename CommandType> | |
| auto | tryHandler () const noexcept -> CommandHandlerRef< CommandType > |
|
Retrieves a typed reference to the registered handler. More... | |
template <typename CommandType> | |
| bool | submit (const CommandType &cmd) const noexcept |
|
Directly submits a command to its registered handler. More... | |
Private Member Attributes Index
| std::vector< CommandHandlerEntry > | entries_ |
|
Dense vector of handler entries, indexed by CommandTypeId value. More... | |
Description
Registry that maps CommandType types to handler instances via function pointers.
The CommandHandlerRegistry provides a mechanism to decouple command producers (systems) from command consumers (managers). Handlers are registered by reference, and the registry stores a type-erased "trampoline" function that allows invoking the handler's submit(const Cmd&) method without knowing the concrete handler type at the call site.
This avoids virtual inheritance (TypedCommandHandler) and allows any class with a matching submit signature to act as a handler.
Lookup is O(1) based on the CommandTypeId.
Definition at line 89 of file CommandHandlerRegistry.ixx.
Public Member Functions
handleCommands()
| inline |
Definition at line 136 of file CommandHandlerRegistry.ixx.
Reference helios::engine::runtime::registerComponents.
has()
| inline noexcept |
Checks if a handler is registered for the specified command type.
- Template Parameters
-
CommandType The command type to check.
- Returns
True if a valid handler exists.
Definition at line 148 of file CommandHandlerRegistry.ixx.
Reference helios::engine::runtime::registerComponents.
registerHandler()
| inline |
Registers an object as the handler for a specific command type.
The handler object must provide a method: bool submit(const CommandType&) noexcept. Upon registration, a static lambda (trampoline) is generated to handle type erasure and casting.
- Template Parameters
-
CommandType The command type to handle.
OwningT The concrete type of the handler object.
- Parameters
-
owner Reference to the handler instance. Must outlive the registry (usually Owned by GameWorld/ResourceRegistry).
- Precondition
No handler is currently registered for this command type.
Definition at line 114 of file CommandHandlerRegistry.ixx.
References helios::engine::runtime::registerComponents and submit.
Referenced by helios::engine::runtime::lifecycle::WorldLifecycleManager::init, helios::engine::runtime::timing::TimerManager::init and helios::engine::state::StateManager< StateType >::init.
submit()
| inline noexcept |
Directly submits a command to its registered handler.
- Template Parameters
-
CommandType The command type.
- Parameters
-
cmd The command instance.
- Returns
True if a handler was found and it returned true; false otherwise.
Definition at line 193 of file CommandHandlerRegistry.ixx.
Reference helios::engine::runtime::registerComponents.
Referenced by registerHandler.
tryHandler()
| inline noexcept |
Retrieves a typed reference to the registered handler.
- Template Parameters
-
CommandType The command type.
- Returns
A CommandHandlerRef wrapper. Can be checked for validity via operator bool().
Definition at line 167 of file CommandHandlerRegistry.ixx.
References helios::engine::runtime::messaging::command::CommandHandlerRef< CommandType >::owner and helios::engine::runtime::registerComponents.
Private Member Attributes
entries_
|
Dense vector of handler entries, indexed by CommandTypeId value.
Definition at line 94 of file CommandHandlerRegistry.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.