libmetaref
|
Extends struct for reflection and runtime analysis. Allows (string like) annotation for struct fields.
Well I want a situation whereby I can assign the values of struct fields without the need to know what field is declared or not. For example to deserialize a json object into a struct in the traditional manner I will be aware of the JSON object structure and the struct fields so I iterate the JSON object and assign match with the struct fields, this requires me to know both the JSON structure and the struct fields, but with this library there is no need to be aware of either of the two a json library that support libmetaref can just simply take your JSON object, struct and assign where appropriate and possibly set non matching field to NULL.
An example is described below.
location.json
The Location struct file:
location_struct.h
Assume a JSON library that add support for libmetaref
json_to_struct.c
In the example above the json library handles the struct field assignment, the json values validation. The example above is a pseudocode it not expected to compile.
Must initialize the struct with calloc to enable all the field values are NULL
Compile time check still happens
It cannot auto detect type of field, esp struct
Functions expecting struct created with metaref should have the _metaref
prefix. E.g.
A function that accept struct not defined with metaref
A function that accept struct defined with metaref