Skip to main content

CommandBuffer.ixx File

Type-erased command buffer wrapper using the Concept/Model pattern. More...

Included Headers

#include <cassert> #include <memory> #include <helios.engine.common.concepts.IsCommandBufferLike>

Namespaces Index

namespacehelios
namespaceengine

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

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacemessaging

Communication infrastructure for commands and events. More...

namespacecommand

Compile-time typed command buffering and handler routing. More...

Classes Index

classCommandBuffer

Type-erased wrapper for command buffers using the Concept/Model pattern. More...

classConcept

Internal virtual interface for type-erased dispatch. More...

classModel<T>

Typed model that adapts a concrete buffer to the Concept interface. More...

Description

Type-erased command buffer wrapper using the Concept/Model pattern.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file CommandBuffer.ixx
3 * @brief Type-erased command buffer wrapper using the Concept/Model pattern.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9
10export module helios.engine.runtime.messaging.command.CommandBuffer;
11
12import helios.engine.common.concepts.IsCommandBufferLike;
13
15
17
19
20 /**
21 * @brief Type-erased wrapper for command buffers using the Concept/Model pattern.
22 *
23 * @details CommandBuffer erases the concrete buffer type at construction time,
24 * allowing heterogeneous storage and polymorphic dispatch without requiring
25 * concrete buffers to inherit from a common base class.
26 *
27 * ## Type Erasure
28 *
29 * ```
30 * CommandBuffer (value type, owns erased Concept via unique_ptr)
31 * └── Concept (internal virtual interface)
32 * └── Model<T> (typed wrapper, owns T by value)
33 * └── T (plain class, provides flush() / clear())
34 * ```
35 *
36 * The wrapped type must satisfy `IsCommandBufferLike<T>`, which requires
37 * `flush(GameWorld&, UpdateContext&) noexcept` and `clear() noexcept`.
38 *
39 * CommandBuffer is move-only (non-copyable).
40 *
41 * @see IsCommandBufferLike
42 * @see TypedCommandBuffer
43 * @see EngineCommandBuffer
44 * @see ResourceRegistry
45 */
47
48 private:
49
50 /**
51 * @brief Internal virtual interface for type-erased dispatch.
52 */
53 class Concept {
54 public:
55 virtual ~Concept() = default;
56 virtual void flush(GameWorld& gameWorld, UpdateContext& updateContext) noexcept = 0;
57 virtual void clear() noexcept = 0;
58
59 [[nodiscard]] virtual void* underlying() noexcept = 0;
60 [[nodiscard]] virtual const void* underlying() const noexcept = 0;
61 };
62
63 /**
64 * @brief Typed model that adapts a concrete buffer to the Concept interface.
65 *
66 * @tparam T The concrete command buffer type.
67 */
68 template<typename T>
69 class Model final : public Concept {
70
71 /**
72 * @brief The owned command buffer instance.
73 */
74 T cmdBuffer_;
75
76 public:
77
78 explicit Model(T cmdBuffer) : cmdBuffer_(std::move(cmdBuffer)) {}
79
80 void flush(GameWorld& gameWorld, UpdateContext& updateContext) noexcept override {
81 cmdBuffer_.flush(gameWorld, updateContext);
82 }
83
84 void clear() noexcept override {
85 cmdBuffer_.clear();
86 }
87
88 void* underlying() noexcept override {
89 return &cmdBuffer_;
90 }
91
92 const void* underlying() const noexcept override {
93 return &cmdBuffer_;
94 }
95 };
96
97 /**
98 * @brief Owning pointer to the type-erased command buffer.
99 */
100 std::unique_ptr<Concept> pimpl_;
101
102 public:
103
104 CommandBuffer() = default;
105
106 /**
107 * @brief Constructs a CommandBuffer wrapping the given concrete buffer.
108 *
109 * @details Ownership of the buffer is transferred into a heap-allocated
110 * Model<T>. The concrete type is erased after construction.
111 *
112 * @tparam T The concrete buffer type. Must satisfy IsCommandBufferLike.
113 *
114 * @param cmdBuffer The buffer instance to wrap. Moved into the wrapper.
115 */
116 template<typename T>
117 requires IsCommandBufferLike<T>
118 explicit CommandBuffer(T cmdBuffer) : pimpl_(std::make_unique<Model<T>>(std::move(cmdBuffer))) {}
119
120 CommandBuffer(const CommandBuffer&) = delete;
122
124 CommandBuffer(CommandBuffer&&) noexcept = default;
125
126 /**
127 * @brief Executes all queued commands and clears the buffer.
128 *
129 * @details Delegates to the wrapped buffer's `flush()`. Commands are
130 * routed to their registered handler if available, otherwise executed
131 * directly.
132 *
133 * @param gameWorld The game world providing the CommandHandlerRegistry.
134 * @param updateContext The current frame's update context.
135 *
136 * @pre The CommandBuffer must be initialized (not default-constructed).
137 */
138 void flush(GameWorld& gameWorld, UpdateContext& updateContext) noexcept {
139 assert(pimpl_ && "CommandBuffer not initialized");
140 pimpl_->flush(gameWorld, updateContext);
141 }
142
143 /**
144 * @brief Discards all queued commands without executing them.
145 *
146 * @pre The CommandBuffer must be initialized.
147 */
148 void clear() noexcept {
149 assert(pimpl_ && "CommandBuffer not initialized");
150 pimpl_->clear();
151 }
152
153 /**
154 * @brief Returns a type-erased pointer to the owned buffer instance.
155 *
156 * @return Non-null void pointer to the underlying concrete buffer.
157 *
158 * @pre The CommandBuffer must be initialized.
159 */
160 [[nodiscard]] void* underlying() noexcept {
161 assert(pimpl_ && "CommandBuffer not initialized");
162 return pimpl_->underlying();
163 }
164
165 /**
166 * @copydoc underlying()
167 */
168 [[nodiscard]] const void* underlying() const noexcept {
169 assert(pimpl_ && "CommandBuffer not initialized");
170 return pimpl_->underlying();
171 }
172
173 };
174
175
176}
177

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.