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");
290 return static_cast<const T*
>(_::get_ptr<T>(
world_,
id_, comp_id));
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)");
565 template <typename Func, if_t< is_callable<Func>::value > = 0>
566 bool get(
const Func& func)
const;
573 template<
typename... Ts>
575 flecs_static_assert(
sizeof...(Ts) > 1,
"get_n requires at least two components");
576 flecs_static_assert(
sizeof...(Ts) < 9,
"get_n cannot fetch more than eight components");
577 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_const {get<Ts>()...};
589 template<
typename Second>
591 const Second *r = try_get_second<Second>(first);
593 "invalid get_second: entity does not have pair (use try_get_second)");
606 template<
typename First,
typename Second>
608 const Second *r = try_get<First, Second>();
610 "invalid get_second: entity does not have pair (use try_get_second)");
623 template <typename T, if_t< is_actual<T>::value > = 0>
627 "operation invalid for empty type");
628 return static_cast<T*
>(_::get_mut_ptr<T>(world_, id_, comp_id));
639 template <
typename T,
typename A = actual_type_t<T>,
640 if_t< flecs::is_pair<T>::value > = 0>
644 "operation invalid for empty type");
655 template <
typename First,
typename Second,
typename P = pair<First, Second>,
656 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
658 return this->try_get_mut<P>();
668 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
672 "operation invalid for empty type");
673 return static_cast<First*
>(
684 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
686 const auto& et = enum_type<Second>(this->world_);
688 return try_get_mut<First>(target);
719 template<
typename... Ts>
721 flecs_static_assert(
sizeof...(Ts) > 1,
"try_get_mut_n requires at least two components");
722 flecs_static_assert(
sizeof...(Ts) < 9,
"try_get_mut_n cannot fetch more than eight components");
723 return typename tuple_builder<
sizeof...(Ts), Ts...>::type_ptr {try_get_mut<Ts>()...};
734 template<
typename Second>
742 "operation invalid for empty type");
743 return static_cast<Second*
>(
755 template<
typename First,
typename Second>
757 return try_get_mut<pair_object<First, Second>>();
769 template <typename T, if_t< is_actual<T>::value > = 0>
771 T* r = try_get_mut<T>();
773 "invalid get_mut: entity does not have component (use try_get_mut)");
785 template <
typename T,
typename A = actual_type_t<T>,
786 if_t< flecs::is_pair<T>::value > = 0>
788 A* r = try_get_mut<T>();
790 "invalid get_mut: entity does not have component (use try_get_mut)");
802 template <
typename First,
typename Second,
typename P = pair<First, Second>,
803 typename A = actual_type_t<P>, if_not_t< flecs::is_pair<First>::value > = 0>
805 A* r = try_get_mut<First, Second>();
807 "invalid get_mut: entity does not have pair (use try_get_mut)");
819 template<typename First, typename Second, if_not_t< is_enum<Second>::value> = 0>
821 First* r = try_get_mut<First>(second);
823 "invalid get_mut: entity does not have pair (use try_get_mut)");
835 template<typename First, typename Second, if_t< is_enum<Second>::value && !std::is_same<First, Second>::value > = 0>
837 const auto& et = enum_type<Second>(this->world_);
839 return get_mut<First>(target);
851 "invalid get_mut: entity does not have component (use try_get_mut)");
868 "invalid get_mut: entity does not have pair (use try_get_mut)");
877 template<
typename... Ts>
879 flecs_static_assert(
sizeof...(Ts) > 1,
"get_mut_n requires at least two components");
880 flecs_static_assert(
sizeof...(Ts) < 9,
"get_mut_n cannot fetch more than eight components");
881 return typename tuple_builder<
sizeof...(Ts), Ts...>::type {get_mut<Ts>()...};
893 template<
typename Second>
895 Second *r = try_get_mut_second<Second>(first);
897 "invalid get_mut_second: entity does not have pair (use try_get_mut_second)");
910 template<
typename First,
typename Second>
912 Second *r = try_get_mut_second<First, Second>();
914 "invalid get_mut_second: entity does not have pair (use try_get_mut_second)");
923 template<
typename Enum>
924 Enum get_constant()
const;
935 template<
typename First>
976 template <
typename T>
986 template <
typename First,
typename Second>
1003 template<
typename Rel>
1023 flecs::entity lookup(
const char *path,
bool search_path =
false)
const;
1039 template <
typename T>
1047 if (is_enum<T>::value) {
1048 return ecs_has_pair(world_, id_, cid, flecs::Wildcard);
1060 template <typename E, if_t< is_enum<E>::value > = 0>
1063 auto o = enum_type<E>(world_).entity(value);
1065 "Constant was not found in Enum reflection data."
1066 " Did you mean to use has<E>() instead of has(E)?");
1076 template <
typename First,
typename Second>
1087 template<typename First, typename Second, if_not_t< is_enum<Second>::value > = 0>
1088 bool has(Second second)
const {
1090 return ecs_has_id(world_, id_, ecs_pair(comp_id, second));
1099 template <
typename Second>
1110 template<typename First, typename E, if_t< is_enum<E>::value && !std::is_same<First, E>::value > = 0>
1112 const auto& et = enum_type<E>(this->world_);
1114 return has<First>(second);
1124 return ecs_has_id(world_, id_, ecs_pair(first, second));
1143 template <
typename First>
1146 return owns(ecs_pair(comp_id, second));
1156 return owns(ecs_pair(first, second));
1165 template <
typename T>
1177 template <
typename First,
typename Second>
1190 template <
typename Second>
1209 template<
typename T>
1221 return this->enabled(ecs_pair(first, second));
1230 template <
typename First>
1241 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.