Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs::component< T > Struct Template Reference

Component class. More...

#include <component.hpp>

Inheritance diagram for flecs::component< T >:
[legend]

Public Types

using cmp_hook = int(*)(const T* a, const T* b, const ecs_type_info_t *ti)
using equals_hook = bool(*)(const T* a, const T* b, const ecs_type_info_t *ti)

Public Member Functions

 component (flecs::world_t *world, const char *name=nullptr, bool allow_tag=true, flecs::id_t id=0)
 Register a component.
template<typename Func>
component< T > & on_add (Func &&func)
 Register on_add hook.
template<typename Func>
component< T > & on_remove (Func &&func)
 Register on_remove hook.
template<typename Func>
component< T > & on_set (Func &&func)
 Register on_set hook.
template<typename Func>
component< T > & on_replace (Func &&func)
 Register on_replace hook.
component< T > & on_compare ()
 Register an operator compare hook using type T's comparison operators.
component< T > & on_compare (cmp_hook callback)
 Type-safe variant of the compare op function.
component< T > & on_equals ()
 Register an operator equals hook using type T's equality operator.
component< T > & on_equals (equals_hook callback)
 Type-safe variant of the equals op function.
template<typename Func>
componentopaque (const Func &type_support)
 Register an opaque type interface.
flecs::opaque< T > opaque (flecs::entity_t as_type)
 Return opaque type builder for a type, serialized as the given type.
flecs::opaque< T > opaque (flecs::entity as_type)
 Return opaque type builder for a type, serialized as the given type.
flecs::opaque< T > opaque (flecs::untyped_component as_type)
 Return opaque type builder for a type, serialized as the given type.
template<typename ElemType>
flecs::opaque< T, ElemType > opaque (flecs::id_t as_type)
 Return opaque type builder for a collection type.
component< T > & constant (const char *name, T value)
 Add a constant.
untyped_componenton_compare (ecs_cmp_t compare_callback)
 Register a custom compare hook for this component.
untyped_componenton_equals (ecs_equals_t equals_callback)
 Register a custom equals hook for this component.
template<typename Kind>
untyped_componentmetric (flecs::entity_t parent=0, const char *brief=nullptr, const char *name=nullptr)
 Register a member as a metric.
Public Member Functions inherited from flecs::untyped_component
 untyped_component ()
 Default constructor.
 untyped_component (flecs::world_t *world, flecs::entity_t id)
 Construct from world and entity ID.
 untyped_component (flecs::entity_t id)
 Construct from entity ID.
 untyped_component (flecs::world_t *world, const char *name)
 Construct from world and name.
 untyped_component (world_t *world, const char *name, const char *sep, const char *root_sep)
 Construct from world, name, and scope separators.
untyped_componenton_compare (ecs_cmp_t compare_callback)
 Register a custom compare hook for this component.
