Initial Import
[profile/ivi/json-glib.git] / json-glib / json-types.h
1 /* json-types.h - JSON data types
2  * 
3  * This file is part of JSON-GLib
4  * Copyright (C) 2007  OpenedHand Ltd.
5  * Copyright (C) 2009  Intel Corp.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Author:
21  *   Emmanuele Bassi  <ebassi@linux.intel.com>
22  */
23
24 #if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
25 #error "Only <json-glib/json-glib.h> can be included directly."
26 #endif
27
28 #ifndef __JSON_TYPES_H__
29 #define __JSON_TYPES_H__
30
31 #include <glib-object.h>
32
33 G_BEGIN_DECLS
34
35 /**
36  * JSON_NODE_TYPE:
37  * @node: a #JsonNode
38  *
39  * Evaluates to the #JsonNodeType contained by @node
40  */
41 #define JSON_NODE_TYPE(node)    (json_node_get_node_type ((node)))
42
43 /**
44  * JSON_NODE_HOLDS:
45  * @node: a #JsonNode
46  * @t: a #JsonNodeType
47  *
48  * Evaluates to %TRUE if the @node holds type @t
49  *
50  * Since: 0.10
51  */
52 #define JSON_NODE_HOLDS(node,t)         (json_node_get_node_type ((node)) == (t))
53
54 /**
55  * JSON_NODE_HOLDS_VALUE:
56  * @node: a #JsonNode
57  *
58  * Evaluates to %TRUE if @node holds a %JSON_NODE_VALUE
59  *
60  * Since: 0.10
61  */
62 #define JSON_NODE_HOLDS_VALUE(node)     (JSON_NODE_HOLDS ((node), JSON_NODE_VALUE))
63
64 /**
65  * JSON_NODE_HOLDS_OBJECT:
66  * @node: a #JsonNode
67  *
68  * Evaluates to %TRUE if @node holds a %JSON_NODE_OBJECT
69  *
70  * Since: 0.10
71  */
72 #define JSON_NODE_HOLDS_OBJECT(node)    (JSON_NODE_HOLDS ((node), JSON_NODE_OBJECT))
73
74 /**
75  * JSON_NODE_HOLDS_ARRAY:
76  * @node: a #JsonNode
77  *
78  * Evaluates to %TRUE if @node holds a %JSON_NODE_ARRAY
79  *
80  * Since: 0.10
81  */
82 #define JSON_NODE_HOLDS_ARRAY(node)     (JSON_NODE_HOLDS ((node), JSON_NODE_ARRAY))
83
84 /**
85  * JSON_NODE_HOLDS_NULL:
86  * @node: a #JsonNode
87  *
88  * Evaluates to %TRUE if @node holds a %JSON_NODE_NULL
89  *
90  * Since: 0.10
91  */
92 #define JSON_NODE_HOLDS_NULL(node)      (JSON_NODE_HOLDS ((node), JSON_NODE_NULL))
93
94 #define JSON_TYPE_NODE          (json_node_get_type ())
95 #define JSON_TYPE_OBJECT        (json_object_get_type ())
96 #define JSON_TYPE_ARRAY         (json_array_get_type ())
97
98 /**
99  * JsonNode:
100  *
101  * A generic container of JSON data types. The contents of the #JsonNode
102  * structure are private and should only be accessed via the provided
103  * functions and never directly.
104  */
105 typedef struct _JsonNode        JsonNode;
106
107 /**
108  * JsonObject:
109  *
110  * A JSON object type. The contents of the #JsonObject structure are private
111  * and should only be accessed by the provided API
112  */
113 typedef struct _JsonObject      JsonObject;
114
115 /**
116  * JsonArray:
117  *
118  * A JSON array type. The contents of the #JsonArray structure are private
119  * and should only be accessed by the provided API
120  */
121 typedef struct _JsonArray       JsonArray;
122
123 /**
124  * JsonNodeType:
125  * @JSON_NODE_OBJECT: The node contains a #JsonObject
126  * @JSON_NODE_ARRAY: The node contains a #JsonArray
127  * @JSON_NODE_VALUE: The node contains a fundamental type
128  * @JSON_NODE_NULL: Special type, for nodes containing null
129  *
130  * Indicates the content of a #JsonNode.
131  */
132 typedef enum {
133   JSON_NODE_OBJECT,
134   JSON_NODE_ARRAY,
135   JSON_NODE_VALUE,
136   JSON_NODE_NULL
137 } JsonNodeType;
138
139 /**
140  * JsonObjectForeach:
141  * @object: the iterated #JsonObject
142  * @member_name: the name of the member
143  * @member_node: a #JsonNode containing the @member_name value
144  * @user_data: data passed to the function
145  *
146  * The function to be passed to json_object_foreach_member(). You
147  * should not add or remove members to and from @object within
148  * this function. It is safe to change the value of @member_node.
149  *
150  * Since: 0.8
151  */
152 typedef void (* JsonObjectForeach) (JsonObject  *object,
153                                     const gchar *member_name,
154                                     JsonNode    *member_node,
155                                     gpointer     user_data);
156
157 /**
158  * JsonArrayForeach:
159  * @array: the iterated #JsonArray
160  * @index_: the index of the element
161  * @element_node: a #JsonNode containing the value at @index_
162  * @user_data: data passed to the function
163  *
164  * The function to be passed to json_array_foreach_element(). You
165  * should not add or remove elements to and from @array within
166  * this function. It is safe to change the value of @element_node.
167  *
168  * Since: 0.8
169  */
170 typedef void (* JsonArrayForeach) (JsonArray  *array,
171                                    guint       index_,
172                                    JsonNode   *element_node,
173                                    gpointer    user_data);
174
175 /*
176  * JsonNode
177  */
178 GType                 json_node_get_type        (void) G_GNUC_CONST;
179 JsonNode *            json_node_new             (JsonNodeType  type);
180 JsonNode *            json_node_copy            (JsonNode     *node);
181 void                  json_node_free            (JsonNode     *node);
182 JsonNodeType          json_node_get_node_type   (JsonNode     *node);
183 GType                 json_node_get_value_type  (JsonNode     *node);
184 void                  json_node_set_parent      (JsonNode     *node,
185                                                  JsonNode     *parent);
186 JsonNode *            json_node_get_parent      (JsonNode     *node);
187 const gchar *         json_node_type_name       (JsonNode     *node);
188
189 void                  json_node_set_object      (JsonNode     *node,
190                                                  JsonObject   *object);
191 void                  json_node_take_object     (JsonNode     *node,
192                                                  JsonObject   *object);
193 JsonObject *          json_node_get_object      (JsonNode     *node);
194 JsonObject *          json_node_dup_object      (JsonNode     *node);
195 void                  json_node_set_array       (JsonNode     *node,
196                                                  JsonArray    *array);
197 void                  json_node_take_array      (JsonNode     *node,
198                                                  JsonArray    *array);
199 JsonArray *           json_node_get_array       (JsonNode     *node);
200 JsonArray *           json_node_dup_array       (JsonNode     *node);
201 void                  json_node_set_value       (JsonNode     *node,
202                                                  const GValue *value);
203 void                  json_node_get_value       (JsonNode     *node,
204                                                  GValue       *value);
205 void                  json_node_set_string      (JsonNode     *node,
206                                                  const gchar  *value);
207 const gchar *         json_node_get_string      (JsonNode     *node);
208 gchar *               json_node_dup_string      (JsonNode     *node);
209 void                  json_node_set_int         (JsonNode     *node,
210                                                  gint64        value);
211 gint64                json_node_get_int         (JsonNode     *node);
212 void                  json_node_set_double      (JsonNode     *node,
213                                                  gdouble       value);
214 gdouble               json_node_get_double      (JsonNode     *node);
215 void                  json_node_set_boolean     (JsonNode     *node,
216                                                  gboolean      value);
217 gboolean              json_node_get_boolean     (JsonNode     *node);
218 gboolean              json_node_is_null         (JsonNode     *node);
219
220 /*
221  * JsonObject
222  */
223 GType                 json_object_get_type           (void) G_GNUC_CONST;
224 JsonObject *          json_object_new                (void);
225 JsonObject *          json_object_ref                (JsonObject  *object);
226 void                  json_object_unref              (JsonObject  *object);
227
228 #ifndef JSON_DISABLE_DEPRECATED
229 void                  json_object_add_member         (JsonObject  *object,
230                                                       const gchar *member_name,
231                                                       JsonNode    *node) G_GNUC_DEPRECATED;
232 #endif /* JSON_DISABLE_DEPRECATED */
233
234 void                  json_object_set_member         (JsonObject  *object,
235                                                       const gchar *member_name,
236                                                       JsonNode    *node);
237 void                  json_object_set_int_member     (JsonObject  *object,
238                                                       const gchar *member_name,
239                                                       gint64       value);
240 void                  json_object_set_double_member  (JsonObject  *object,
241                                                       const gchar *member_name,
242                                                       gdouble      value);
243 void                  json_object_set_boolean_member (JsonObject  *object,
244                                                       const gchar *member_name,
245                                                       gboolean     value);
246 void                  json_object_set_string_member  (JsonObject  *object,
247                                                       const gchar *member_name,
248                                                       const gchar *value);
249 void                  json_object_set_null_member    (JsonObject  *object,
250                                                       const gchar *member_name);
251 void                  json_object_set_array_member   (JsonObject  *object,
252                                                       const gchar *member_name,
253                                                       JsonArray   *value);
254 void                  json_object_set_object_member  (JsonObject  *object,
255                                                       const gchar *member_name,
256                                                       JsonObject  *value);
257 GList *               json_object_get_members        (JsonObject  *object);
258 JsonNode *            json_object_get_member         (JsonObject  *object,
259                                                       const gchar *member_name);
260 JsonNode *            json_object_dup_member         (JsonObject  *object,
261                                                       const gchar *member_name);
262 gint64                json_object_get_int_member     (JsonObject  *object,
263                                                       const gchar *member_name);
264 gdouble               json_object_get_double_member  (JsonObject  *object,
265                                                       const gchar *member_name);
266 gboolean              json_object_get_boolean_member (JsonObject  *object,
267                                                       const gchar *member_name);
268 const gchar *         json_object_get_string_member  (JsonObject  *object,
269                                                       const gchar *member_name);
270 gboolean              json_object_get_null_member    (JsonObject  *object,
271                                                       const gchar *member_name);
272 JsonArray *           json_object_get_array_member   (JsonObject  *object,
273                                                       const gchar *member_name);
274 JsonObject *          json_object_get_object_member  (JsonObject  *object,
275                                                       const gchar *member_name);
276 gboolean              json_object_has_member         (JsonObject  *object,
277                                                       const gchar *member_name);
278 void                  json_object_remove_member      (JsonObject  *object,
279                                                       const gchar *member_name);
280 GList *               json_object_get_values         (JsonObject  *object);
281 guint                 json_object_get_size           (JsonObject  *object);
282 void                  json_object_foreach_member     (JsonObject  *object,
283                                                       JsonObjectForeach func,
284                                                       gpointer     data);
285
286 GType                 json_array_get_type            (void) G_GNUC_CONST;
287 JsonArray *           json_array_new                 (void);
288 JsonArray *           json_array_sized_new           (guint        n_elements);
289 JsonArray *           json_array_ref                 (JsonArray   *array);
290 void                  json_array_unref               (JsonArray   *array);
291 void                  json_array_add_element         (JsonArray   *array,
292                                                       JsonNode    *node);
293 void                  json_array_add_int_element     (JsonArray   *array,
294                                                       gint64       value);
295 void                  json_array_add_double_element  (JsonArray   *array,
296                                                       gdouble      value);
297 void                  json_array_add_boolean_element (JsonArray   *array,
298                                                       gboolean     value);
299 void                  json_array_add_string_element  (JsonArray   *array,
300                                                       const gchar *value);
301 void                  json_array_add_null_element    (JsonArray   *array);
302 void                  json_array_add_array_element   (JsonArray   *array,
303                                                       JsonArray   *value);
304 void                  json_array_add_object_element  (JsonArray   *array,
305                                                       JsonObject  *value);
306 GList *               json_array_get_elements        (JsonArray   *array);
307 JsonNode *            json_array_get_element         (JsonArray   *array,
308                                                       guint        index_);
309 gint64                json_array_get_int_element     (JsonArray   *array,
310                                                       guint        index_);
311 gdouble               json_array_get_double_element  (JsonArray   *array,
312                                                       guint        index_);
313 gboolean              json_array_get_boolean_element (JsonArray   *array,
314                                                       guint        index_);
315 const gchar *         json_array_get_string_element  (JsonArray   *array,
316                                                       guint        index_);
317 gboolean              json_array_get_null_element    (JsonArray   *array,
318                                                       guint        index_);
319 JsonArray *           json_array_get_array_element   (JsonArray   *array,
320                                                       guint        index_);
321 JsonObject *          json_array_get_object_element  (JsonArray   *array,
322                                                       guint        index_);
323 JsonNode *            json_array_dup_element         (JsonArray   *array,
324                                                       guint        index_);
325 void                  json_array_remove_element      (JsonArray   *array,
326                                                       guint        index_);
327 guint                 json_array_get_length          (JsonArray   *array);
328 void                  json_array_foreach_element     (JsonArray   *array,
329                                                       JsonArrayForeach func,
330                                                       gpointer     data);
331
332 G_END_DECLS
333
334 #endif /* __JSON_TYPES_H__ */