diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-08-12 15:29:41 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-08-12 15:35:47 +0100 |
commit | 10e5a1d38113b7b6e7c71da76ff11219baf1022d (patch) | |
tree | d21219ef532acebdc45107369e3f74abfb53cbc7 /json-glib/json-reader.h | |
parent | c3215ba1d46f7965fb58272da069bec389a174df (diff) | |
download | json-glib-10e5a1d38113b7b6e7c71da76ff11219baf1022d.tar.gz |
Add JsonReader
JsonReader is a simple, cursor-based API for parsing a JSON DOM. It is
similar, in spirit, to the XmlReader API provided by various platforms
and XML parsing libraries.
Diffstat (limited to 'json-glib/json-reader.h')
-rw-r--r-- | json-glib/json-reader.h | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/json-glib/json-reader.h b/json-glib/json-reader.h new file mode 100644 index 0000000..a4fb239 --- /dev/null +++ b/json-glib/json-reader.h @@ -0,0 +1,142 @@ +/* json-reader.h - JSON cursor parser + * + * This file is part of JSON-GLib + * Copyright (C) 2010 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Author: + * Emmanuele Bassi <ebassi@linux.intel.com> + */ + +#if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION) +#error "Only <json-glib/json-glib.h> can be included directly." +#endif + +#ifndef __JSON_READER_H__ +#define __JSON_READER_H__ + +#include <json-glib/json-types.h> + +G_BEGIN_DECLS + +#define JSON_TYPE_READER (json_reader_get_type ()) +#define JSON_READER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), JSON_TYPE_READER, JsonReader)) +#define JSON_IS_READER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JSON_TYPE_READER)) +#define JSON_READER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), JSON_TYPE_READER, JsonReaderClass)) +#define JSON_IS_READER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), JSON_TYPE_READER)) +#define JSON_READER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), JSON_TYPE_READER, JsonReaderClass)) + +/** + * JSON_READER_ERROR: + * + * Error domain for #JsonReader errors + * + * Since: 0.12 + */ +#define JSON_READER_ERROR (json_reader_error_quark ()) + +typedef struct _JsonReader JsonReader; +typedef struct _JsonReaderPrivate JsonReaderPrivate; +typedef struct _JsonReaderClass JsonReaderClass; + +/** + * JsonReaderError: + * @JSON_READER_ERROR_NO_ARRAY: No array found at the current position + * @JSON_READER_ERROR_INVALID_INDEX: Index out of bounds + * @JSON_READER_ERROR_NO_OBJECT: No object found at the current position + * @JSON_READER_ERROR_INVALID_MEMBER: Member not found + * + * Error codes enumeration for #JsonReader errors + * + * Since: 0.12 + */ +typedef enum { + JSON_READER_ERROR_NO_ARRAY, + JSON_READER_ERROR_INVALID_INDEX, + JSON_READER_ERROR_NO_OBJECT, + JSON_READER_ERROR_INVALID_MEMBER +} JsonReaderError; + +/** + * JsonReader: + * + * The <structname>JsonReader</structname> structure contains only + * private data and should only be accessed using the provided API + * + * Since: 0.12 + */ +struct _JsonReader +{ + /*< private >*/ + GObject parent_instance; + + JsonReaderPrivate *priv; +}; + +/** + * JsonReaderClass: + * + * The <structname>JsonReaderClass</structname> structure contains only + * private data + * + * Since: 0.12 + */ +struct _JsonReaderClass +{ + /*< private >*/ + GObjectClass parent_class; + + void (*_json_padding0) (void); + void (*_json_padding1) (void); + void (*_json_padding2) (void); + void (*_json_padding3) (void); + void (*_json_padding4) (void); +}; + +GQuark json_reader_error_quark (void); +GType json_reader_get_type (void) G_GNUC_CONST; + +JsonReader * json_reader_new (void); + +gboolean json_reader_load_from_data (JsonReader *reader, + const gchar *data, + gssize length, + GError **error); + +G_CONST_RETURN GError *json_reader_get_error (JsonReader *reader); + +gboolean json_reader_is_array (JsonReader *reader); +gboolean json_reader_read_element (JsonReader *reader, + guint index_); +void json_reader_end_element (JsonReader *reader); +gint json_reader_count_elements (JsonReader *reader); + +gboolean json_reader_is_object (JsonReader *reader); +gboolean json_reader_read_member (JsonReader *reader, + const gchar *member_name); +void json_reader_end_member (JsonReader *reader); +gint json_reader_count_members (JsonReader *reader); + +gboolean json_reader_is_value (JsonReader *reader); +JsonNode * json_reader_get_value (JsonReader *reader); +gint64 json_reader_get_value_int (JsonReader *reader); +gdouble json_reader_get_value_double (JsonReader *reader); +G_CONST_RETURN gchar * json_reader_get_value_string (JsonReader *reader); +gboolean json_reader_get_value_boolean (JsonReader *reader); +gboolean json_reader_get_value_null (JsonReader *reader); + +G_END_DECLS + +#endif /* __JSON_READER_H__ */ |