Flecs: include/flecs/addons/cpp/type.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
type.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8namespace flecs {
9
17
21 struct type {
22 type() : world_(nullptr), type_(nullptr) { }
23
24 type(world_t *world, const type_t *t)
25 : world_(world)
26 , type_(t) { }
27
29 flecs::string str() const {
30 return flecs::string(ecs_type_str(world_, type_));
31 }
32
34 int32_t count() const {
35 if (!type_) {
36 return 0;
37 }
38 return type_->count;
39 }
40
42 flecs::id_t* array() const {
43 if (!type_) {
44 return nullptr;
45 }
46 return type_->array;
47 }
48
50 flecs::id get(int32_t index) const {
51 ecs_assert(type_ != NULL, ECS_INVALID_PARAMETER, NULL);
52 ecs_assert(type_->count > index, ECS_OUT_OF_RANGE, NULL);
53 if (!type_) {
54 return flecs::id();
55 }
56 return flecs::id(world_, type_->array[index]);
57 }
58
59 const flecs::id_t* begin() const {
60 if (type_ && type_->count) {
61 return type_->array;
62 } else {
63 return &empty_;
64 }
65 }
66
67 const flecs::id_t* end() const {
68 if (type_ && type_->count) {
69 return &type_->array[type_->count];
70 } else {
71 return &empty_;
72 }
73 }
74
76 operator const type_t*() const {
77 return type_;
78 }
79private:
80 world_t *world_;
81 const type_t *type_;
82 flecs::id_t empty_;
83};
84
86
87}
ecs_assert
#define ecs_assert(condition, error_code,...)
Assert.
Definition log.h:368
flecs::type::array
flecs::id_t * array() const
Return pointer to array.
Definition type.hpp:42
flecs::type::count
int32_t count() const
Return number of ids in type.
Definition type.hpp:34
flecs::type::str
flecs::string str() const
Convert type to comma-separated string.
Definition type.hpp:29
flecs::type::get
flecs::id get(int32_t index) const
Get id at specified index in type.
Definition type.hpp:50
ecs_type_str
char * ecs_type_str(const ecs_world_t *world, const ecs_type_t *type)
Convert type to string.
ecs_type_t::array
ecs_id_t * array
Array with ids.
Definition flecs.h:383
ecs_type_t::count
int32_t count
Number of elements in array.
Definition flecs.h:384
flecs::id
Class that wraps around a flecs::id_t.
Definition decl.hpp:27
flecs::string
Definition string.hpp:13
flecs::world
The world.
Definition world.hpp:150