48 : flecs::
id( nullptr,
id ) { }
71 explicit operator bool()
const {
129 template <
typename Parent>
172 template <
typename Func>
173 void each(
const Func& func)
const;
186 template <
typename Func>
199 template <
typename Func>
212 template <
typename First,
typename Func>
213 void each(
const Func& func)
const {
227 template <
typename Func>
232 if (
id_ == flecs::Wildcard ||
id_ == flecs::Any) {
255 template <
typename Rel,
typename Func>
271 template <
typename Func>
273 children(flecs::ChildOf, FLECS_MOV(func));
285 template <typename T, if_t< is_actual<T>::value > = 0>
289 "operation invalid for empty type");
301 template <
typename T,
typename A = actual_type_t<T>,
302 if_t< flecs::is_pair<T>::value > = 0>
306 "operation invalid for empty type");
317 template <
typename First,
typename Second,
typename P = pair<First, Second>,
318 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
320 return this->try_get<P>();
330 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
334 "operation invalid for empty type");
335 return static_cast<const First*
>(
346 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
348 const auto& et = enum_type<Second>(this->
world_);
350 return try_get<First>(
target);
381 template<
typename... Ts>
383 flecs_static_assert(
sizeof...(Ts) > 1,
"try_get_n requires at least two components");
384 flecs_static_assert(
sizeof...(Ts) < 9,
"try_get_n cannot fetch more than eight components");
385 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_const_ptr {try_get<Ts>()...};
396 template<
typename Second>
404 "operation invalid for empty type");
405 return static_cast<const Second*
>(
406 ecs_get_id(world_, id_, ecs_pair(first, second)));
417 template<
typename First,
typename Second>
419 return try_get<pair_object<First, Second>>();
431 template <typename T, if_t< is_actual<T>::value > = 0>
433 const T *r = try_get<T>();
435 "invalid get: entity does not have component '%s' (use try_get)",
436 flecs::_::type_name<T>());
448 template <
typename T,
typename A = actual_type_t<T>,
449 if_t< flecs::is_pair<T>::value > = 0>
451 const A *r = try_get<T>();
453 "invalid get: entity does not have component '%s' (use try_get)",
454 flecs::_::type_name<T>());
466 template <
typename First,
typename Second,
typename P = pair<First, Second>,
467 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
469 return this->get<P>();
480 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
481 const First&
get(Second second)
const {
482 const First *r = try_get<First>(second);
484 "invalid get: entity does not have pair (use try_get)");
496 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
498 const auto& et = enum_type<Second>(this->world_);
500 return get<First>(target);
510 const void *r =
ecs_get_id(world_, id_, comp);
512 "invalid get: entity does not have component (use try_get)");
527 const void *r =
ecs_get_id(world_, id_, ecs_pair(first, second));
529 "invalid get: entity does not have pair (use try_get)");
567 template <typename Func, if_t< is_callable<Func>::value > = 0>
568 bool get(
const Func& func)
const;
575 template<
typename... Ts>
577 flecs_static_assert(
sizeof...(Ts) > 1,
"get_n requires at least two components");
578 flecs_static_assert(
sizeof...(Ts) < 9,
"get_n cannot fetch more than eight components");
579 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_const {get<Ts>()...};
591 template<
typename Second>
593 const Second *r = try_get_second<Second>(first);
595 "invalid get_second: entity does not have pair (use try_get_second)");
608 template<
typename First,
typename Second>
610 const Second *r = try_get<First, Second>();
612 "invalid get_second: entity does not have pair (use try_get_second)");
625 template <typename T, if_t< is_actual<T>::value > = 0>
629 "operation invalid for empty type");
641 template <
typename T,
typename A = actual_type_t<T>,
642 if_t< flecs::is_pair<T>::value > = 0>
646 "operation invalid for empty type");
657 template <
typename First,
typename Second,
typename P = pair<First, Second>,
658 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
660 return this->try_get_mut<P>();
670 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
674 "operation invalid for empty type");
675 return static_cast<First*
>(
686 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
688 const auto& et = enum_type<Second>(this->world_);
690 return try_get_mut<First>(target);
721 template<
typename... Ts>
723 flecs_static_assert(
sizeof...(Ts) > 1,
"try_get_mut_n requires at least two components");
724 flecs_static_assert(
sizeof...(Ts) < 9,
"try_get_mut_n cannot fetch more than eight components");
725 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_ptr {try_get_mut<Ts>()...};
736 template<
typename Second>
744 "operation invalid for empty type");
745 return static_cast<Second*
>(
757 template<
typename First,
typename Second>
759 return try_get_mut<pair_object<First, Second>>();
771 template <typename T, if_t< is_actual<T>::value > = 0>
773 T* r = try_get_mut<T>();
775 "invalid get_mut: entity does not have component (use try_get_mut)");
787 template <
typename T,
typename A = actual_type_t<T>,
788 if_t< flecs::is_pair<T>::value > = 0>
790 A* r = try_get_mut<T>();
792 "invalid get_mut: entity does not have component (use try_get_mut)");
804 template <
typename First,
typename Second,
typename P = pair<First, Second>,
805 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
807 A* r = try_get_mut<First, Second>();
809 "invalid get_mut: entity does not have pair (use try_get_mut)");
821 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
823 First* r = try_get_mut<First>(second);
825 "invalid get_mut: entity does not have pair (use try_get_mut)");
837 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
839 const auto& et = enum_type<Second>(this->world_);
841 return get_mut<First>(target);
853 "invalid get_mut: entity does not have component (use try_get_mut)");
870 "invalid get_mut: entity does not have pair (use try_get_mut)");
879 template<
typename... Ts>
881 flecs_static_assert(
sizeof...(Ts) > 1,
"get_mut_n requires at least two components");
882 flecs_static_assert(
sizeof...(Ts) < 9,
"get_mut_n cannot fetch more than eight components");
883 return typename tuple_builder<
sizeof...(Ts), Ts...>::type {get_mut<Ts>()...};
895 template<
typename Second>
897 Second *r = try_get_mut_second<Second>(first);
899 "invalid get_mut_second: entity does not have pair (use try_get_mut_second)");
912 template<
typename First,
typename Second>
914 Second *r = try_get_mut_second<First, Second>();
916 "invalid get_mut_second: entity does not have pair (use try_get_mut_second)");
925 template<
typename Enum>
926 Enum get_constant()
const;
937 template<
typename First>
978 template <
typename T>
988 template <
typename First,
typename Second>
1005 template<
typename Rel>
1025 flecs::entity lookup(
const char *path,
bool search_path =
false)
const;
1041 template <
typename T>
1049 if (is_enum<T>::value) {
1050 return ecs_has_pair(world_, id_, cid, flecs::Wildcard);
1062 template <typename E, if_t< is_enum<E>::value > = 0>
1065 auto o = enum_type<E>(world_).entity(value);
1067 "Constant was not found in Enum reflection data."
1068 " Did you mean to use has<E>() instead of has(E)?");
1078 template <
typename First,
typename Second>
1089 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
1090 bool has(Second second)
const {
1092 return ecs_has_id(world_, id_, ecs_pair(comp_id, second));
1101 template <
typename Second>
1112 template<typename First, typename E, if_t< is_enum<E>::value && !std::is_same<First, E>::value > = 0>
1114 const auto& et = enum_type<E>(this->world_);
1116 return has<First>(second);
1126 return ecs_has_id(world_, id_, ecs_pair(first, second));
1145 template <
typename First>
1148 return owns(ecs_pair(comp_id, second));
1158 return owns(ecs_pair(first, second));
1167 template <
typename T>
1179 template <
typename First,
typename Second>
1192 template <
typename Second>
1211 template<
typename T>
1223 return this->enabled(ecs_pair(first, second));
1232 template <
typename First>
1243 template <
typename First,
typename Second>
component< T > & constant(const char *name, T value)
Add a constant.
Utilities to fetch components as tuples from entities.
#define ecs_assert(condition, error_code,...)
Assert.
#define ECS_INVALID_OPERATION
Invalid operation error code.
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
const ecs_type_info_t * ecs_get_type_info(const ecs_world_t *world, ecs_id_t component)
Get the type info for a component.
ecs_entity_t entity_t
Entity type.
ecs_world_t world_t
World type.
bool ecs_children_next(ecs_iter_t *it)
Progress an iterator created with ecs_children().
ecs_iter_t ecs_children_w_rel(const ecs_world_t *world, ecs_entity_t relationship, ecs_entity_t parent)
Same as ecs_children(), but with a custom relationship argument.
bool ecs_is_enabled_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if a component is enabled.
bool ecs_owns_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity owns a component.
int32_t ecs_get_depth(const ecs_world_t *world, ecs_entity_t entity, ecs_entity_t rel)
Return the depth for an entity in the tree for the specified relationship.
bool ecs_has_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Test if an entity has a component.
#define ecs_has_pair(world, entity, first, second)
Test if an entity has a pair.
const void * ecs_get_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Get an immutable pointer to a component.
void * ecs_get_mut_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Get a mutable pointer to a component.
bool ecs_is_valid(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is valid.
bool ecs_is_alive(const ecs_world_t *world, ecs_entity_t e)
Test whether an entity is alive.
char * ecs_get_path_w_sep(const ecs_world_t *world, ecs_entity_t parent, ecs_entity_t child, const char *sep, const char *prefix)
Get a path identifier for an entity.
const char * ecs_get_symbol(const ecs_world_t *world, ecs_entity_t entity)
Get the symbol of an entity.
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
const ecs_world_t * ecs_get_world(const ecs_poly_t *poly)
Get the world from a poly.
Component added to enum type entities.
bool owns_second(flecs::entity_t first) const
Check if entity owns the provided pair.
flecs::type type() const
Get the entity's type.
auto try_get_n() const
Get multiple component values as a tuple of const pointers.
entity_view(entity_t id)
Implicit conversion from flecs::entity_t to flecs::entity_view.
int32_t depth(flecs::entity_t rel) const
Get the depth for a given relationship.
bool enabled() const
Test if pair is enabled.
const Second * try_get_second(flecs::entity_t first) const
Get the second part for a pair.
bool has(flecs::id_t first, flecs::id_t second) const
Check if entity has the provided pair.
First & get_mut(Second constant) const
Get a mutable pair.
T & get_mut() const
Get mutable component value.
A & get_mut() const
Get mutable component value.
flecs::string_view name() const
Return the entity name.
bool owns(flecs::id_t second) const
Check if entity owns the provided pair.
const A * try_get() const
Get a pair.
bool is_valid() const
Check if entity is valid.
flecs::string path(const char *sep="::", const char *init_sep="::") const
Return the entity path.
const void * try_get(flecs::entity_t first, flecs::entity_t second) const
Get a pair (untyped).
flecs::string_view symbol() const
Return the entity symbol.
void each(const Func &func) const
Iterate targets for a given relationship.
A & get_mut() const
Get a mutable pair.
flecs::table_range range() const
Get table range for the entity.
void * get_mut(flecs::entity_t first, flecs::entity_t second) const
Get a mutable pair (untyped).
const Second & get_second(flecs::entity_t first) const
Get the second part for a pair.
const Second & get_second() const
Get the second part for a pair.
bool owns() const
Check if entity owns the provided pair.
const T & get() const
Get component value.
bool has(E value) const
Check if entity has the provided pair.
int32_t depth() const
Get the depth for a given relationship.
entity_view(flecs::world_t *world, flecs::id_t id)
Wrap an existing entity ID.
bool enabled(flecs::id_t id) const
Test if ID is enabled.
bool has_second(flecs::entity_t first) const
Check if entity has the provided pair.
const First * try_get(Second constant) const
Get a pair.
Second & get_mut_second() const
Get the second part for a pair.
Second * try_get_mut_second(flecs::entity_t first) const
Get the second part for a pair.
const First & get(Second second) const
Get a pair.
void children(Func &&func) const
Iterate children for an entity.
const void * try_get(flecs::id_t comp) const
Get component value (untyped).
bool owns(flecs::id_t e) const
Check if entity owns the provided entity.
Second & get_mut_second(flecs::entity_t first) const
Get the second part for a pair.
const First & get(Second constant) const
Get a pair.
flecs::table table() const
Get the entity's table.
flecs::string path_from(flecs::entity_t parent, const char *sep="::", const char *init_sep="::") const
Return the entity path relative to a parent.
bool enabled(flecs::id_t second) const
Test if pair is enabled.
bool has(Second second) const
Check if entity has the provided pair.
A * try_get_mut() const
Get mutable component value.
bool has(flecs::id_t e) const
Check if entity has the provided entity.
bool owns() const
Check if entity owns the provided component.
bool enabled() const
Check if entity is enabled (does not have the Disabled tag).
flecs::entity parent() const
Get parent of entity.
entity_view()
Default constructor.
const First * try_get(Second second) const
Get a pair.
void * get_mut(flecs::id_t comp) const
Get mutable component value (untyped).
A * try_get_mut() const
Get a mutable pair.
void each(const Func &func) const
Iterate (component) IDs of an entity.
const void * get(flecs::entity_t first, flecs::entity_t second) const
Get a pair (untyped).
bool is_alive() const
Check if entity is alive.
const A & get() const
Get a pair.
bool has() const
Check if entity has the provided component.
T * try_get_mut() const
Get mutable component value.
bool owns(flecs::id_t first, flecs::id_t second) const
Check if entity owns the provided pair.
void * try_get_mut(flecs::id_t comp) const
Get mutable component value (untyped).
void children(Func &&func) const
Iterate children for an entity.
const A & get() const
Get component value.
auto get_n() const
Get multiple component values as a tuple of const references.
First & get_mut(Second second) const
Get a mutable pair.
Second * try_get_mut_second() const
Get the second part for a pair.
void * try_get_mut(flecs::entity_t first, flecs::entity_t second) const
Get a mutable pair (untyped).
First * try_get_mut(Second second) const
Get a mutable pair.
entity_t id() const
Get entity ID.
flecs::entity target(int32_t index=0) const
Get target for a given pair.
const T * try_get() const
Get component value.
const void * get(flecs::id_t comp) const
Get component value (untyped).
bool has() const
Check if entity has the provided pair.
flecs::string path_from(const char *sep="::", const char *init_sep="::") const
Return the entity path relative to a typed parent.
First * try_get_mut(Second constant) const
Get a mutable pair.
auto try_get_mut_n() const
Get multiple mutable component values as a tuple of pointers.
bool enabled() const
Test if component is enabled.
const Second * try_get_second() const
Get the second part for a pair.
void children(flecs::entity_t rel, Func &&func) const
Iterate children for an entity.
auto get_mut_n() const
Get multiple mutable component values as a tuple of references.
bool has(E value) const
Check if entity has the provided enum constant.
bool enabled(flecs::id_t first, flecs::id_t second) const
Test if pair is enabled.
const A * try_get() const
Get component value.
entity()
Default constructor.
Class that wraps around a flecs::id_t.
flecs::world world() const
Get the world.
flecs::id_t id_
The raw ID value.
flecs::entity second() const
Get second element from a pair.
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
flecs::entity first() const
Get first element from a pair.
Class for iterating over query results.
Builds tuple types for a given number of component types.