Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
Expr

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_tecs_vars_declare (ecs_vars_t *vars, const char *name, ecs_entity_t type)
 Declare variable in current scope.
 
FLECS_API ecs_expr_var_tecs_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_tecs_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.
 

Detailed Description

Serialize/deserialize values to string.

Typedef Documentation

◆ 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).

Function Documentation

◆ ecs_astresc()

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.

Parameters
delimiterThe delimiter used (for example '"').
inThe input string.
Returns
Escaped string.

◆ ecs_chresc()

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.

Parameters
outThe string to write the character to.
inThe input character.
delimiterThe delimiiter used (for example '"')
Returns
Pointer to the character after the last one written.

◆ ecs_chrparse()

const char * ecs_chrparse ( const char *  in,
char *  out 
)

Parse an escaped character.

Parse a character with a potential escape sequence.

Parameters
inPointer to character in input string.
outOutput string.
Returns
Pointer to the character after the last one read.

◆ ecs_parse_expr()

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.

Parameters
worldThe world.
ptrThe pointer to the expression to parse.
valueThe value containing type & pointer to write to.
descConfiguration parameters for deserializer.
Returns
Pointer to the character after the last one read, or NULL if failed.

◆ ecs_parse_expr_token()

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.

Parameters
nameThe name of the expression (used for debug logs).
exprThe full expression (used for debug logs).
ptrThe pointer to the expression to parse.
tokenThe buffer to write to (must have size ECS_MAX_TOKEN_SIZE)
Returns
Pointer to the character after the last one read, or NULL if failed.

◆ ecs_primitive_to_expr_buf()

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.

Parameters
worldThe world.
kindThe kind of primitive value.
dataThe value ot serialize
bufThe strbuf to append the string to.
Returns
Zero if success, non-zero if failed.

◆ ecs_ptr_to_expr()

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.

Parameters
worldThe world.
typeThe type of the value to serialize.
dataThe value to serialize.
Returns
String with expression, or NULL if failed.

◆ ecs_ptr_to_expr_buf()

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.

Parameters
worldThe world.
typeThe type of the value to serialize.
dataThe value to serialize.
bufThe strbuf to append the string to.
Returns
Zero if success, non-zero if failed.

◆ ecs_stresc()

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.

Parameters
outPointer to output string (msut be).
sizeMaximum number of characters written to output.
delimiterThe delimiter used (for example '"').
inThe input string.
Returns
The number of characters that (would) have been written.

◆ ecs_vars_declare_w_value()

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.