|
Reduct
v4.1.3-1-gd06c383
A functional and immutable language.
|
Schemas provide a way to validate the structure of Reduct association lists and transform them into native C structures.
The reduct_schema_apply() function expects an association list where each key corresponds to a field in the schema and the value is the data for that field.
Arrays are an exception to the above and can be specified in two ways:
("my-key" ("first" "second" "third"))("my-key" "first" "second" "third") Data Structures | |
| struct | reduct_schema_t |
| Schema field structure. More... | |
| struct | reduct_schema_internal_t |
| Internal schema structure. More... | |
| struct | reduct_schema_global_t |
| Global schema-related state structure. More... | |
Macros | |
| #define | REDUCT_SCHEMA_INDEX_NONE ((reduct_schema_index_t) - 1) |
| Invalid schema index. | |
| #define | REDUCT_SCHEMA_FIELD(_key, _struct, _member, _type) |
| Helper macro to define a schema field. | |
| #define | REDUCT_SCHEMA_FIELD_ARRAY(_key, _struct, _member, _subtype) |
| Helper macro to define an array schema field. | |
Typedefs | |
| typedef uint32_t | reduct_schema_id_t |
| Schema ID type. | |
| typedef uint32_t | reduct_schema_index_t |
| Schema index type. | |
Enumerations | |
| enum | reduct_schema_type_t { REDUCT_SCHEMA_TYPE_UINT , REDUCT_SCHEMA_TYPE_INT , REDUCT_SCHEMA_TYPE_FLOAT , REDUCT_SCHEMA_TYPE_BOOL , REDUCT_SCHEMA_TYPE_STRING , REDUCT_SCHEMA_TYPE_HANDLE , REDUCT_SCHEMA_TYPE_ARRAY , REDUCT_SCHEMA_TYPE_ATOM , REDUCT_SCHEMA_TYPE_LIST } |
| Schema type flags. More... | |
Functions | |
| REDUCT_API void | reduct_schema_global_init (reduct_schema_global_t *global) |
| Initialize a global schema state. | |
| REDUCT_API void | reduct_schema_global_deinit (reduct_schema_global_t *global) |
| Deinitialize a global schema state. | |
| REDUCT_API reduct_schema_id_t | reduct_schema_new (struct reduct *reduct, size_t count, const reduct_schema_t *fields) |
| Create a new schema from an array of fields. | |
| REDUCT_API void | reduct_schema_apply (struct reduct *reduct, reduct_schema_id_t id, reduct_handle_t listH, void *out) |
| Apply a schema to an association list and populate a C structure. | |
| REDUCT_API size_t | reduct_schema_get_count (struct reduct *reduct, reduct_schema_id_t id) |
| Get the number of fields in a schema. | |
| REDUCT_API reduct_handle_t | reduct_schema_serialize (struct reduct *reduct, reduct_schema_id_t id, const void *in) |
| Transform a C structure into an association list using a schema. | |
| #define REDUCT_SCHEMA_INDEX_NONE ((reduct_schema_index_t) - 1) |
| #define REDUCT_SCHEMA_FIELD | ( | _key, | |
| _struct, | |||
| _member, | |||
| _type | |||
| ) |
Helper macro to define a schema field.
| _key | The key string in the association list. |
| _struct | The C structure type. |
| _member | The member name in the C structure. |
| _type | The reduct_schema_type_t of the field, only the suffix is required, REDUCT_SCHEMA_TYPE_ is added automatically. |
| #define REDUCT_SCHEMA_FIELD_ARRAY | ( | _key, | |
| _struct, | |||
| _member, | |||
| _subtype | |||
| ) |
Helper macro to define an array schema field.
| _key | The key string. |
| _struct | The C structure type. |
| _member | The array member name. |
| _type | The reduct_schema_type_t of the field, only the suffix is required, REDUCT_SCHEMA_TYPE_ is added automatically. |
| typedef uint32_t reduct_schema_id_t |
| typedef uint32_t reduct_schema_index_t |
| enum reduct_schema_type_t |
Schema type flags.
| Enumerator | |
|---|---|
| REDUCT_SCHEMA_TYPE_UINT | Unsigned integer. |
| REDUCT_SCHEMA_TYPE_INT | Signed integer. |
| REDUCT_SCHEMA_TYPE_FLOAT | Float or double. |
| REDUCT_SCHEMA_TYPE_BOOL | A |
| REDUCT_SCHEMA_TYPE_STRING | An array of characters. |
| REDUCT_SCHEMA_TYPE_HANDLE | |
| REDUCT_SCHEMA_TYPE_ARRAY | A fixed-size array of primitives. |
| REDUCT_SCHEMA_TYPE_ATOM | A pointer to a |
| REDUCT_SCHEMA_TYPE_LIST | A pointer to a |
| REDUCT_API void reduct_schema_global_init | ( | reduct_schema_global_t * | global | ) |
Initialize a global schema state.
| global | Pointer to the global schema state to initialize. |
| REDUCT_API void reduct_schema_global_deinit | ( | reduct_schema_global_t * | global | ) |
Deinitialize a global schema state.
| global | Pointer to the global schema state to deinitialize. |
| REDUCT_API reduct_schema_id_t reduct_schema_new | ( | struct reduct * | reduct, |
| size_t | count, | ||
| const reduct_schema_t * | fields | ||
| ) |
Create a new schema from an array of fields.
| reduct | Pointer to the Reduct structure. |
| count | Number of fields. |
| fields | Array of field definitions. |
| REDUCT_API void reduct_schema_apply | ( | struct reduct * | reduct, |
| reduct_schema_id_t | id, | ||
| reduct_handle_t | listH, | ||
| void * | out | ||
| ) |
Apply a schema to an association list and populate a C structure.
Any fields not explicitly set by the given list are guaranteed to be left untouched.
| reduct | Pointer to the Reduct structure. |
| id | The ID of the schema to apply. |
| listH | The handle to the association list. |
| out | Pointer to the destination C structure. |
| REDUCT_API size_t reduct_schema_get_count | ( | struct reduct * | reduct, |
| reduct_schema_id_t | id | ||
| ) |
Get the number of fields in a schema.
| reduct | Pointer to the Reduct structure. |
| id | The schema ID. |
| REDUCT_API reduct_handle_t reduct_schema_serialize | ( | struct reduct * | reduct, |
| reduct_schema_id_t | id, | ||
| const void * | in | ||
| ) |
Transform a C structure into an association list using a schema.
| reduct | Pointer to the Reduct structure. |
| id | The ID of the schema to use. |
| in | Pointer to the source C structure. |