Flecs v3.2
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
8#include <stdio.h>
9
10namespace flecs {
11namespace _ {
12
13 template <typename T, if_t< is_const_p<T>::value > = 0>
14 constexpr flecs::inout_kind_t type_to_inout() {
15 return flecs::In;
16 }
17
18 template <typename T, if_t< is_reference<T>::value > = 0>
19 constexpr flecs::inout_kind_t type_to_inout() {
20 return flecs::Out;
21 }
22
23 template <typename T, if_not_t<
24 is_const_p<T>::value || is_reference<T>::value > = 0>
25 constexpr flecs::inout_kind_t type_to_inout() {
26 return flecs::InOutDefault;
27 }
28
29 template <typename T, if_t< is_pointer<T>::value > = 0>
30 constexpr flecs::oper_kind_t type_to_oper() {
31 return flecs::Optional;
32 }
33
34 template <typename T, if_not_t< is_pointer<T>::value > = 0>
35 constexpr flecs::oper_kind_t type_to_oper() {
36 return flecs::And;
37 }
38
39 template <typename ... Components>
40 struct sig {
41 sig(flecs::world_t *world)
42 : m_world(world)
44 , inout ({ (type_to_inout<Components>())... })
45 , oper ({ (type_to_oper<Components>())... })
46 { }
47
48 flecs::world_t *m_world;
49 flecs::array<flecs::id_t, sizeof...(Components)> ids;
50 flecs::array<flecs::inout_kind_t, sizeof...(Components)> inout;
51 flecs::array<flecs::oper_kind_t, sizeof...(Components)> oper;
52
53 template <typename Builder>
54 void populate(const Builder& b) {
55 size_t i = 0;
56 for (auto id : ids) {
57 if (!(id & ECS_ID_FLAGS_MASK)) {
58 const flecs::type_info_t *ti = ecs_get_type_info(m_world, id);
59 if (ti) {
60 // Union relationships always return a value of type
61 // flecs::entity_t which holds the target id of the
62 // union relationship.
63 // If a union component with a non-zero size (like an
64 // enum) is added to the query signature, the each/iter
65 // functions would accept a parameter of the component
66 // type instead of flecs::entity_t, which would cause
67 // an assert.
68 ecs_assert(!ti->size || !ecs_has_id(m_world, id, flecs::Union),
69 ECS_INVALID_PARAMETER,
70 "use term() method to add union relationship");
71 }
72 }
73 b->term(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:351
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:896
ecs_size_t size
Size of type.
Definition flecs.h:897
The world.
Definition world.hpp:132