Flecs: include/flecs/addons/cpp/utils/builder.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.1 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10namespace flecs {
11namespace _ {
12
13// Macros for template types so we don't go cross-eyed.
14#define FLECS_TBUILDER template<typename ... Components> class
15#define FLECS_IBUILDER template<typename IBase, typename ... Components> class
16
17template<FLECS_TBUILDER T, typename TDesc, typename Base, FLECS_IBUILDER IBuilder, typename ... Components>
18 struct builder : IBuilder<Base, Components ...>
19{
20 using IBase = IBuilder<Base, Components ...>;
21
22public:
23 builder(flecs::world_t *world)
24 : IBase(&desc_)
25 , desc_{}
26 , world_(world) { }
27
28 builder(const builder& f)
29 : IBase(&desc_, f.term_index_)
30 {
31 world_ = f.world_;
32 desc_ = f.desc_;
33 }
34
35 builder(builder&& f) noexcept
36 : builder<T, TDesc, Base, IBuilder, Components...>(f) { }
37
38 operator TDesc*() {
39 return &desc_;
40 }
41
42 T<Components ...> build() {
43 return T<Components...>(world_, *static_cast<Base*>(this));
44 }
45
46protected:
47 flecs::world_t* world_v() override { return world_; }
48 TDesc desc_;
49 flecs::world_t *world_;
50};
51
52#undef FLECS_TBUILDER
53#undef FLECS_IBUILDER
54
55} // namespace _
56} // namespace flecs
flecs::world_t
ecs_world_t world_t
World type.
Definition c_types.hpp:18
flecs::_
Int to enum.
Definition component.hpp:18
flecs::world
The world.
Definition world.hpp:246