Initial Import
[profile/ivi/json-glib.git] / json-glib / json-reader.h
1 /* json-reader.h - JSON cursor parser
2  * 
3  * This file is part of JSON-GLib
4  * Copyright (C) 2010  Intel Corp.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Author:
20  *   Emmanuele Bassi  <ebassi@linux.intel.com>
21  */
22
23 #if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
24 #error "Only <json-glib/json-glib.h> can be included directly."
25 #endif
26
27 #ifndef __JSON_READER_H__
28 #define __JSON_READER_H__
29
30 #include <json-glib/json-types.h>
31
32 G_BEGIN_DECLS
33
34 #define JSON_TYPE_READER                (json_reader_get_type ())
35 #define JSON_READER(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), JSON_TYPE_READER, JsonReader))
36 #define JSON_IS_READER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JSON_TYPE_READER))
37 #define JSON_READER_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), JSON_TYPE_READER, JsonReaderClass))
38 #define JSON_IS_READER_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), JSON_TYPE_READER))
39 #define JSON_READER_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), JSON_TYPE_READER, JsonReaderClass))
40
41 /**
42  * JSON_READER_ERROR:
43  *
44  * Error domain for #JsonReader errors
45  *
46  * Since: 0.12
47  */
48 #define JSON_READER_ERROR               (json_reader_error_quark ())
49
50 typedef struct _JsonReader              JsonReader;
51 typedef struct _JsonReaderPrivate       JsonReaderPrivate;
52 typedef struct _JsonReaderClass         JsonReaderClass;
53
54 /**
55  * JsonReaderError:
56  * @JSON_READER_ERROR_NO_ARRAY: No array found at the current position
57  * @JSON_READER_ERROR_INVALID_INDEX: Index out of bounds
58  * @JSON_READER_ERROR_NO_OBJECT: No object found at the current position
59  * @JSON_READER_ERROR_INVALID_MEMBER: Member not found
60  * @JSON_READER_ERROR_INVALID_NODE: No valid node found at the current position
61  * @JSON_READER_ERROR_NO_VALUE: The node at the current position does not
62  *   hold a value
63  * @JSON_READER_ERROR_INVALID_TYPE: The node at the current position does not
64  *   hold a value of the desired type
65  *
66  * Error codes enumeration for #JsonReader errors
67  *
68  * Since: 0.12
69  */
70 typedef enum {
71   JSON_READER_ERROR_NO_ARRAY,
72   JSON_READER_ERROR_INVALID_INDEX,
73   JSON_READER_ERROR_NO_OBJECT,
74   JSON_READER_ERROR_INVALID_MEMBER,
75   JSON_READER_ERROR_INVALID_NODE,
76   JSON_READER_ERROR_NO_VALUE,
77   JSON_READER_ERROR_INVALID_TYPE
78 } JsonReaderError;
79
80 /**
81  * JsonReader:
82  *
83  * The <structname>JsonReader</structname> structure contains only
84  * private data and should only be accessed using the provided API
85  *
86  * Since: 0.12
87  */
88 struct _JsonReader
89 {
90   /*< private >*/
91   GObject parent_instance;
92
93   JsonReaderPrivate *priv;
94 };
95
96 /**
97  * JsonReaderClass:
98  *
99  * The <structname>JsonReaderClass</structname> structure contains only
100  * private data
101  *
102  * Since: 0.12
103  */
104 struct _JsonReaderClass
105 {
106   /*< private >*/
107   GObjectClass parent_class;
108
109   void (*_json_padding0) (void);
110   void (*_json_padding1) (void);
111   void (*_json_padding2) (void);
112   void (*_json_padding3) (void);
113   void (*_json_padding4) (void);
114 };
115
116 GQuark json_reader_error_quark (void);
117 GType json_reader_get_type (void) G_GNUC_CONST;
118
119 JsonReader *           json_reader_new               (JsonNode     *node);
120
121 void                   json_reader_set_root          (JsonReader   *reader,
122                                                       JsonNode     *root);
123
124 const GError *         json_reader_get_error         (JsonReader   *reader);
125
126 gboolean               json_reader_is_array          (JsonReader   *reader);
127 gboolean               json_reader_read_element      (JsonReader   *reader,
128                                                       guint         index_);
129 void                   json_reader_end_element       (JsonReader   *reader);
130 gint                   json_reader_count_elements    (JsonReader   *reader);
131
132 gboolean               json_reader_is_object         (JsonReader   *reader);
133 gboolean               json_reader_read_member       (JsonReader   *reader,
134                                                       const gchar  *member_name);
135 void                   json_reader_end_member        (JsonReader   *reader);
136 gint                   json_reader_count_members     (JsonReader   *reader);
137 gchar **               json_reader_list_members      (JsonReader   *reader);
138 const gchar *          json_reader_get_member_name   (JsonReader   *reader);
139
140 gboolean               json_reader_is_value          (JsonReader   *reader);
141 JsonNode *             json_reader_get_value         (JsonReader   *reader);
142 gint64                 json_reader_get_int_value     (JsonReader   *reader);
143 gdouble                json_reader_get_double_value  (JsonReader   *reader);
144 const gchar *          json_reader_get_string_value  (JsonReader   *reader);
145 gboolean               json_reader_get_boolean_value (JsonReader   *reader);
146 gboolean               json_reader_get_null_value    (JsonReader   *reader);
147
148 G_END_DECLS
149
150 #endif /* __JSON_READER_H__ */