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
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::InOut;
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 : world_(world)
44 , inout ({ (type_to_inout<Components>())... })
45 , oper ({ (type_to_oper<Components>())... })
46 { }
47
48 flecs::world_t *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(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.
69 !ti->size || !ecs_has_id(world_, id, flecs::Union),
70 ECS_INVALID_PARAMETER,
71 "use with() method to add union relationship");
72 }
73 }
74
75 b->with(id).inout(inout[i]).oper(oper[i]);
76 i ++;
77 }
78 }
79 };
80
81} // namespace _
82} // namespace flecs
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:352
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:916
ecs_size_t size
Size of type.
Definition flecs.h:917
The world.
Definition world.hpp:137