21struct term_ref_builder_i {
22 term_ref_builder_i() : term_ref_(
nullptr) { }
24 virtual ~term_ref_builder_i() { }
28 this->assert_term_ref();
29 term_ref_->id |= flecs::Self;
34 Base& id(flecs::entity_t
id) {
35 this->assert_term_ref();
48 Base& entity(flecs::entity_t entity) {
49 this->assert_term_ref();
50 term_ref_->id = entity | flecs::IsEntity;
55 Base& name(
const char *name) {
56 this->assert_term_ref();
57 term_ref_->id |= flecs::IsEntity;
58 term_ref_->name =
const_cast<char*
>(name);
63 Base& var(
const char *var_name) {
64 this->assert_term_ref();
65 term_ref_->id |= flecs::IsVariable;
66 term_ref_->name =
const_cast<char*
>(var_name);
71 Base& flags(flecs::flags32_t flags) {
72 this->assert_term_ref();
73 term_ref_->id = flags;
80 virtual flecs::world_t* world_v() = 0;
82 void assert_term_ref() {
83 ecs_assert(term_ref_ != NULL, ECS_INVALID_PARAMETER,
84 "no active term (call .with() first)");
89 return *
static_cast<Base*
>(
this);
99struct term_builder_i : term_ref_builder_i<Base> {
100 term_builder_i() : term_(
nullptr) { }
106 Base& term(id_t
id) {
113 this->term_ref_ = &term_->src;
122 this->term_ref_ = &term_->first;
130 this->term_ref_ = &term_->second;
135 Base& src(flecs::entity_t
id) {
150 Base& src(
const char *name) {
151 ecs_assert(name != NULL, ECS_INVALID_PARAMETER, NULL);
153 if (name[0] ==
'$') {
162 Base& first(flecs::entity_t
id) {
177 Base& first(
const char *name) {
178 ecs_assert(name != NULL, ECS_INVALID_PARAMETER, NULL);
180 if (name[0] ==
'$') {
189 Base& second(flecs::entity_t
id) {
204 Base& second(
const char *name) {
205 ecs_assert(name != NULL, ECS_INVALID_PARAMETER, NULL);
207 if (name[0] ==
'$') {
218 Base& up(flecs::entity_t trav = 0) {
219 this->assert_term_ref();
220 ecs_check(this->term_ref_ != &term_->first, ECS_INVALID_PARAMETER,
221 "up traversal can only be applied to term source");
222 ecs_check(this->term_ref_ != &term_->second, ECS_INVALID_PARAMETER,
223 "up traversal can only be applied to term source");
224 this->term_ref_->id |= flecs::Up;
232 template <
typename Trav>
239 Base& cascade(flecs::entity_t trav = 0) {
240 this->assert_term_ref();
242 this->term_ref_->id |= flecs::Cascade;
249 template <
typename Trav>
256 this->assert_term_ref();
257 this->term_ref_->id |= flecs::Desc;
267 Base& trav(flecs::entity_t trav, flecs::flags32_t flags = 0) {
268 this->assert_term_ref();
270 this->term_ref_->id |= flags;
284 term_->inout =
static_cast<int16_t
>(
inout);
298 term_->inout =
static_cast<int16_t
>(
inout);
299 if (term_->oper !=
EcsNot) {
300 this->src().entity(0);
328 return this->
inout(flecs::In);
333 return this->
inout(flecs::Out);
338 return this->
inout(flecs::InOut);
343 return this->
inout(flecs::InOutNone);
349 term_->oper =
static_cast<int16_t
>(
oper);
355 return this->
oper(flecs::And);
360 return this->
oper(flecs::Or);
365 return this->
oper(flecs::Not);
370 return this->
oper(flecs::Optional);
375 return this->
oper(flecs::AndFrom);
380 return this->
oper(flecs::OrFrom);
385 return this->
oper(flecs::NotFrom);
391 ecs_assert(term_->id || term_->first.id, ECS_INVALID_PARAMETER,
392 "no component specified for singleton");
394 flecs::id_t sid = term_->id;
396 sid = term_->first.id;
399 ecs_assert(sid != 0, ECS_INVALID_PARAMETER, NULL);
401 if (!ECS_IS_PAIR(sid)) {
404 term_->src.id = ecs_pair_first(this->world_v(), sid);
418 virtual flecs::world_t* world_v()
override = 0;
423 this->term_ref_ = &term_->
src;
425 this->term_ref_ =
nullptr;
431 ecs_assert(term_ != NULL, ECS_INVALID_PARAMETER,
432 "no active term (call .with() first)");
436 return *
static_cast<Base*
>(
this);