CommandHandlerRegistry.ixx File
Registry for mapping command types to their handlers. More...
Included Headers
#include <concepts>
#include <vector>
#include <cassert>
#include <helios.engine.runtime.messaging.command.types>
#include <helios.ecs.types.ComponentTypeId>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | runtime |
| namespace | messaging |
| namespace | command |
Classes Index
| struct | CommandHandlerEntry |
|
Type-erased storage entry for a registered command handler. More... | |
| struct | CommandHandlerRef<CommandType> |
|
Typed reference wrapper for invoking a registered handler. More... | |
| class | CommandHandlerRegistry |
|
Registry that maps CommandType types to handler instances via function pointers. More... | |
Description
Registry for mapping command types to their handlers.
File Listing
The file content with the documentation metadata removed is:
17using namespace helios::engine::runtime::messaging::command::types;
20export namespace helios::engine::runtime::messaging::command {
25 struct CommandHandlerEntry {
43 struct CommandHandlerRef {
70 bool submit(const CommandType& cmd) const noexcept {
89 class CommandHandlerRegistry {
114 void registerHandler(OwningT& owner) {
115 static_assert(requires(OwningT& x, const CommandType& c) {
119 const auto idx = CommandTypeId::id<CommandType>().value();
121 if (entries_.size() <= idx) {
122 entries_.resize(idx + 1);
127 entries_[idx] = CommandHandlerEntry{
129 +[](void* owner, const void* cmd) noexcept -> bool {
130 return static_cast<OwningT*>(owner)->submit(*static_cast<const CommandType*>(cmd));
135 template<typename... CommandType, typename OwningT>
136 void handleCommands(OwningT& owner) {
137 (registerHandler<CommandType>(owner), ...);
149 const auto idx = CommandTypeId::id<CommandType>().value();
151 if (idx >= entries_.size()) {
168 const auto idx = CommandTypeId::id<CommandType>().value();
170 if (idx >= entries_.size()) {
180 return CommandHandlerRef<CommandType>{ entry.owner, entry.submitFn };
193 bool submit(const CommandType& cmd) const noexcept {
194 if (auto handler = tryHandler<CommandType>()) {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.