Skip to content
Flecs v4.1
cursor.hpp
Go to the documentation of this file.
1/**
2 * @file addons/cpp/mixins/meta/cursor.hpp
3 * @brief Cursor for reading/writing dynamic values.
4 */
5
6#pragma once
7
8namespace flecs {
9
10/**
11 * @defgroup cpp_addons_meta Meta
12 * @ingroup cpp_addons
13 * Flecs reflection framework.
14 *
15 * @{
16 */
17
18/** Class for reading/writing dynamic values.
19 *
20 * @ingroup cpp_addons_meta
21 */
22struct cursor {
23 cursor(flecs::world_t *world, flecs::entity_t type_id, void *ptr) {
24 cursor_ = ecs_meta_cursor(world, type_id, ptr);
25 }
26
27 /** Push a value scope (such as a nested struct). */
28 int push() {
29 return ecs_meta_push(&cursor_);
30 }
31
32 /** Pop a value scope. */
33 int pop() {
34 return ecs_meta_pop(&cursor_);
35 }
36
37 /** Move to the next member/element. */
38 int next() {
39 return ecs_meta_next(&cursor_);
40 }
41
42 /** Move to a member by name. */
43 int member(const char *name) {
44 return ecs_meta_member(&cursor_, name);
45 }
46
47 /** Move to an element by index. */
48 int elem(int32_t elem) {
49 return ecs_meta_elem(&cursor_, elem);
50 }
51
52 /** Test if the current scope is a collection type. */
55 }
56
57 /** Get the member name. */
60 }
61
62 /** Get the type of a value. */
63 flecs::entity get_type() const;
64
65 /** Get the unit of a value. */
66 flecs::entity get_unit() const;
67
68 /** Get an untyped pointer to a value. */
69 void* get_ptr() {
71 }
72
73 /** Set boolean value. */
74 int set_bool(bool value) {
75 return ecs_meta_set_bool(&cursor_, value);
76 }
77
78 /** Set char value. */
79 int set_char(char value) {
80 return ecs_meta_set_char(&cursor_, value);
81 }
82
83 /** Set signed int value. */
84 int set_int(int64_t value) {
85 return ecs_meta_set_int(&cursor_, value);
86 }
87
88 /** Set unsigned int value. */
89 int set_uint(uint64_t value) {
90 return ecs_meta_set_uint(&cursor_, value);
91 }
92
93 /** Set float value. */
94 int set_float(double value) {
95 return ecs_meta_set_float(&cursor_, value);
96 }
97
98 /** Set string value. */
99 int set_string(const char *value) {
100 return ecs_meta_set_string(&cursor_, value);
101 }
102
103 /** Set string literal value. */
104 int set_string_literal(const char *value) {
105 return ecs_meta_set_string_literal(&cursor_, value);
106 }
107
108 /** Set entity value. */
110 return ecs_meta_set_entity(&cursor_, value);
111 }
112
113 /** Set (component) ID value. */
114 int set_id(flecs::id_t value) {
115 return ecs_meta_set_id(&cursor_, value);
116 }
117
118 /** Set null value. */
119 int set_null() {
120 return ecs_meta_set_null(&cursor_);
121 }
122
123 /** Get boolean value. */
124 bool get_bool() const {
125 return ecs_meta_get_bool(&cursor_);
126 }
127
128 /** Get char value. */
129 char get_char() const {
130 return ecs_meta_get_char(&cursor_);
131 }
132
133 /** Get signed int value. */
134 int64_t get_int() const {
135 return ecs_meta_get_int(&cursor_);
136 }
137
138 /** Get unsigned int value. */
139 uint64_t get_uint() const {
140 return ecs_meta_get_uint(&cursor_);
141 }
142
143 /** Get float value. */
144 double get_float() const {
146 }
147
148 /** Get string value. */
149 const char *get_string() const {
151 }
152
153 /** Get entity value. */
155
156 /** Cursor object. */
158};
159
160/** @} */
161
162}
FLECS_API int ecs_meta_set_int(ecs_meta_cursor_t *cursor, int64_t value)
Set field with int value.
FLECS_API int ecs_meta_next(ecs_meta_cursor_t *cursor)
Move cursor to next field.
FLECS_API int ecs_meta_set_uint(ecs_meta_cursor_t *cursor, uint64_t value)
Set field with uint value.
FLECS_API bool ecs_meta_get_bool(const ecs_meta_cursor_t *cursor)
Get field value as boolean.
FLECS_API int ecs_meta_set_string_literal(ecs_meta_cursor_t *cursor, const char *value)
Set field with string literal value (has enclosing "").
FLECS_API int ecs_meta_set_float(ecs_meta_cursor_t *cursor, double value)
Set field with float value.
FLECS_API bool ecs_meta_is_collection(const ecs_meta_cursor_t *cursor)
Is the current scope a collection?
FLECS_API int ecs_meta_set_id(ecs_meta_cursor_t *cursor, ecs_id_t value)
Set field with (component) ID value.
FLECS_API ecs_meta_cursor_t ecs_meta_cursor(const ecs_world_t *world, ecs_entity_t type, void *ptr)
Create meta cursor.
FLECS_API const char * ecs_meta_get_string(const ecs_meta_cursor_t *cursor)
Get field value as string.
FLECS_API const char * ecs_meta_get_member(const ecs_meta_cursor_t *cursor)
Get member name of current field.
FLECS_API double ecs_meta_get_float(const ecs_meta_cursor_t *cursor)
Get field value as float.
FLECS_API int ecs_meta_pop(ecs_meta_cursor_t *cursor)
Pop a struct or collection scope (must follow a push).
FLECS_API uint64_t ecs_meta_get_uint(const ecs_meta_cursor_t *cursor)
Get field value as unsigned integer.
FLECS_API char ecs_meta_get_char(const ecs_meta_cursor_t *cursor)
Get field value as char.
FLECS_API int ecs_meta_elem(ecs_meta_cursor_t *cursor, int32_t elem)
Move cursor to a field.
FLECS_API int64_t ecs_meta_get_int(const ecs_meta_cursor_t *cursor)
Get field value as signed integer.
FLECS_API int ecs_meta_set_string(ecs_meta_cursor_t *cursor, const char *value)
Set field with string value.
FLECS_API int ecs_meta_member(ecs_meta_cursor_t *cursor, const char *name)
Move cursor to member.
FLECS_API int ecs_meta_set_bool(ecs_meta_cursor_t *cursor, bool value)
Set field with boolean value.
FLECS_API int ecs_meta_set_char(ecs_meta_cursor_t *cursor, char value)
Set field with char value.
FLECS_API void * ecs_meta_get_ptr(ecs_meta_cursor_t *cursor)
Get pointer to current field.
FLECS_API int ecs_meta_set_null(ecs_meta_cursor_t *cursor)
Set field with null value.
FLECS_API int ecs_meta_set_entity(ecs_meta_cursor_t *cursor, ecs_entity_t value)
Set field with entity value.
FLECS_API int ecs_meta_push(ecs_meta_cursor_t *cursor)
Push a scope (required and only valid for structs and collections).
ecs_id_t id_t
ID type.
Definition c_types.hpp:20
ecs_entity_t entity_t
Entity type.
Definition c_types.hpp:21
ecs_world_t world_t
World type.
Definition c_types.hpp:18
Type that enables iterating and populating a value using reflection data.
Definition meta.h:635
flecs::entity get_type() const
Get the type of a value.
Definition impl.hpp:95
int set_bool(bool value)
Set boolean value.
Definition cursor.hpp:74
int set_string_literal(const char *value)
Set string literal value.
Definition cursor.hpp:104
const char * get_string() const
Get string value.
Definition cursor.hpp:149
int set_int(int64_t value)
Set signed int value.
Definition cursor.hpp:84
int member(const char *name)
Move to a member by name.
Definition cursor.hpp:43
uint64_t get_uint() const
Get unsigned int value.
Definition cursor.hpp:139
char get_char() const
Get char value.
Definition cursor.hpp:129
int elem(int32_t elem)
Move to an element by index.
Definition cursor.hpp:48
bool get_bool() const
Get boolean value.
Definition cursor.hpp:124
int set_float(double value)
Set float value.
Definition cursor.hpp:94
double get_float() const
Get float value.
Definition cursor.hpp:144
int set_char(char value)
Set char value.
Definition cursor.hpp:79
flecs::string_view get_member() const
Get the member name.
Definition cursor.hpp:58
int set_null()
Set null value.
Definition cursor.hpp:119
bool is_collection()
Test if the current scope is a collection type.
Definition cursor.hpp:53
int push()
Push a value scope (such as a nested struct).
Definition cursor.hpp:28
int set_id(flecs::id_t value)
Set (component) ID value.
Definition cursor.hpp:114
int set_uint(uint64_t value)
Set unsigned int value.
Definition cursor.hpp:89
int set_string(const char *value)
Set string value.
Definition cursor.hpp:99
int pop()
Pop a value scope.
Definition cursor.hpp:33
int64_t get_int() const
Get signed int value.
Definition cursor.hpp:134
flecs::entity get_entity() const
Get entity value.
Definition impl.hpp:103
int set_entity(flecs::entity_t value)
Set entity value.
Definition cursor.hpp:109
int next()
Move to the next member/element.
Definition cursor.hpp:38
flecs::entity get_unit() const
Get the unit of a value.
Definition impl.hpp:99
void * get_ptr()
Get an untyped pointer to a value.
Definition cursor.hpp:69
ecs_meta_cursor_t cursor_
Cursor object.
Definition cursor.hpp:157
Entity.
Definition entity.hpp:30
Non-owning string view.
Definition string.hpp:169
The world.
Definition world.hpp:129