Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
signature.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9namespace _ {
10
11 template <typename T, if_t< is_const_p<T>::value > = 0>
12 constexpr flecs::inout_kind_t type_to_inout() {
13 return flecs::In;
14 }
15
16 template <typename T, if_t< is_reference<T>::value > = 0>
17 constexpr flecs::inout_kind_t type_to_inout() {
18 return flecs::InOut;
19 }
20
21 template <typename T, if_not_t<
22 is_const_p<T>::value || is_reference<T>::value > = 0>
23 constexpr flecs::inout_kind_t type_to_inout() {
24 return flecs::InOutDefault;
25 }
26
27 template <typename T, if_t< is_pointer<T>::value > = 0>
28 constexpr flecs::oper_kind_t type_to_oper() {
29 return flecs::Optional;
30 }
31
32 template <typename T, if_not_t< is_pointer<T>::value > = 0>
33 constexpr flecs::oper_kind_t type_to_oper() {
34 return flecs::And;
35 }
36
37 template <typename ... Components>
38 struct sig {
39 sig(flecs::world_t *world)
40 : world_(world)
42 , inout ({ (type_to_inout<Components>())... })
43 , oper ({ (type_to_oper<Components>())... })
44 { }
45
46 flecs::world_t *world_;
47 flecs::array<flecs::id_t, sizeof...(Components)> ids;
48 flecs::array<flecs::inout_kind_t, sizeof...(Components)> inout;
49 flecs::array<flecs::oper_kind_t, sizeof...(Components)> oper;
50
51 template <typename Builder>
52 void populate(const Builder& b) {
53 size_t i = 0;
54 for (auto id : ids) {
55 if (!(id & ECS_ID_FLAGS_MASK)) {
56 const flecs::type_info_t *ti = ecs_get_type_info(world_, id);
57 if (ti) {
58 // Union relationships always return a value of type
59 // flecs::entity_t which holds the target id of the
60 // union relationship.
61 // If a union component with a non-zero size (like an
62 // enum) is added to the query signature, the each/iter
63 // functions would accept a parameter of the component
64 // type instead of flecs::entity_t, which would cause
65 // an assert.
67 !ti->size || !ecs_has_id(world_, id, flecs::Union),
68 ECS_INVALID_PARAMETER,
69 "use with() method to add union relationship");
70 }
71 }
72
73 b->with(id).inout(inout[i]).oper(oper[i]);
74 i ++;
75 }
76 }
77 };
78
79} // namespace _
80} // namespace flecs
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t id)
Get the type for an id.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Test if an entity has an id.
Type that contains component information (passed to ctors/dtors/...)
Definition flecs.h:989
ecs_size_t size
Size of type.
Definition flecs.h:990
The world.
Definition world.hpp:137