Flecs v3.2
A fast entity component system (ECS) for C & C++
|
Serialize/deserialize values to string. More...
Classes | |
struct | ecs_expr_var_t |
Storage for parser variables. More... | |
struct | ecs_expr_var_scope_t |
struct | ecs_vars_t |
struct | ecs_parse_expr_desc_t |
Used with ecs_parse_expr(). More... | |
Typedefs | |
typedef struct ecs_expr_var_t | ecs_expr_var_t |
Storage for parser variables. | |
typedef struct ecs_expr_var_scope_t | ecs_expr_var_scope_t |
typedef struct ecs_vars_t | ecs_vars_t |
typedef struct ecs_parse_expr_desc_t | ecs_parse_expr_desc_t |
Used with ecs_parse_expr(). | |
Functions | |
FLECS_API char * | ecs_chresc (char *out, char in, char delimiter) |
Write an escaped character. | |
const char * | ecs_chrparse (const char *in, char *out) |
Parse an escaped character. | |
FLECS_API ecs_size_t | ecs_stresc (char *out, ecs_size_t size, char delimiter, const char *in) |
Write an escaped string. | |
FLECS_API char * | ecs_astresc (char delimiter, const char *in) |
Return escaped string. | |
FLECS_API void | ecs_vars_init (ecs_world_t *world, ecs_vars_t *vars) |
Init variable storage. | |
FLECS_API void | ecs_vars_fini (ecs_vars_t *vars) |
Cleanup variable storage. | |
FLECS_API void | ecs_vars_push (ecs_vars_t *vars) |
Push variable scope. | |
FLECS_API int | ecs_vars_pop (ecs_vars_t *vars) |
Pop variable scope. | |
FLECS_API ecs_expr_var_t * | ecs_vars_declare (ecs_vars_t *vars, const char *name, ecs_entity_t type) |
Declare variable in current scope. | |
FLECS_API ecs_expr_var_t * | ecs_vars_declare_w_value (ecs_vars_t *vars, const char *name, ecs_value_t *value) |
Declare variable in current scope from value. | |
FLECS_API ecs_expr_var_t * | ecs_vars_lookup (const ecs_vars_t *vars, const char *name) |
Lookup variable in scope and parent scopes. | |
FLECS_API const char * | ecs_parse_expr (ecs_world_t *world, const char *ptr, ecs_value_t *value, const ecs_parse_expr_desc_t *desc) |
Parse expression into value. | |
FLECS_API char * | ecs_ptr_to_expr (const ecs_world_t *world, ecs_entity_t type, const void *data) |
Serialize value into expression string. | |
FLECS_API int | ecs_ptr_to_expr_buf (const ecs_world_t *world, ecs_entity_t type, const void *data, ecs_strbuf_t *buf) |
Serialize value into expression buffer. | |
FLECS_API char * | ecs_ptr_to_str (const ecs_world_t *world, ecs_entity_t type, const void *data) |
Similar as ecs_ptr_to_expr(), but serializes values to string. | |
FLECS_API int | ecs_ptr_to_str_buf (const ecs_world_t *world, ecs_entity_t type, const void *data, ecs_strbuf_t *buf) |
Serialize value into string buffer. | |
FLECS_API int | ecs_primitive_to_expr_buf (const ecs_world_t *world, ecs_primitive_kind_t kind, const void *data, ecs_strbuf_t *buf) |
Serialize primitive value into string buffer. | |
FLECS_API const char * | ecs_parse_expr_token (const char *name, const char *expr, const char *ptr, char *token) |
Parse expression token. | |
FLECS_API char * | ecs_interpolate_string (ecs_world_t *world, const char *str, const ecs_vars_t *vars) |
Evaluate interpolated expressions in string. | |
FLECS_API void | ecs_iter_to_vars (const ecs_iter_t *it, ecs_vars_t *vars, int offset) |
Convert iterator to vars This operation converts an iterator to a variable array. | |
Serialize/deserialize values to string.
typedef struct ecs_expr_var_t ecs_expr_var_t |
Storage for parser variables.
Variables make it possible to parameterize expression strings, and are referenced with the $ operator (e.g. $var).
FLECS_API char * ecs_astresc | ( | char | delimiter, |
const char * | in ) |
Return escaped string.
Return escaped version of input string. Same as ecs_stresc(), but returns an allocated string of the right size.
delimiter | The delimiter used (for example '"'). |
in | The input string. |
FLECS_API char * ecs_chresc | ( | char * | out, |
char | in, | ||
char | delimiter ) |
Write an escaped character.
Write a character to an output string, insert escape character if necessary.
out | The string to write the character to. |
in | The input character. |
delimiter | The delimiter used (for example '"') |
const char * ecs_chrparse | ( | const char * | in, |
char * | out ) |
Parse an escaped character.
Parse a character with a potential escape sequence.
in | Pointer to character in input string. |
out | Output string. |
FLECS_API char * ecs_interpolate_string | ( | ecs_world_t * | world, |
const char * | str, | ||
const ecs_vars_t * | vars ) |
Evaluate interpolated expressions in string.
This operation evaluates expressions in a string, and replaces them with their evaluated result. Supported expression formats are:
The $, { and } characters can be escaped with a backslash ().
world | The world. |
str | The string to evaluate. |
vars | The variables to use for evaluation. |
FLECS_API void ecs_iter_to_vars | ( | const ecs_iter_t * | it, |
ecs_vars_t * | vars, | ||
int | offset ) |
Convert iterator to vars This operation converts an iterator to a variable array.
This allows for using iterator results in expressions. The operation only converts a single result at a time, and does not progress the iterator.
Iterator fields with data will be made available as variables with as name the field index (e.g. "$1"). The operation does not check if reflection data is registered for a field type. If no reflection data is registered for the type, using the field variable in expressions will fail.
Field variables will only contain single elements, even if the iterator returns component arrays. The offset parameter can be used to specify which element in the component arrays to return. The offset parameter must be smaller than it->count.
The operation will create a variable for query variables that contain a single entity.
The operation will attempt to use existing variables. If a variable does not yet exist, the operation will create it. If an existing variable exists with a mismatching type, the operation will fail.
Accessing variables after progressing the iterator or after the iterator is destroyed will result in undefined behavior.
If vars contains a variable that is not present in the iterator, the variable will not be modified.
it | The iterator to convert to variables. |
vars | The variables to write to. |
offset | The offset to the current element. |
FLECS_API const char * ecs_parse_expr | ( | ecs_world_t * | world, |
const char * | ptr, | ||
ecs_value_t * | value, | ||
const ecs_parse_expr_desc_t * | desc ) |
Parse expression into value.
This operation parses a flecs expression into the provided pointer. The memory pointed to must be large enough to contain a value of the used type.
If no type and pointer are provided for the value argument, the operation will discover the type from the expression and allocate storage for the value. The allocated value must be freed with ecs_value_free().
world | The world. |
ptr | The pointer to the expression to parse. |
value | The value containing type & pointer to write to. |
desc | Configuration parameters for deserializer. |
FLECS_API const char * ecs_parse_expr_token | ( | const char * | name, |
const char * | expr, | ||
const char * | ptr, | ||
char * | token ) |
Parse expression token.
Expression tokens can contain more characters (such as '|') than tokens parsed by the query (term) parser.
name | The name of the expression (used for debug logs). |
expr | The full expression (used for debug logs). |
ptr | The pointer to the expression to parse. |
token | The buffer to write to (must have size ECS_MAX_TOKEN_SIZE) |
FLECS_API int ecs_primitive_to_expr_buf | ( | const ecs_world_t * | world, |
ecs_primitive_kind_t | kind, | ||
const void * | data, | ||
ecs_strbuf_t * | buf ) |
Serialize primitive value into string buffer.
Serializes a primitive value to an ecs_strbuf_t instance. This operation can be reused by other serializers to avoid having to write boilerplate code that serializes primitive values to a string.
world | The world. |
kind | The kind of primitive value. |
data | The value to serialize |
buf | The strbuf to append the string to. |
FLECS_API char * ecs_ptr_to_expr | ( | const ecs_world_t * | world, |
ecs_entity_t | type, | ||
const void * | data ) |
Serialize value into expression string.
This operation serializes a value of the provided type to a string. The memory pointed to must be large enough to contain a value of the used type.
world | The world. |
type | The type of the value to serialize. |
data | The value to serialize. |
FLECS_API int ecs_ptr_to_expr_buf | ( | const ecs_world_t * | world, |
ecs_entity_t | type, | ||
const void * | data, | ||
ecs_strbuf_t * | buf ) |
Serialize value into expression buffer.
Same as ecs_ptr_to_expr(), but serializes to an ecs_strbuf_t instance.
world | The world. |
type | The type of the value to serialize. |
data | The value to serialize. |
buf | The strbuf to append the string to. |
FLECS_API char * ecs_ptr_to_str | ( | const ecs_world_t * | world, |
ecs_entity_t | type, | ||
const void * | data ) |
Similar as ecs_ptr_to_expr(), but serializes values to string.
Whereas the output of ecs_ptr_to_expr() is a valid expression, the output of ecs_ptr_to_str() is a string representation of the value. In most cases the output of the two operations is the same, but there are some differences:
world | The world. |
type | The type of the value to serialize. |
data | The value to serialize. |
FLECS_API int ecs_ptr_to_str_buf | ( | const ecs_world_t * | world, |
ecs_entity_t | type, | ||
const void * | data, | ||
ecs_strbuf_t * | buf ) |
Serialize value into string buffer.
Same as ecs_ptr_to_str(), but serializes to an ecs_strbuf_t instance.
world | The world. |
type | The type of the value to serialize. |
data | The value to serialize. |
buf | The strbuf to append the string to. |
FLECS_API ecs_size_t ecs_stresc | ( | char * | out, |
ecs_size_t | size, | ||
char | delimiter, | ||
const char * | in ) |
Write an escaped string.
Write an input string to an output string, escape characters where necessary. To determine the size of the output string, call the operation with a NULL argument for 'out', and use the returned size to allocate a string that is large enough.
out | Pointer to output string (must be). |
size | Maximum number of characters written to output. |
delimiter | The delimiter used (for example '"'). |
in | The input string. |
FLECS_API ecs_expr_var_t * ecs_vars_declare_w_value | ( | ecs_vars_t * | vars, |
const char * | name, | ||
ecs_value_t * | value ) |
Declare variable in current scope from value.
This operation takes ownership of the value. The value pointer must be allocated with ecs_value_new().