YAJL 2.1.0
yajl_tree.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2011 Florian Forster <ff at octo.it>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
31#ifndef YAJL_TREE_H
32#define YAJL_TREE_H 1
33
34#include <yajl/yajl_common.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
41typedef enum {
52 yajl_t_any = 8
54
55#define YAJL_NUMBER_INT_VALID 0x01
56#define YAJL_NUMBER_DOUBLE_VALID 0x02
57
59typedef struct yajl_val_s * yajl_val;
60
69{
75 union
76 {
77 char * string;
78 struct {
79 long long i; /*< integer value, if representable. */
80 double d; /*< double value, if representable. */
81 char *r; /*< unparsed number in string form. */
85 unsigned int flags;
87 struct {
88 const char **keys; /*< Array of keys */
89 yajl_val *values; /*< Array of values. */
90 size_t len; /*< Number of key-value-pairs. */
92 struct {
93 yajl_val *values; /*< Array of elements. */
94 size_t len; /*< Number of elements. */
96 } u;
97};
98
122 char *error_buffer, size_t error_buffer_size);
123
124
132
147YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type);
148
149/* Various convenience macros to check the type of a `yajl_val` */
150#define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string))
151#define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number))
152#define YAJL_IS_INTEGER(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_INT_VALID))
153#define YAJL_IS_DOUBLE(v) (YAJL_IS_NUMBER(v) && ((v)->u.number.flags & YAJL_NUMBER_DOUBLE_VALID))
154#define YAJL_IS_OBJECT(v) (((v) != NULL) && ((v)->type == yajl_t_object))
155#define YAJL_IS_ARRAY(v) (((v) != NULL) && ((v)->type == yajl_t_array ))
156#define YAJL_IS_TRUE(v) (((v) != NULL) && ((v)->type == yajl_t_true ))
157#define YAJL_IS_FALSE(v) (((v) != NULL) && ((v)->type == yajl_t_false ))
158#define YAJL_IS_NULL(v) (((v) != NULL) && ((v)->type == yajl_t_null ))
159
162#define YAJL_GET_STRING(v) (YAJL_IS_STRING(v) ? (v)->u.string : NULL)
163
166#define YAJL_GET_NUMBER(v) ((v)->u.number.r)
167
170#define YAJL_GET_DOUBLE(v) ((v)->u.number.d)
171
174#define YAJL_GET_INTEGER(v) ((v)->u.number.i)
175
177#define YAJL_GET_OBJECT(v) (YAJL_IS_OBJECT(v) ? &(v)->u.object : NULL)
178
180#define YAJL_GET_ARRAY(v) (YAJL_IS_ARRAY(v) ? &(v)->u.array : NULL)
181
182#ifdef __cplusplus
183}
184#endif
185
186#endif /* YAJL_TREE_H */
Definition yajl_tree.h:69
struct yajl_val_s::@0::@2 object
size_t len
Definition yajl_tree.h:90
unsigned int flags
Definition yajl_tree.h:85
union yajl_val_s::@0 u
long long i
Definition yajl_tree.h:79
yajl_type type
Definition yajl_tree.h:72
struct yajl_val_s::@0::@1 number
char * string
Definition yajl_tree.h:77
struct yajl_val_s::@0::@3 array
const char ** keys
Definition yajl_tree.h:88
double d
Definition yajl_tree.h:80
char * r
Definition yajl_tree.h:81
yajl_val * values
Definition yajl_tree.h:89
#define YAJL_API
Definition yajl_common.h:41
YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char **path, yajl_type type)
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_type
Definition yajl_tree.h:41
@ yajl_t_object
Definition yajl_tree.h:44
@ yajl_t_false
Definition yajl_tree.h:47
@ yajl_t_true
Definition yajl_tree.h:46
@ yajl_t_string
Definition yajl_tree.h:42
@ yajl_t_any
Definition yajl_tree.h:52
@ yajl_t_array
Definition yajl_tree.h:45
@ yajl_t_null
Definition yajl_tree.h:48
@ yajl_t_number
Definition yajl_tree.h:43
struct yajl_val_s * yajl_val
Definition yajl_tree.h:59