untyped_componenton_equals (ecs_equals_t equals_callback)
 Register a custom equals hook for this component.
 entity ()
 Default constructor.
 entity (const flecs::world_t *world, flecs::entity_t id)
 Wrap an existing entity ID.
 entity (world_t *world)
 Create a new entity.
 entity (world_t *world, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity.
 entity (world_t *world, flecs::entity_t parent, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity for a parent using ChildOf hierarchy storage.
 entity (world_t *world, const flecs::Parent &parent, const char *name=nullptr)
 Create a named entity for a parent using Parent hierarchy storage.
 entity (entity_t id)
 Conversion from flecs::entity_t to flecs::entity.
template<typename Kind>
untyped_componentmetric (flecs::entity_t parent=0, const char *brief=nullptr, const char *name=nullptr)
 Register a member as a metric.
Public Member Functions inherited from flecs::entity
 entity ()
 Default constructor.
 entity (const flecs::world_t *world, flecs::entity_t id)
 Wrap an existing entity ID.
 entity (world_t *world)
 Create a new entity.
 entity (world_t *world, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity.
 entity (world_t *world, flecs::entity_t parent, const char *name, const char *sep="::", const char *root_sep="::")
 Create a named entity for a parent using ChildOf hierarchy storage.
 entity (world_t *world, const flecs::Parent &parent, const char *name=nullptr)
 Create a named entity for a parent using Parent hierarchy storage.
 entity (entity_t id)
 Conversion from flecs::entity_t to flecs::entity.
template<typename T>
T & ensure () const
 Get mutable component value.
void * ensure (entity_t comp) const
 Get mutable component value (untyped).
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
A & ensure () const
 Get mutable reference for a pair.
template<typename First>
First & ensure (entity_t second) const
 Get mutable reference for the first element of a pair.
void * ensure (entity_t first, entity_t second) const
 Get mutable pointer for a pair (untyped).
template<typename Second>
Second & ensure_second (entity_t first) const
 Get mutable reference for the second element of a pair.
template<typename T>
void modified () const
 Signal that component was modified.
template<typename First, typename Second, typename A = actual_type_t<flecs::pair<First, Second>>>
void modified () const
 Signal that the first element of a pair was modified.
template<typename First>
void modified (entity_t second) const
 Signal that the first part of a pair was modified.
void modified (entity_t first, entity_t second) const
 Signal that a pair has been modified (untyped).
void modified (entity_t comp) const
 Signal that component was modified.
template<typename T, if_t< is_actual< T >::value > = 0>
ref< T > get_ref_w_id (flecs::id_t component) const
 Get reference to component specified by component ID.
template<typename T, if_t< is_actual< T >::value > = 0>
ref< T > get_ref () const
 Get reference to component.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
ref< A > get_ref () const
 Get reference to component.
template<typename First, typename Second, typename P = flecs::pair<First, Second>, typename A = actual_type_t<P>>
ref< A > get_ref () const
 Get reference to pair component.
template<typename First>
ref< First > get_ref (flecs::entity_t second) const
 Get reference to the first element of a pair.
untyped_ref get_ref (flecs::id_t component) const
 Get untyped reference to component by component ID.
untyped_ref get_ref (flecs::id_t first, flecs::id_t second) const
 Get untyped reference to pair by first and second entity IDs.
template<typename Second>
ref< Second > get_ref_second (flecs::entity_t first) const
 Get reference to the second element of a pair.
void clear () const
 Clear an entity.
void destruct () const
 Delete an entity.
template<typename ... Args>
flecs::entity child (flecs::entity_t r=flecs::ChildOf, Args &&... args)
 Create a child entity with a specified relationship.
template<typename R, typename ... Args>
flecs::entity child (Args &&... args)
 Create a child entity with a typed relationship.
void set_child_order (flecs::entity_t *children, int32_t child_count) const
 Set child order.
flecs::entity_view view () const
 Return the entity as an entity_view.
const char * from_json (const char *json)
 Deserialize an entity from JSON.
const char * from_json (const char *json)
 Deserialize an entity from JSON.
Public Member Functions inherited from flecs::entity_builder< entity >
const entityset_doc_name (const char *name) const
 Set human-readable name.
const entityset_doc_brief (const char *brief) const
 Set brief description.
const entityset_doc_detail (const char *detail) const
 Set detailed description.
const entityset_doc_link (const char *link) const
 Set link to external documentation.
const entityset_doc_color (const char *color) const
 Set doc color.
const entityset_doc_uuid (const char *uuid) const
 Set doc UUID.
const entityobserve (flecs::entity_t evt, Func &&callback) const
 Observe an event on an entity.
const entityobserve (Func &&callback) const
 Observe an event on an entity.
const entityobserve (Func &&callback) const
 Observe an event on an entity.
const entityset_json (flecs::id_t e, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a component from JSON.
const entityset_json (flecs::entity_t r, flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
const entityset_json (const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a component from JSON.
const entityset_json (const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
const entityset_json (flecs::entity_t t, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
const entityset_json_second (flecs::entity_t r, const char *json, flecs::from_json_desc_t *desc=nullptr) const
 Set a pair from JSON.
 entity_view ()
 Default constructor.
 entity_view (flecs::world_t *world, flecs::id_t id)
 Wrap an existing entity ID.
 entity_view (entity_t id)
 Implicit conversion from flecs::entity_t to flecs::entity_view.
const entityadd () const
 Add a component to an entity.
const entityadd_second (flecs::entity_t first) const
 Add a pair.
const entityadd_if (bool cond, flecs::id_t component) const
 Conditional add.
const entityis_a (entity_t second) const
 Shortcut for add(IsA, entity).
const entitychild_of (entity_t second) const
 Shortcut for add(ChildOf, entity).
const entitydepends_on (entity_t second) const
 Shortcut for add(DependsOn, entity).
const entityslot_of (entity_t second) const
 Shortcut for add(SlotOf, entity).
const entityslot () const
 Shortcut for add(SlotOf, target(ChildOf)).
const entityremove () const
 Remove a component from an entity.
const entityremove_second (flecs::entity_t first) const
 Remove a pair.
const entityauto_override (flecs::id_t id) const
 Mark ID for auto-overriding.
const entityauto_override_second (flecs::entity_t first) const
 Mark pair for auto-overriding.
const entityset_auto_override (const T &val) const
 Set component, mark component for auto-overriding.
const entityemplace_auto_override (Args &&... args) const
 Emplace component, mark component for auto-overriding.
const entityenable () const
 Enable an entity.
const entitydisable () const
 Disable an entity.
const entityset_ptr (entity_t comp, size_t size, const void *ptr) const
const entityset (T &&value) const
 Set a component for an entity.
const entityset_second (entity_t first, const Second &value) const
 Set a pair for an entity.
const entityassign (T &&value) const
 Assign a component for an entity.
const entityassign_second (entity_t first, const Second &value) const
 Assign a pair for an entity.
const entityinsert (const Func &func) const
 Set 1..N components.
const entityemplace (Args &&... args) const
 Emplace a component.
const entityemplace_first (flecs::entity_t second, Args &&... args) const
const entityemplace_second (flecs::entity_t first, Args &&... args) const
const entitywith (const Func &func) const
 Entities created in the function will have the current entity.
const entityscope (const Func &func) const
 The function will be run with the scope set to the current entity.
const entityset_name (const char *name) const
 Set the entity name.
const entityset_alias (const char *name) const
 Set the entity alias.
const entityunit (const char *symbol, flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
 Make an entity a unit.
Public Member Functions inherited from flecs::entity_view
 entity_view ()
 Default constructor.
 entity_view (flecs::world_t *world, flecs::id_t id)
 Wrap an existing entity ID.
 entity_view (entity_t id)
 Implicit conversion from flecs::entity_t to flecs::entity_view.
entity_t id () const
 Get entity ID.
bool is_valid () const
 Check if entity is valid.
 operator bool () const
 Conversion to bool.
bool is_alive () const
 Check if entity is alive.
flecs::string_view name () const
 Return the entity name.
flecs::string_view symbol () const
 Return the entity symbol.
flecs::string path (const char *sep="::", const char *init_sep="::") const
 Return the entity path.
flecs::string path_from (flecs::entity_t parent, const char *sep="::", const char *init_sep="::") const
 Return the entity path relative to a parent.
template<typename Parent>
flecs::string path_from (const char *sep="::", const char *init_sep="::") const
 Return the entity path relative to a typed parent.
bool enabled () const
 Check if entity is enabled (does not have the Disabled tag).
flecs::type type () const
 Get the entity's type.
flecs::table table () const
 Get the entity's table.
flecs::table_range range () const
 Get table range for the entity.
template<typename Func>
void each (const Func &func) const
 Iterate (component) IDs of an entity.
template<typename Func>
void each (flecs::id_t first, flecs::id_t second, const Func &func) const
 Iterate matching pair IDs of an entity.
template<typename Func>
void each (const flecs::entity_view &rel, const Func &func) const
 Iterate targets for a given relationship.
template<typename First, typename Func>
void each (const Func &func) const
 Iterate targets for a given relationship.
template<typename Func>
void children (flecs::entity_t rel, Func &&func) const
 Iterate children for an entity.
template<typename Rel, typename Func>
void children (Func &&func) const
 Iterate children for an entity.
template<typename Func>
void children (Func &&func) const
 Iterate children for an entity.
template<typename T, if_t< is_actual< T >::value > = 0>
const T * try_get () const
 Get component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
const A * try_get () const
 Get component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
const A * try_get () const
 Get a pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
const First * try_get (Second second) const
 Get a pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
const First * try_get (Second constant) const
 Get a pair.
const void * try_get (flecs::id_t comp) const
 Get component value (untyped).
const void * try_get (flecs::entity_t first, flecs::entity_t second) const
 Get a pair (untyped).
template<typename... Ts>
auto try_get_n () const
 Get multiple component values as a tuple of const pointers.
template<typename Second>
const Second * try_get_second (flecs::entity_t first) const
 Get the second part for a pair.
template<typename First, typename Second>
const Second * try_get_second () const
 Get the second part for a pair.
template<typename T, if_t< is_actual< T >::value > = 0>
const T & get () const
 Get component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
const A & get () const
 Get component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
const A & get () const
 Get a pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
const First & get (Second second) const
 Get a pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
const First & get (Second constant) const
 Get a pair.
const void * get (flecs::id_t comp) const
 Get component value (untyped).
const void * get (flecs::entity_t first, flecs::entity_t second) const
 Get a pair (untyped).
template<typename Func, if_t< is_callable< Func >::value > = 0>
bool get (const Func &func) const
 Get 1..N components.
template<typename... Ts>
auto get_n () const
 Get multiple component values as a tuple of const references.
template<typename Second>
const Second & get_second (flecs::entity_t first) const
 Get the second part for a pair.
template<typename First, typename Second>
const Second & get_second () const
 Get the second part for a pair.
template<typename T, if_t< is_actual< T >::value > = 0>
T * try_get_mut () const
 Get mutable component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
A * try_get_mut () const
 Get mutable component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
A * try_get_mut () const
 Get a mutable pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
First * try_get_mut (Second second) const
 Get a mutable pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
First * try_get_mut (Second constant) const
 Get a mutable pair.
void * try_get_mut (flecs::id_t comp) const
 Get mutable component value (untyped).
void * try_get_mut (flecs::entity_t first, flecs::entity_t second) const
 Get a mutable pair (untyped).
template<typename... Ts>
auto try_get_mut_n () const
 Get multiple mutable component values as a tuple of pointers.
template<typename Second>
Second * try_get_mut_second (flecs::entity_t first) const
 Get the second part for a pair.
template<typename First, typename Second>
Second * try_get_mut_second () const
 Get the second part for a pair.
template<typename T, if_t< is_actual< T >::value > = 0>
T & get_mut () const
 Get mutable component value.
template<typename T, typename A = actual_type_t<T>, if_t< flecs::is_pair< T >::value > = 0>
A & get_mut () const
 Get mutable component value.
template<typename First, typename Second, typename P = pair<First, Second>, typename A = actual_type_t<P>, if_not_t< flecs::is_pair< First >::value > = 0>
A & get_mut () const
 Get a mutable pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
First & get_mut (Second second) const
 Get a mutable pair.
template<typename First, typename Second, if_t< is_enum< Second >::value &&!std::is_same< First, Second >::value > = 0>
First & get_mut (Second constant) const
 Get a mutable pair.
void * get_mut (flecs::id_t comp) const
 Get mutable component value (untyped).
void * get_mut (flecs::entity_t first, flecs::entity_t second) const
 Get a mutable pair (untyped).
template<typename... Ts>
auto get_mut_n () const
 Get multiple mutable component values as a tuple of references.
template<typename Second>
Second & get_mut_second (flecs::entity_t first) const
 Get the second part for a pair.
template<typename First, typename Second>
Second & get_mut_second () const
 Get the second part for a pair.
template<typename Enum>
Enum get_constant () const
 Get enum constant for enum relationship.
template<typename First>
flecs::entity target (int32_t index=0) const
 Get target for a given pair.
flecs::entity target (flecs::entity_t first, int32_t index=0) const
 Get target for a given pair.
flecs::entity target_for (flecs::entity_t relationship, flecs::id_t id) const
 Get the target of a pair for a given relationship ID.
template<typename T>
flecs::entity target_for (flecs::entity_t relationship) const
 Get the target of a pair for a given relationship ID.
template<typename First, typename Second>
flecs::entity target_for (flecs::entity_t relationship) const
 Get the target of a pair for a given relationship ID.
int32_t depth (flecs::entity_t rel) const
 Get the depth for a given relationship.
template<typename Rel>
int32_t depth () const
 Get the depth for a given relationship.
flecs::entity parent () const
 Get parent of entity.
flecs::entity lookup (const char *path, bool search_path=false) const
 Lookup an entity by name.
bool has (flecs::id_t e) const
 Check if entity has the provided entity.
template<typename T>
bool has () const
 Check if entity has the provided component.
template<typename E, if_t< is_enum< E >::value > = 0>
bool has (E value) const
 Check if entity has the provided enum constant.
template<typename First, typename Second>
bool has () const
 Check if entity has the provided pair.
template<typename First, typename Second, if_not_t< is_enum< Second >::value > = 0>
bool has (Second second) const
 Check if entity has the provided pair.
template<typename Second>
bool has_second (flecs::entity_t first) const
 Check if entity has the provided pair.
template<typename First, typename E, if_t< is_enum< E >::value &&!std::is_same< First, E >::value > = 0>
bool has (E value) const
 Check if entity has the provided pair.
bool has (flecs::id_t first, flecs::id_t second) const
 Check if entity has the provided pair.
bool owns (flecs::id_t e) const
 Check if entity owns the provided entity.
template<typename First>
bool owns (flecs::id_t second) const
 Check if entity owns the provided pair.
bool owns (flecs::id_t first, flecs::id_t second) const
 Check if entity owns the provided pair.
template<typename T>
bool owns () const
 Check if entity owns the provided component.
template<typename First, typename Second>
bool owns () const
 Check if entity owns the provided pair.
template<typename Second>
bool owns_second (flecs::entity_t first) const
 Check if entity owns the provided pair.
bool enabled (flecs::id_t id) const
 Test if ID is enabled.
template<typename T>
bool enabled () const
 Test if component is enabled.
bool enabled (flecs::id_t first, flecs::id_t second) const
 Test if pair is enabled.
template<typename First>
bool enabled (flecs::id_t second) const
 Test if pair is enabled.
template<typename First, typename Second>
bool enabled () const
 Test if pair is enabled.
flecs::entity clone (bool clone_value=true, flecs::entity_t dst_id=0) const
 Clone an entity.
flecs::entity mut (const flecs::world &stage) const
 Return a mutable entity handle for the current stage.
flecs::entity mut (const flecs::iter &it) const
 Same as mut(world), but for an iterator.
flecs::entity mut (const flecs::entity_view &e) const
 Same as mut(world), but for an entity.
flecs::string to_json (const flecs::entity_to_json_desc_t *desc=nullptr) const
 Serialize an entity to JSON.
const char * doc_name () const
 Get human-readable name.
const char * doc_brief () const
 Get brief description.
const char * doc_detail () const
 Get detailed description.
const char * doc_link () const
 Get link to external documentation.
const char * doc_color () const
 Get color.
const char * doc_uuid () const
 Get UUID.
int32_t alert_count (flecs::entity_t alert=0) const
 Return the number of alerts for an entity.
template<typename E>
to_constant () const
 Convert an entity to an enum constant.
void emit (flecs::entity_t evt) const
 Emit an event for an entity.
void emit (flecs::entity evt) const
 Emit an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void emit () const
 Emit an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void emit (const Evt &payload) const
 Emit an event with payload for an entity.
void enqueue (flecs::entity_t evt) const
 Enqueue an event for an entity.
void enqueue (flecs::entity evt) const
 Enqueue an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void enqueue () const
 Enqueue an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void enqueue (const Evt &payload) const
 Enqueue an event with payload for an entity.
int32_t alert_count (flecs::entity_t alert=0) const
 Return the number of alerts for an entity.
const char * doc_name () const
 Get human-readable name.
const char * doc_brief () const
 Get brief description.
const char * doc_detail () const
 Get detailed description.
const char * doc_link () const
 Get link to external documentation.
const char * doc_color () const
 Get color.
const char * doc_uuid () const
 Get UUID.
template<typename E>
to_constant () const
 Convert an entity to an enum constant.
void emit (flecs::entity_t evt) const
 Emit an event for an entity.
void emit (flecs::entity evt) const
 Emit an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void emit () const
 Emit an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void emit (const Evt &payload) const
 Emit an event with payload for an entity.
void enqueue (flecs::entity_t evt) const
 Enqueue an event for an entity.
void enqueue (flecs::entity evt) const
 Enqueue an event for an entity.
template<typename Evt, if_t< is_empty< Evt >::value > = 0>
void enqueue () const
 Enqueue an event for an entity.
template<typename Evt, if_not_t< is_empty< Evt >::value > = 0>
void enqueue (const Evt &payload) const
 Enqueue an event with payload for an entity.
flecs::string to_json (const flecs::entity_to_json_desc_t *desc=nullptr) const
 Serialize an entity to JSON.
Public Member Functions inherited from flecs::id
 id (flecs::id_t value)
 id (flecs::world_t *world, flecs::id_t value=0)
 id (flecs::world_t *world, flecs::id_t first, flecs::id_t second)
 id (flecs::world_t *world, const char *expr)
 id (flecs::id_t first, flecs::id_t second)
 id (const flecs::id &first, const flecs::id &second)
bool is_pair () const
 Test if ID is a pair (has first, second).
bool is_wildcard () const
 Test if ID is a wildcard.
bool is_entity () const
 Test if ID is an entity.
flecs::entity entity () const
 Return ID as entity (only allowed when ID is a valid entity).
flecs::entity add_flags (flecs::id_t flags) const
 Return ID with flags added.
flecs::entity remove_flags (flecs::id_t flags) const
 Return ID with flags removed.
flecs::entity remove_flags () const
 Return ID without flags.
flecs::entity remove_generation () const
 Return ID without generation.
flecs::entity type_id () const
 Return component type of ID.
bool has_flags (flecs::id_t flags) const
 Test if ID has specified flags.
bool has_flags () const
 Test if ID has any flags.
flecs::entity flags () const
 Return ID flags set on ID.
bool has_relation (flecs::id_t first) const
 Test if ID has the specified first element.
flecs::entity first () const
 Get first element from a pair.
flecs::entity second () const
 Get second element from a pair.
flecs::string str () const
 Convert ID to string.
flecs::string flags_str () const
 Convert flags of ID to string.
flecs::id_t raw_id () const
 Return flecs::id_t value.
 operator flecs::id_t () const
flecs::world world () const
 Get the world.
untyped_componentmember (flecs::entity_t type_id, flecs::entity_t unit, const char *name, int32_t count=0)
 Add a member with unit.
untyped_componentmember (flecs::entity_t type_id, flecs::entity_t unit, const char *name, int32_t count, size_t offset)
 Add a member with unit, count, and offset.
untyped_componentmember (flecs::entity_t type_id, const char *name, int32_t count=0)
 Add a member.
untyped_componentmember (flecs::entity_t type_id, const char *name, int32_t count, size_t offset)
 Add a member with count and offset.
template<typename MemberType>
untyped_componentmember (const char *name, int32_t count=0)
 Add a member.
template<typename MemberType>
untyped_componentmember (const char *name, int32_t count, size_t offset)
 Add a member.
template<typename MemberType>
untyped_componentmember (flecs::entity_t unit, const char *name, int32_t count=0)
 Add a member with unit.
template<typename MemberType>
untyped_componentmember (flecs::entity_t unit, const char *name, int32_t count, size_t offset)
 Add a member with unit.
template<typename MemberType, typename UnitType>
untyped_componentmember (const char *name, int32_t count=0)
 Add a member with unit.
template<typename MemberType, typename UnitType>
untyped_componentmember (const char *name, int32_t count, size_t offset)
 Add a member with unit.
template<typename MemberType, typename ComponentType, typename RealType = typename std::remove_extent<MemberType>::type>
untyped_componentmember (const char *name, const MemberType ComponentType::*ptr)
 Add a member using pointer-to-member.
template<typename MemberType, typename ComponentType, typename RealType = typename std::remove_extent<MemberType>::type>
untyped_componentmember (flecs::entity_t unit, const char *name, const MemberType ComponentType::*ptr)
 Add a member with unit using pointer-to-member.
template<typename UnitType, typename MemberType, typename ComponentType, typename RealType = typename std::remove_extent<MemberType>::type>
untyped_componentmember (const char *name, const MemberType ComponentType::*ptr)
 Add a member with unit using pointer-to-member.
template<typename T = int32_t>
untyped_componentconstant (const char *name, T value)
 Add a constant.
template<typename T = uint32_t>
untyped_componentbit (const char *name, T value)
 Add a bitmask constant.
template<typename Elem>
untyped_componentarray (int32_t elem_count)
 Register array metadata for a component.
untyped_componentrange (double min, double max)
 Add a member value range.
untyped_componentwarning_range (double min, double max)
 Add a member warning range.
untyped_componenterror_range (double min, double max)
 Add a member error range.

Additional Inherited Members

Static Public Member Functions inherited from flecs::entity
static flecs::entity null (const flecs::world_t *world)
 Entity ID 0.
static flecs::entity null ()
 Entity ID 0 without a world.
Protected Member Functions inherited from flecs::untyped_component
flecs::type_hooks_t get_hooks () const
 Get the type hooks for this component.
void set_hooks (flecs::type_hooks_t &h)
 Set the type hooks for this component.
Protected Member Functions inherited from flecs::entity_builder< entity >
const entityto_base () const
Protected Attributes inherited from flecs::id
flecs::world_tworld_
 World is optional, but guarantees that entity identifiers extracted from the ID are valid.
flecs::id_t id_
 The raw ID value.
untyped_componentmember (flecs::entity_t type_id, flecs::entity_t unit, const char *name, int32_t count=0)
 Add a member with unit.
untyped_componentmember (flecs::entity_t type_id, flecs::entity_t unit, const char *name, int32_t count, size_t offset)
 Add a member with unit, count, and offset.
untyped_componentmember (flecs::entity_t type_id, const char *name, int32_t count=0)
 Add a member.
untyped_componentmember (flecs::entity_t type_id, const char *name, int32_t count, size_t offset)
 Add a member with count and offset.
template<typename MemberType>
untyped_componentmember (const char *name, int32_t count=0)
 Add a member.
template<typename MemberType>
untyped_componentmember (const char *name, int32_t count, size_t offset)
 Add a member.
template<typename MemberType>
untyped_componentmember (flecs::entity_t unit, const char *name, int32_t count=0)
 Add a member with unit.
template<typename MemberType>
untyped_componentmember (flecs::entity_t unit, const char *name, int32_t count, size_t offset)
 Add a member with unit.
template<typename MemberType, typename UnitType>
untyped_componentmember (const char *name, int32_t count=0)
 Add a member with unit.
template<typename MemberType, typename UnitType>
untyped_componentmember (const char *name, int32_t count, size_t offset)
 Add a member with unit.
template<typename MemberType, typename ComponentType, typename RealType = typename std::remove_extent<MemberType>::type>
untyped_componentmember (const char *name, const MemberType ComponentType::*ptr)
 Add a member using pointer-to-member.
template<typename MemberType, typename ComponentType, typename RealType = typename std::remove_extent<MemberType>::type>
untyped_componentmember (flecs::entity_t unit, const char *name, const MemberType ComponentType::*ptr)
 Add a member with unit using pointer-to-member.
template<typename UnitType, typename MemberType, typename ComponentType, typename RealType = typename std::remove_extent<MemberType>::type>
untyped_componentmember (const char *name, const MemberType ComponentType::*ptr)
 Add a member with unit using pointer-to-member.
template<typename T = int32_t>
untyped_componentconstant (const char *name, T value)
 Add a constant.
template<typename T = uint32_t>
untyped_componentbit (const char *name, T value)
 Add a bitmask constant.
template<typename Elem>
untyped_componentarray (int32_t elem_count)
 Register array metadata for a component.
untyped_componentrange (double min, double max)
 Add a member value range.
untyped_componentwarning_range (double min, double max)
 Add a member warning range.
untyped_componenterror_range (double min, double max)
 Add a member error range.
const entityunit (flecs::entity_t prefix=0, flecs::entity_t base=0, flecs::entity_t over=0, int32_t factor=0, int32_t power=0) const
 Make an entity a derived unit.
const entityunit_prefix (const char *symbol, int32_t factor=0, int32_t power=0) const
 Make an entity a unit prefix.
const entityquantity (flecs::entity_t quantity) const
 Add a quantity to a unit.
const entityquantity () const
 Add a quantity to a unit.
const entityquantity () const
 Make an entity a quantity.

Detailed Description

template<typename T>
struct flecs::component< T >

Component class.

Class used to register components and component metadata.

Definition at line 394 of file component.hpp.

Member Typedef Documentation

◆ cmp_hook

template<typename T>
using flecs::component< T >::cmp_hook = int(*)(const T* a, const T* b, const ecs_type_info_t *ti)

Definition at line 507 of file component.hpp.

◆ equals_hook

template<typename T>
using flecs::component< T >::equals_hook = bool(*)(const T* a, const T* b, const ecs_type_info_t *ti)

Definition at line 533 of file component.hpp.

Constructor & Destructor Documentation

◆ component()

template<typename T>
flecs::component< T >::component ( flecs::world_t * world,
const char * name = nullptr,
bool allow_tag = true,
flecs::id_t id = 0 )
inline

Register a component.

If the component was already registered, this operation will return a handle to the existing component.

Parameters
worldThe world for which to register the component.
nameOptional name (overrides typename).
allow_tagIf true, empty types will be registered with size 0.
idOptional component ID to register the component with.

Definition at line 404 of file component.hpp.

Member Function Documentation

◆ constant()

template<typename T>
component< T > & flecs::component< T >::constant ( const char * name,
T value )
inline

Add a constant.

Definition at line 39 of file component.hpp.

◆ on_add()

template<typename T>
template<typename Func>
component< T > & flecs::component< T >::on_add ( Func && func)
inline

Register on_add hook.

Parameters
funcThe callback function.
Returns
Reference to self for chaining.

Definition at line 420 of file component.hpp.

◆ on_compare() [1/3]

template<typename T>
component< T > & flecs::component< T >::on_compare ( )
inline

Register an operator compare hook using type T's comparison operators.

Returns
Reference to self for chaining.

Definition at line 499 of file component.hpp.

◆ on_compare() [2/3]

template<typename T>
component< T > & flecs::component< T >::on_compare ( cmp_hook callback)
inline

Type-safe variant of the compare op function.

Parameters
callbackThe comparison callback function.
Returns
Reference to self for chaining.

Definition at line 514 of file component.hpp.

◆ on_compare() [3/3]

template<typename T>
untyped_component & flecs::untyped_component::on_compare ( ecs_cmp_t compare_callback)
inline

Register a custom compare hook for this component.

Parameters
compare_callbackThe comparison callback function.
Returns
Reference to self for chaining.

Definition at line 349 of file component.hpp.

◆ on_equals() [1/3]

template<typename T>
component< T > & flecs::component< T >::on_equals ( )
inline

Register an operator equals hook using type T's equality operator.

Returns
Reference to self for chaining.

Definition at line 525 of file component.hpp.

◆ on_equals() [2/3]

template<typename T>
untyped_component & flecs::untyped_component::on_equals ( ecs_equals_t equals_callback)
inline

Register a custom equals hook for this component.

Parameters
equals_callbackThe equality callback function.
Returns
Reference to self for chaining.

Definition at line 369 of file component.hpp.

◆ on_equals() [3/3]

template<typename T>
component< T > & flecs::component< T >::on_equals ( equals_hook callback)
inline

Type-safe variant of the equals op function.

Parameters
callbackThe equality callback function.
Returns
Reference to self for chaining.

Definition at line 540 of file component.hpp.

◆ on_remove()

template<typename T>
template<typename Func>
component< T > & flecs::component< T >::on_remove ( Func && func)
inline

Register on_remove hook.

Parameters
funcThe callback function.
Returns
Reference to self for chaining.

Definition at line 439 of file component.hpp.

◆ on_replace()

template<typename T>
template<typename Func>
component< T > & flecs::component< T >::on_replace ( Func && func)
inline

Register on_replace hook.

Parameters
funcThe callback function.
Returns
Reference to self for chaining.

Definition at line 479 of file component.hpp.

◆ on_set()

template<typename T>
template<typename Func>
component< T > & flecs::component< T >::on_set ( Func && func)
inline

Register on_set hook.

Parameters
funcThe callback function.
Returns
Reference to self for chaining.

Definition at line 459 of file component.hpp.

◆ opaque() [1/5]

template<typename T>
template<typename Func>
component & flecs::component< T >::opaque ( const Func & type_support)
inline

Register an opaque type interface.

Definition at line 9 of file component.hpp.

◆ opaque() [2/5]

template<typename T>
flecs::opaque< T > flecs::component< T >::opaque ( flecs::entity as_type)
inline

Return opaque type builder for a type, serialized as the given type.

Definition at line 23 of file component.hpp.

◆ opaque() [3/5]

template<typename T>
flecs::opaque< T > flecs::component< T >::opaque ( flecs::entity_t as_type)
inline

Return opaque type builder for a type, serialized as the given type.

Definition at line 18 of file component.hpp.

◆ opaque() [4/5]

template<typename T>
template<typename ElemType>
flecs::opaque< T, ElemType > flecs::component< T >::opaque ( flecs::id_t as_type)
inline

Return opaque type builder for a collection type.

Definition at line 34 of file component.hpp.

◆ opaque() [5/5]

template<typename T>
flecs::opaque< T > flecs::component< T >::opaque ( flecs::untyped_component< T > as_type)
inline

Return opaque type builder for a type, serialized as the given type.

Definition at line 28 of file component.hpp.


The documentation for this struct was generated from the following files: