Skip to main content

engine/ecs/ComponentOpsRegistry.ixx File

Global registry mapping ComponentTypeId to ComponentOps. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespaceecs

Core Entity-Component-System architecture. More...

Classes Index

classComponentOpsRegistry

Global registry for component lifecycle function pointers. More...

Description

Global registry mapping ComponentTypeId to ComponentOps.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ComponentOpsRegistry.ixx
3 * @brief Global registry mapping ComponentTypeId to ComponentOps.
4 */
5module;
6
7#include <vector>
8
9export module helios.engine.ecs.ComponentOpsRegistry;
10
11import helios.engine.ecs.EntityHandle;
12import helios.engine.ecs.ComponentOps;
13import helios.engine.ecs.Traits;
14import helios.engine.ecs.types.ComponentTypeId;
15
16
17export namespace helios::engine::ecs {
18
19 /**
20 * @brief Global registry for component lifecycle function pointers.
21 *
22 * @details `ComponentOpsRegistry` provides O(1) lookup of `ComponentOps`
23 * by `ComponentTypeId`. It uses a type-indexed vector where the index
24 * corresponds to the component type's unique identifier.
25 *
26 * ## Usage
27 *
28 * ```cpp
29 * // Registration (done by ComponentReflector)
30 * ComponentOpsRegistry::setOps(typeId, ops);
31 *
32 * // Lookup at runtime
33 * const auto& ops = ComponentOpsRegistry::ops(typeId);
34 * if (ops.onAcquire) {
35 * ops.onAcquire(rawComponent);
36 * }
37 * ```
38 *
39 * @note Not thread-safe. All registration must complete before concurrent access.
40 *
41 * @see ComponentOps
42 * @see ComponentReflector
43 */
45
46 /**
47 * @brief Type-indexed storage for ComponentOps.
48 */
49 inline static std::vector<ComponentOps> operations_;
50
51 /**
52 * @brief Empty ops returned for unregistered types.
53 */
54 inline static constexpr ComponentOps emptyOps_{};
55
56 public:
57
58 /**
59 * @brief Registers ComponentOps for a component type.
60 *
61 * @details Auto-resizes the internal vector if necessary.
62 *
63 * @param typeId The unique identifier for the component type.
64 * @param ops The lifecycle function pointers to register.
65 */
67
68 if (typeId.value() >= operations_.size()) {
69 operations_.resize(typeId.value() + 1);
70 }
71
72 operations_[typeId.value()] = ops;
73 }
74
75 /**
76 * @brief Retrieves ComponentOps for a component type.
77 *
78 * @param typeId The unique identifier for the component type.
79 *
80 * @return Reference to the registered ComponentOps, or empty ops if not registered.
81 */
83
84 if (typeId.value() >= operations_.size()) {
85 return emptyOps_;
86 }
87
88 return operations_[typeId.value()];
89 }
90
91 };
92
93}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.