Flecs v4.0
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
impl.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include "builder_i.hpp"
9
10namespace flecs {
11
16struct term final : term_builder_i<term> {
17 term()
18 : term_builder_i<term>(&value)
19 , value({})
20 , world_(nullptr) { }
21
22 term(flecs::world_t *world_ptr)
23 : term_builder_i<term>(&value)
24 , value({})
25 , world_(world_ptr) { }
26
27 term(flecs::world_t *world_ptr, ecs_term_t t)
28 : term_builder_i<term>(&value)
29 , value({})
30 , world_(world_ptr) {
31 value = t;
32 this->set_term(&value);
33 }
34
35 term(flecs::world_t *world_ptr, id_t component_id)
36 : term_builder_i<term>(&value)
37 , value({})
38 , world_(world_ptr) {
39 if (component_id & ECS_ID_FLAGS_MASK) {
40 value.id = component_id;
41 } else {
42 value.first.id = component_id;
43 }
44 this->set_term(&value);
45 }
46
47 term(flecs::world_t *world_ptr, entity_t first, entity_t second)
48 : term_builder_i<term>(&value)
49 , value({})
50 , world_(world_ptr) {
51 value.id = ecs_pair(first, second);
52 this->set_term(&value);
53 }
54
55 term(id_t component_id)
56 : term_builder_i<term>(&value)
57 , value({})
58 , world_(nullptr) {
59 if (component_id & ECS_ID_FLAGS_MASK) {
60 value.id = component_id;
61 } else {
62 value.first.id = component_id;
63 }
64 }
65
66 term(id_t first, id_t second)
67 : term_builder_i<term>(&value)
68 , value({})
69 , world_(nullptr) {
70 value.first.id = first;
71 value.second.id = second;
72 }
73
74 void reset() {
75 value = {};
76 this->set_term(nullptr);
77 }
78
79 bool is_set() {
80 return ecs_term_is_initialized(&value);
81 }
82
83 flecs::id id() {
84 return flecs::id(world_, value.id);
85 }
86
87 flecs::inout_kind_t inout() {
88 return static_cast<flecs::inout_kind_t>(value.inout);
89 }
90
91 flecs::oper_kind_t oper() {
92 return static_cast<flecs::oper_kind_t>(value.oper);
93 }
94
95 flecs::entity get_src() {
96 return flecs::entity(world_, ECS_TERM_REF_ID(&value.src));
97 }
98
99 flecs::entity get_first() {
100 return flecs::entity(world_, ECS_TERM_REF_ID(&value.first));
101 }
102
103 flecs::entity get_second() {
104 return flecs::entity(world_, ECS_TERM_REF_ID(&value.second));
105 }
106
107 operator flecs::term_t() const {
108 return value;
109 }
110
111 flecs::term_t value;
112
113protected:
114 flecs::world_t* world_v() override { return world_; }
115
116private:
117 flecs::world_t *world_;
118};
119
120// Term mixin implementation
121template <typename... Args>
122inline flecs::term world::term(Args &&... args) const {
123 return flecs::term(world_, FLECS_FWD(args)...);
124}
125
126template <typename T>
127inline flecs::term world::term() const {
128 return flecs::term(world_, _::type<T>::id(world_));
129}
130
131template <typename First, typename Second>
132inline flecs::term world::term() const {
133 return flecs::term(world_, ecs_pair(
134 _::type<First>::id(world_),
135 _::type<Second>::id(world_)));
136}
137
138}
flecs::term term() const
Create a term for a (component) type.
bool ecs_term_is_initialized(const ecs_term_t *term)
Test whether a term is set.
ecs_entity_t id
Entity id.
Definition flecs.h:774
Type that describes a term (single element in a query).
Definition flecs.h:788
ecs_term_ref_t src
Source of term.
Definition flecs.h:794
ecs_id_t id
Component id to be matched by term.
Definition flecs.h:789
int16_t oper
Operator of term.
Definition flecs.h:803
ecs_term_ref_t second
Second element of pair.
Definition flecs.h:796
int16_t inout
Access to contents matched by term.
Definition flecs.h:802
ecs_term_ref_t first
Component or first element of pair.
Definition flecs.h:795
Entity.
Definition entity.hpp:30
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
Term builder interface.
Definition builder_i.hpp:99
Class that describes a term.
Definition impl.hpp:16
Term builder interface.