json-gen-c  0.1.5
json-gen-c generate C code for json manipulation
struct_parse.h File Reference

Parse struct definitions. Support scalar types(int, long, float, double, sstr_t), arrays, structs. More...

#include <stddef.h>
#include "utils/hash_map.h"
#include "utils/sstr.h"
Include dependency graph for struct_parse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  struct_field
 structure to store field list of parsed structs. A struct may have multiple field, and each field may be an array, or a struct. We use a single linked list to store the fields of a struct. More...
 
struct  struct_container
 structure to store parsed structs. A struct may have multiple fields, we put fields in a linked list. More...
 
struct  pos
 position of string More...
 
struct  struct_parser
 parser context More...
 
struct  struct_token
 token More...
 

Macros

#define FIELD_TYPE_INT   0
 
#define FIELD_TYPE_LONG   1
 
#define FIELD_TYPE_FLOAT   2
 
#define FIELD_TYPE_DOUBLE   3
 
#define FIELD_TYPE_SSTR   4
 
#define FIELD_TYPE_STRUCT   6
 
#define FIELD_TYPE_BOOL   7
 
#define TYPE_NAME_INT   "int"
 
#define TYPE_NAME_BOOL   "bool"
 
#define TYPE_NAME_SSTR   "sstr_t"
 
#define TYPE_NAME_LONG   "long"
 
#define TYPE_NAME_FLOAT   "float"
 
#define TYPE_NAME_DOUBLE   "double"
 
#define STRUCT_MAP_BUCKET_SIZE   4096
 We use a hash map to store parsed structs, and use the struct name as the key. This is the size of the hash map's bucket.
 
#define TOKEN_LEFT_BRACE   '{'
 
#define TOKEN_RIGHT_BRACE   '}'
 
#define TOKEN_LEFT_BRACKET   '['
 
#define TOKEN_RIGHT_BRACKET   ']'
 
#define TOKEN_SEMICOLON   ';'
 
#define TOKEN_SHARPE   '#'
 
#define TOKEN_STRING   4
 
#define TOKEN_IDENTIFY   1
 
#define TOKEN_INTEGER   2
 
#define TOKEN_FLOAT   3
 
#define TOKEN_EOF   0
 
#define TOKEN_ERROR   -1
 

Functions

struct struct_parserstruct_parser_new ()
 create and init a struct_parser instance. More...
 
void struct_parser_free (struct struct_parser *parser)
 free a struct_parser instance. More...
 
int struct_parser_parse (struct struct_parser *parser, sstr_t content)
 parse a struct definition file, and store the parsed structs in struct_parser. More...
 

Detailed Description

Parse struct definitions. Support scalar types(int, long, float, double, sstr_t), arrays, structs.

Function Documentation

◆ struct_parser_free()

void struct_parser_free ( struct struct_parser parser)

free a struct_parser instance.

Parameters
parserstruct struct_parser*

◆ struct_parser_new()

struct struct_parser* struct_parser_new ( )

create and init a struct_parser instance.

Returns
struct struct_parser* if success, NULL otherwise.

◆ struct_parser_parse()

int struct_parser_parse ( struct struct_parser parser,
sstr_t  content 
)

parse a struct definition file, and store the parsed structs in struct_parser.

Parameters
parsercontext of parser.
contentcontent of the file.
Returns
int 0 if success, -1 otherwise.