![]() |
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 (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 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. | |
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 delimiiter 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 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 ot 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 string 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 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 (msut 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.