Dumb-ways-to-memorize
2D game
parseobject.h
Go to the documentation of this file.
1 #ifndef __PARSE_OBJECT_H
2 #define __PARSE_OBJECT_H
3 
4 #include <jsmn.h>
5 
6 typedef struct object_s object_t;
7 
8 /**
9  * An object structure that is used for a better parsing system taken from jsmn tokens.
10  *
11  * key + value = single key address + single value address
12  * object = single key + multiple values
13  *
14  * @author Anthony Rios
15  * @date 3/30/2016
16  */
17 
18 struct object_s
19 {
20  object_t *parent; /**< Pointer to Parent Object*/
21  object_t *children; /**< Array of children objects*/
22  jsmntok_t *keys; /**< Array of keys */
23  jsmntok_t *values; /**< Array of values related to those keys */
24  char *name; /**< The name of the object */
25 };
26 
27 /**
28  * Parse to object, this object has no parent.
29  *
30  * @param [in,out] token If non-null, the token that begins with object.
31  * @param [in,out] g_str If non-null, the global string data of given tokens.
32  *
33  * @return null if it fails, else an object_t*.
34  *
35  * @author Anthony Rios
36  * @date 2/1/2016
37  */
38 object_t *ParseToObject(jsmntok_t *token, char *g_str);
39 
40 /**
41  * Searches for the first object in object list that matches name.
42  *
43  * @param [in,out] obj If non-null, the object.
44  * @param [in,out] name If non-null, the name.
45  *
46  * @return null if it fails, else the found object.
47  *
48  * @author Anthony Rios
49  * @date 2/27/2016
50  */
51 object_t *FindObject(object_t *obj, char *name);
52 
53 //Recursive Member Count
54 int CountObjectMembers(object_t *obj, char *g_str);
55 
56 //Recursive Children Count
57 int CountObjectChildren(object_t *obj);
58 
59 // Recursive Print for Objects
60 void PrintObject(object_t *obj, char *g_str);
61 
62 // Copy's object into a object_array ,dynamically allocates if dst not big enough
63 int CopyObjectToObjectArray(object_t **dst, object_t *src, int size);
64 
65 #endif
Definition: jsmn.h:40
int CountObjectChildren(object_t *obj)
Definition: parseobject.c:170
object_t * FindObject(object_t *obj, char *name)
Definition: parseobject.c:120
jsmntok_t * values
Definition: parseobject.h:23
jsmntok_t * keys
Definition: parseobject.h:22
object_t * ParseToObject(jsmntok_t *token, char *g_str)
Definition: parseobject.c:8
void PrintObject(object_t *obj, char *g_str)
Definition: parseobject.c:188
object_t * parent
Definition: parseobject.h:20
int CopyObjectToObjectArray(object_t **dst, object_t *src, int size)
Definition: parseobject.c:237
object_t * children
Definition: parseobject.h:21
int CountObjectMembers(object_t *obj, char *g_str)
Definition: parseobject.c:144
char * name
Definition: parseobject.h:24