Flecs: include/flecs/addons/cpp/mixins/term/impl.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| 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
5
6#pragma once
7
8#include "builder_i.hpp"
9
10namespace flecs {
11
16 struct 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>
122 inline flecs::term world::term(Args &&... args) const {
123 return flecs::term(world_, FLECS_FWD(args)...);
124}
125
126template <typename T>
127 inline flecs::term world::term() const {
128 return flecs::term(world_, _::type<T>::id(world_));
129}
130
131template <typename First, typename Second>
132 inline 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::world::term
flecs::term term() const
Create a term for a (component) type.
Definition impl.hpp:127
ecs_term_is_initialized
bool ecs_term_is_initialized(const ecs_term_t *term)
Test whether a term is set.
ecs_term_t
Type that describes a term (single element in a query).
Definition flecs.h:793
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
flecs::term
Class that describes a term.
Definition impl.hpp:16
builder_i.hpp
Term builder interface.