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

| Flecs v4.0 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#ifdef FLECS_META
13 using U = typename std::underlying_type<E>::type;
14 const E* ptr = static_cast<const E*>(ecs_get_id(world_, id_,
15 ecs_pair(flecs::Constant, _::type<U>::id(world_))));
16 ecs_assert(ptr != NULL, ECS_INVALID_PARAMETER, "entity is not a constant");
17 return ptr[0];
18#else
19 ecs_assert(false, ECS_UNSUPPORTED,
20 "operation not supported without FLECS_META addon");
21 return E();
22#endif
23}
24
25template <typename E, if_t< is_enum<E>::value >>
26 inline flecs::entity world::to_entity(E constant) const {
27 const auto& et = enum_type<E>(world_);
28 return flecs::entity(world_, et.entity(constant));
29}
30
31}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
flecs::component::constant
untyped_component & constant(const char *name, T value)
Add constant.
Definition untyped_component.inl:192
flecs::entity_view::to_constant
E to_constant() const
Convert entity to enum constant.
Definition impl.hpp:11
flecs::world::to_entity
flecs::entity to_entity(E constant) const
Convert enum constant to entity.
Definition impl.hpp:26
ecs_get_id
const void * ecs_get_id(const ecs_world_t *world, ecs_entity_t entity, ecs_id_t id)
Get an immutable pointer to a component.
flecs::_::type
Definition flecs.hpp:39
flecs::entity
Entity.
Definition entity.hpp:30