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

| Flecs v4.1 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
8namespace flecs {
9
10template <typename E>
11 inline E entity_view::to_constant() const {
12 using U = typename std::underlying_type<E>::type;
13 const E* ptr = static_cast<const E*>(ecs_get_id(world_, id_,
14 ecs_pair(flecs::Constant, _::type<U>::id(world_))));
15 ecs_assert(ptr != nullptr, ECS_INVALID_PARAMETER, "entity is not a constant");
16 return ptr[0];
17}
18
19template <typename E, if_t< is_enum<E>::value >>
20 inline flecs::entity world::to_entity(E constant) const {
21 const auto& et = enum_type<E>(world_);
22 return flecs::entity(world_, et.entity(constant));
23}
24
25}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:473
ECS_INVALID_PARAMETER
#define ECS_INVALID_PARAMETER
Invalid parameter error code.
Definition log.h:671
flecs::component::constant
untyped_component & constant(const char *name, T value)
Add a constant.
Definition untyped_component.inl:186
flecs::entity_view::to_constant
E to_constant() const
Convert an entity to an enum constant.
Definition impl.hpp:11
flecs::world::to_entity
flecs::entity to_entity(E constant) const
Convert an enum constant to an entity.
Definition impl.hpp:20
ecs_get_id
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.
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30
flecs::id::id_
flecs::id_t id_
The raw ID value.
Definition decl.hpp:149
flecs::id::world_
flecs::world_t * world_
World is optional, but guarantees that entity identifiers extracted from the ID are valid.
Definition decl.hpp:147
flecs::world::world_
world_t * world_
Pointer to the underlying C world.
Definition world.hpp:1540