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 #ifndef __JSON_READER_H__ 24 #define __JSON_READER_H__ 25 26 #if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION) 27 #error "Only <json-glib/json-glib.h> can be included directly." 28 #endif 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 `JsonReader` structure contains only private data and should 84 * 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 `JsonReaderClass` structure contains only private data 100 * 101 * Since: 0.12 102 */ 103 struct _JsonReaderClass 104 { 105 /*< private >*/ 106 GObjectClass parent_class; 107 108 void (*_json_padding0) (void); 109 void (*_json_padding1) (void); 110 void (*_json_padding2) (void); 111 void (*_json_padding3) (void); 112 void (*_json_padding4) (void); 113 }; 114 115 JSON_AVAILABLE_IN_1_0 116 GQuark json_reader_error_quark (void); 117 JSON_AVAILABLE_IN_1_0 118 GType json_reader_get_type (void) G_GNUC_CONST; 119 120 JSON_AVAILABLE_IN_1_0 121 JsonReader * json_reader_new (JsonNode *node); 122 123 JSON_AVAILABLE_IN_1_0 124 void json_reader_set_root (JsonReader *reader, 125 JsonNode *root); 126 127 JSON_AVAILABLE_IN_1_0 128 const GError * json_reader_get_error (JsonReader *reader); 129 130 JSON_AVAILABLE_IN_1_0 131 gboolean json_reader_is_array (JsonReader *reader); 132 JSON_AVAILABLE_IN_1_0 133 gboolean json_reader_read_element (JsonReader *reader, 134 guint index_); 135 JSON_AVAILABLE_IN_1_0 136 void json_reader_end_element (JsonReader *reader); 137 JSON_AVAILABLE_IN_1_0 138 gint json_reader_count_elements (JsonReader *reader); 139 140 JSON_AVAILABLE_IN_1_0 141 gboolean json_reader_is_object (JsonReader *reader); 142 JSON_AVAILABLE_IN_1_0 143 gboolean json_reader_read_member (JsonReader *reader, 144 const gchar *member_name); 145 JSON_AVAILABLE_IN_1_0 146 void json_reader_end_member (JsonReader *reader); 147 JSON_AVAILABLE_IN_1_0 148 gint json_reader_count_members (JsonReader *reader); 149 JSON_AVAILABLE_IN_1_0 150 gchar ** json_reader_list_members (JsonReader *reader); 151 JSON_AVAILABLE_IN_1_0 152 const gchar * json_reader_get_member_name (JsonReader *reader); 153 154 JSON_AVAILABLE_IN_1_0 155 gboolean json_reader_is_value (JsonReader *reader); 156 JSON_AVAILABLE_IN_1_0 157 JsonNode * json_reader_get_value (JsonReader *reader); 158 JSON_AVAILABLE_IN_1_0 159 gint64 json_reader_get_int_value (JsonReader *reader); 160 JSON_AVAILABLE_IN_1_0 161 gdouble json_reader_get_double_value (JsonReader *reader); 162 JSON_AVAILABLE_IN_1_0 163 const gchar * json_reader_get_string_value (JsonReader *reader); 164 JSON_AVAILABLE_IN_1_0 165 gboolean json_reader_get_boolean_value (JsonReader *reader); 166 JSON_AVAILABLE_IN_1_0 167 gboolean json_reader_get_null_value (JsonReader *reader); 168 169 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC 170 G_DEFINE_AUTOPTR_CLEANUP_FUNC (JsonReader, g_object_unref) 171 #endif 172 173 G_END_DECLS 174 175 #endif /* __JSON_READER_H__ */ 176