yajl_tree.h
Go to the documentation of this file.
/*
* Copyright (c) 2010-2011 Florian Forster <ff at octo.it>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef YAJL_TREE_H
#define YAJL_TREE_H 1
#include <yajl/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
typedef struct yajl_val_s * yajl_val;
struct yajl_val_s
{
yajl_type type;
union
{
char * string;
struct {
long long i; /*< integer value, if representable. */
double d; /*< double value, if representable. */
char *r; /*< unparsed number in string form. */
unsigned int flags;
} number;
struct {
const char **keys; /*< Array of keys */
yajl_val *values; /*< Array of values. */
size_t len; /*< Number of key-value-pairs. */
} object;
struct {
yajl_val *values; /*< Array of elements. */
size_t len; /*< Number of elements. */
} 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);
/* Various convenience macros to check the type of a `yajl_val` */
#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_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_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 /* YAJL_TREE_H */
yajl_val_s
Definition yajl_tree.h:69
yajl_val_s::len
size_t len
Definition yajl_tree.h:90
yajl_val_s::number
struct yajl_val_s::@230155355363255211045346201324045154011333244046::@104016307225354171273016143245124103264330156313 number
yajl_val_s::flags
unsigned int flags
Definition yajl_tree.h:85
yajl_val_s::object
struct yajl_val_s::@230155355363255211045346201324045154011333244046::@305112272221006147277276356167032300026105327337 object
yajl_val_s::array
struct yajl_val_s::@230155355363255211045346201324045154011333244046::@175362216347216241354031101115264055057377114307 array
yajl_val_s::i
long long i
Definition yajl_tree.h:79
yajl_val_s::type
yajl_type type
Definition yajl_tree.h:72
yajl_val_s::u
union yajl_val_s::@230155355363255211045346201324045154011333244046 u
yajl_val_s::string
char * string
Definition yajl_tree.h:77
yajl_val_s::keys
const char ** keys
Definition yajl_tree.h:88
yajl_val_s::d
double d
Definition yajl_tree.h:80
yajl_val_s::r
char * r
Definition yajl_tree.h:81
yajl_val_s::values
yajl_val * values
Definition yajl_tree.h:89
YAJL_API
#define YAJL_API
Definition yajl_common.h:41
yajl_tree_get
YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char **path, yajl_type type)
yajl_tree_parse
YAJL_API yajl_val yajl_tree_parse(const char *input, char *error_buffer, size_t error_buffer_size)
yajl_tree_free
YAJL_API void yajl_tree_free(yajl_val v)
yajl_type
yajl_type
Definition yajl_tree.h:41
yajl_t_object
@ yajl_t_object
Definition yajl_tree.h:44
yajl_t_false
@ yajl_t_false
Definition yajl_tree.h:47
yajl_t_true
@ yajl_t_true
Definition yajl_tree.h:46
yajl_t_string
@ yajl_t_string
Definition yajl_tree.h:42
yajl_t_any
@ yajl_t_any
Definition yajl_tree.h:52
yajl_t_array
@ yajl_t_array
Definition yajl_tree.h:45
yajl_t_null
@ yajl_t_null
Definition yajl_tree.h:48
yajl_t_number
@ yajl_t_number
Definition yajl_tree.h:43
yajl_val
struct yajl_val_s * yajl_val
Definition yajl_tree.h:59