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 id)
36 : term_builder_i<term>(&value)
37 , value({})
38 , world_(world_ptr) {
39 if (id & ECS_ID_FLAGS_MASK) {
40 value.id = id;
41 } else {
42 value.first.id = id;
43 }
44 this->set_term(&value);
45 }
46
47 term(flecs::world_t *world_ptr, entity_t r, entity_t o)
48 : term_builder_i<term>(&value)
49 , value({})
50 , world_(world_ptr) {
51 value.id = ecs_pair(r, o);
52 this->set_term(&value);
53 }
54
55 term(id_t id)
56 : term_builder_i<term>(&value)
57 , value({})
58 , world_(nullptr) {
59 if (id & ECS_ID_FLAGS_MASK) {
60 value.id = id;
61 } else {
62 value.first.id = id;
63 }
64 }
65
66 term(id_t r, id_t o)
67 : term_builder_i<term>(&value)
68 , value({})
69 , world_(nullptr) {
70 value.id = ecs_pair(r, o);
71 }
72
73 void reset() {
74 value = {};
75 this->set_term(nullptr);
76 }
77
78 bool is_set() {
79 return ecs_term_is_initialized(&value);
80 }
81
82 flecs::id id() {
83 return flecs::id(world_, value.id);
84 }
85
86 flecs::inout_kind_t inout() {
87 return static_cast<flecs::inout_kind_t>(value.inout);
88 }
89
90 flecs::oper_kind_t oper() {
91 return static_cast<flecs::oper_kind_t>(value.oper);
92 }
93
94 flecs::entity get_src() {
95 return flecs::entity(world_, ECS_TERM_REF_ID(&value.src));
96 }
97
98 flecs::entity get_first() {
99 return flecs::entity(world_, ECS_TERM_REF_ID(&value.first));
100 }
101
102 flecs::entity get_second() {
103 return flecs::entity(world_, ECS_TERM_REF_ID(&value.second));
104 }
105
106 operator flecs::term_t() const {
107 return value;
108 }
109
110 flecs::term_t value;
111
112protected:
113 flecs::world_t* world_v() override { return world_; }
114
115private:
116 flecs::world_t *world_;
117};
118
119// Term mixin implementation
120template <typename... Args>
121inline flecs::term world::term(Args &&... args) const {
122 return flecs::term(world_, FLECS_FWD(args)...);
123}
124
125template <typename T>
126inline flecs::term world::term() const {
127 return flecs::term(world_, _::type<T>::id(world_));
128}
129
130template <typename First, typename Second>
131inline flecs::term world::term() const {
132 return flecs::term(world_, ecs_pair(
133 _::type<First>::id(world_),
134 _::type<Second>::id(world_)));
135}
136
137}
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:722
Type that describes a term (single element in a query).
Definition flecs.h:736
ecs_term_ref_t src
Source of term.
Definition flecs.h:742
ecs_id_t id
Component id to be matched by term.
Definition flecs.h:737
int16_t oper
Operator of term.
Definition flecs.h:751
ecs_term_ref_t second
Second element of pair.
Definition flecs.h:744
int16_t inout
Access to contents matched by term.
Definition flecs.h:750
ecs_term_ref_t first
Component or first element of pair.
Definition flecs.h:743
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.