123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- #ifndef YAJL_TREE_H
- #define YAJL_TREE_H 1
- #include "yajl_common.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef enum {
- yajl_t_string = 1,
- yajl_t_number = 2,
- yajl_t_object = 3,
- yajl_t_array = 4,
- yajl_t_true = 5,
- yajl_t_false = 6,
- yajl_t_null = 7,
-
- yajl_t_any = 8
- } yajl_type;
- #define YAJL_NUMBER_INT_VALID 0x01
- #define YAJL_NUMBER_DOUBLE_VALID 0x02
- #define YAJL_NUMBER_UINT_VALID 0x04
- typedef struct yajl_val_s * yajl_val;
- struct yajl_val_s
- {
-
- yajl_type type;
-
- union
- {
- char * string;
- struct {
- long long i;
- unsigned long long ui;
- double d;
- char *r;
-
- unsigned int flags;
- } number;
- struct {
- const char **keys;
- yajl_val *values;
- size_t len;
- } object;
- struct {
- yajl_val *values;
- size_t len;
- } array;
- } u;
- };
- YAJL_API yajl_val yajl_tree_parse (const char *input,
- char *error_buffer, size_t error_buffer_size);
- YAJL_API void yajl_tree_free (yajl_val v);
- YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type);
- #define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
- #define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
- #define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
- #define YAJL_IS_UINTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_UINT_VALID))
- #define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_DOUBLE_VALID))
- #define YAJL_IS_OBJECT(v) (((v) != NULL) && ((v)->type == yajl_t_object))
- #define YAJL_IS_ARRAY(v) (((v) != NULL) && ((v)->type == yajl_t_array ))
- #define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
- #define YAJL_IS_FALSE(v) (((v) != NULL) && ((v)->type == yajl_t_false ))
- #define YAJL_IS_NULL(v) (((v) != NULL) && ((v)->type == yajl_t_null ))
- #define YAJL_GET_STRING(v) (YAJL_IS_STRING(v) ? (v)->u.string : NULL)
- #define YAJL_GET_NUMBER(v) ((v)->u.number.r)
- #define YAJL_GET_DOUBLE(v) ((v)->u.number.d)
- #define YAJL_GET_INTEGER(v) ((v)->u.number.i)
- #define YAJL_GET_UINTEGER(v) ((v)->u.number.ui)
- #define YAJL_GET_OBJECT(v) (YAJL_IS_OBJECT(v) ? &(v)->u.object : NULL)
- #define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
- #ifdef __cplusplus
- }
- #endif
- #endif
|