Skip to main content

Manager.ixx File

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

Included Headers

Namespaces Index

namespacehelios
namespaceengine
namespaceruntime
namespaceworld

Classes Index

classManager

Type-erased wrapper for game world managers. More...

classConcept

Internal virtual interface for type erasure. More...

classModel<T>

Typed wrapper that adapts a concrete manager to the Concept interface. More...

Description

Type-erased manager wrapper using the Concept/Model pattern.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cassert>
8#include <memory>
9
10export module helios.engine.runtime.world.Manager;
11
12import helios.engine.runtime.world.concepts.IsManagerLike;
13
14import helios.engine.runtime.world.UpdateContext;
15import helios.engine.runtime.messaging.command.CommandHandlerRegistry;
16
18using namespace helios::engine::runtime::world::concepts;
19export namespace helios::engine::runtime::world {
20
26 template<typename T>
27 concept HasInit = requires(T& t, CommandHandlerRegistry& commandHandlerRegistry) {
28 {t.init(commandHandlerRegistry) } -> std::same_as<void>;
29 };
30
36 template<typename T>
37 concept HasReset = requires(T& t) {
38 {t.reset() } -> std::same_as<void>;
39 };
40
41
42
63 class Manager {
64
65 private:
69 class Concept {
70 public:
71 virtual ~Concept() = default;
72 virtual void flush(UpdateContext& updateContext) noexcept = 0;
73 virtual void init(CommandHandlerRegistry& commandHandlerRegistry) noexcept = 0;
74 virtual void reset() noexcept = 0;
75
76 [[nodiscard]] virtual void* underlying() noexcept = 0;
77 [[nodiscard]] virtual const void* underlying() const noexcept = 0;
78 };
79
85 template<typename T>
86 class Model final : public Concept {
87 T manager_;
88
89 public:
90
91 explicit Model(T sys) : manager_(std::move(sys)) {}
92
93 void flush(UpdateContext& updateContext) noexcept override {
94 manager_.flush(updateContext);
95 }
96 void init(CommandHandlerRegistry& commandHandlerRegistry) noexcept override {
97 if constexpr (HasInit<T>) {
98 manager_.init(commandHandlerRegistry);
99 }
100 }
101 void reset() noexcept override {
102 if constexpr (HasReset<T>) {
103 manager_.reset();
104 }
105 }
106
107 void* underlying() noexcept override {
108 return &manager_;
109 }
110
111 const void* underlying() const noexcept override {
112 return &manager_;
113 }
114 };
115
116 std::unique_ptr<Concept> pimpl_;
117
118 public:
119
123 Manager() = default;
124
132 template<typename T>
133 requires IsManagerLike<T>
134 explicit Manager(T manager) : pimpl_(std::make_unique<Model<T>>(std::move(manager))) {}
135
136 Manager(const Manager&) = delete;
137 Manager& operator=(const Manager&) = delete;
138
139 Manager& operator=(Manager&&) = default;
141
142
155 assert(pimpl_ && "Manager not initialized");
156 pimpl_->flush(updateContext);
157 }
158
159
171 void init(CommandHandlerRegistry& commandHandlerRegistry) noexcept {
172 assert(pimpl_ && "Manager not initialized");
173 pimpl_->init(commandHandlerRegistry);
174 }
175
185 void reset() noexcept {
186 assert(pimpl_ && "Manager not initialized");
187 pimpl_->reset();
188 }
189
198 assert(pimpl_ && "Manager not initialized");
199 return pimpl_->underlying();
200 }
201
205 [[nodiscard]] const void* underlying() const noexcept {
206 assert(pimpl_ && "Manager not initialized");
207 return pimpl_->underlying();
208 }
209
210 };
211
212
213}
214

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.