Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:12:09

0001 /* json-parser.h - JSON streams parser
0002  * 
0003  * This file is part of JSON-GLib
0004  * Copyright (C) 2007  OpenedHand Ltd.
0005  * Copyright (C) 2009  Intel Corp.
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Lesser General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2.1 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
0019  *
0020  * Author:
0021  *   Emmanuele Bassi  <ebassi@linux.intel.com>
0022  */
0023 
0024 #ifndef __JSON_PARSER_H__
0025 #define __JSON_PARSER_H__
0026 
0027 #if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
0028 #error "Only <json-glib/json-glib.h> can be included directly."
0029 #endif
0030 
0031 #include <gio/gio.h>
0032 #include <json-glib/json-types.h>
0033 
0034 G_BEGIN_DECLS
0035 
0036 #define JSON_TYPE_PARSER                (json_parser_get_type ())
0037 #define JSON_PARSER(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), JSON_TYPE_PARSER, JsonParser))
0038 #define JSON_IS_PARSER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JSON_TYPE_PARSER))
0039 #define JSON_PARSER_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), JSON_TYPE_PARSER, JsonParserClass))
0040 #define JSON_IS_PARSER_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), JSON_TYPE_PARSER))
0041 #define JSON_PARSER_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), JSON_TYPE_PARSER, JsonParserClass))
0042 
0043 /**
0044  * JSON_PARSER_ERROR:
0045  *
0046  * Error domain for `JsonParser`.
0047  */
0048 #define JSON_PARSER_ERROR               (json_parser_error_quark ())
0049 
0050 typedef struct _JsonParser              JsonParser;
0051 typedef struct _JsonParserPrivate       JsonParserPrivate;
0052 typedef struct _JsonParserClass         JsonParserClass;
0053 
0054 /**
0055  * JsonParserError:
0056  * @JSON_PARSER_ERROR_PARSE: parse error
0057  * @JSON_PARSER_ERROR_TRAILING_COMMA: unexpected trailing comma
0058  * @JSON_PARSER_ERROR_MISSING_COMMA: expected comma
0059  * @JSON_PARSER_ERROR_MISSING_COLON: expected colon
0060  * @JSON_PARSER_ERROR_INVALID_BAREWORD: invalid bareword
0061  * @JSON_PARSER_ERROR_EMPTY_MEMBER_NAME: empty member name (Since: 0.16)
0062  * @JSON_PARSER_ERROR_INVALID_DATA: invalid data (Since: 0.18)
0063  * @JSON_PARSER_ERROR_UNKNOWN: unknown error
0064  *
0065  * Error codes for `JSON_PARSER_ERROR`.
0066  *
0067  * This enumeration can be extended at later date
0068  */
0069 typedef enum {
0070   JSON_PARSER_ERROR_PARSE,
0071   JSON_PARSER_ERROR_TRAILING_COMMA,
0072   JSON_PARSER_ERROR_MISSING_COMMA,
0073   JSON_PARSER_ERROR_MISSING_COLON,
0074   JSON_PARSER_ERROR_INVALID_BAREWORD,
0075   JSON_PARSER_ERROR_EMPTY_MEMBER_NAME,
0076   JSON_PARSER_ERROR_INVALID_DATA,
0077 
0078   JSON_PARSER_ERROR_UNKNOWN
0079 } JsonParserError;
0080 
0081 struct _JsonParser
0082 {
0083   /*< private >*/
0084   GObject parent_instance;
0085 
0086   JsonParserPrivate *priv;
0087 };
0088 
0089 /**
0090  * JsonParserClass:
0091  * @parse_start: class handler for the JsonParser::parse-start signal
0092  * @object_start: class handler for the JsonParser::object-start signal
0093  * @object_member: class handler for the JsonParser::object-member signal
0094  * @object_end: class handler for the JsonParser::object-end signal
0095  * @array_start: class handler for the JsonParser::array-start signal
0096  * @array_element: class handler for the JsonParser::array-element signal
0097  * @array_end: class handler for the JsonParser::array-end signal
0098  * @parse_end: class handler for the JsonParser::parse-end signal
0099  * @error: class handler for the JsonParser::error signal
0100  *
0101  * The class structure for the JsonParser type.
0102  */
0103 struct _JsonParserClass
0104 {
0105   /*< private >*/
0106   GObjectClass parent_class;
0107 
0108   /*< public  >*/
0109   void (* parse_start)   (JsonParser   *parser);
0110 
0111   void (* object_start)  (JsonParser   *parser);
0112   void (* object_member) (JsonParser   *parser,
0113                           JsonObject   *object,
0114                           const gchar  *member_name);
0115   void (* object_end)    (JsonParser   *parser,
0116                           JsonObject   *object);
0117 
0118   void (* array_start)   (JsonParser   *parser);
0119   void (* array_element) (JsonParser   *parser,
0120                           JsonArray    *array,
0121                           gint          index_);
0122   void (* array_end)     (JsonParser   *parser,
0123                           JsonArray    *array);
0124 
0125   void (* parse_end)     (JsonParser   *parser);
0126   
0127   void (* error)         (JsonParser   *parser,
0128                           const GError *error);
0129 
0130   /*< private >*/
0131   /* padding for future expansion */
0132   void (* _json_reserved1) (void);
0133   void (* _json_reserved2) (void);
0134   void (* _json_reserved3) (void);
0135   void (* _json_reserved4) (void);
0136   void (* _json_reserved5) (void);
0137   void (* _json_reserved6) (void);
0138   void (* _json_reserved7) (void);
0139   void (* _json_reserved8) (void);
0140 };
0141 
0142 JSON_AVAILABLE_IN_1_0
0143 GQuark json_parser_error_quark (void);
0144 JSON_AVAILABLE_IN_1_0
0145 GType json_parser_get_type (void) G_GNUC_CONST;
0146 
0147 JSON_AVAILABLE_IN_1_0
0148 JsonParser *json_parser_new                     (void);
0149 JSON_AVAILABLE_IN_1_2
0150 JsonParser *json_parser_new_immutable           (void);
0151 JSON_AVAILABLE_IN_1_0
0152 gboolean    json_parser_load_from_file          (JsonParser           *parser,
0153                                                  const gchar          *filename,
0154                                                  GError              **error);
0155 JSON_AVAILABLE_IN_1_6
0156 gboolean    json_parser_load_from_mapped_file   (JsonParser           *parser,
0157                                                  const gchar          *filename,
0158                                                  GError              **error);
0159 JSON_AVAILABLE_IN_1_0
0160 gboolean    json_parser_load_from_data          (JsonParser           *parser,
0161                                                  const gchar          *data,
0162                                                  gssize                length,
0163                                                  GError              **error);
0164 JSON_AVAILABLE_IN_1_0
0165 gboolean    json_parser_load_from_stream        (JsonParser           *parser,
0166                                                  GInputStream         *stream,
0167                                                  GCancellable         *cancellable,
0168                                                  GError              **error);
0169 JSON_AVAILABLE_IN_1_0
0170 void        json_parser_load_from_stream_async  (JsonParser           *parser,
0171                                                  GInputStream         *stream,
0172                                                  GCancellable         *cancellable,
0173                                                  GAsyncReadyCallback   callback,
0174                                                  gpointer              user_data);
0175 JSON_AVAILABLE_IN_1_0
0176 gboolean    json_parser_load_from_stream_finish (JsonParser           *parser,
0177                                                  GAsyncResult         *result,
0178                                                  GError              **error);
0179 
0180 JSON_AVAILABLE_IN_1_0
0181 JsonNode *  json_parser_get_root                (JsonParser           *parser);
0182 JSON_AVAILABLE_IN_1_4
0183 JsonNode *  json_parser_steal_root              (JsonParser           *parser);
0184 
0185 JSON_AVAILABLE_IN_1_0
0186 guint       json_parser_get_current_line        (JsonParser           *parser);
0187 JSON_AVAILABLE_IN_1_0
0188 guint       json_parser_get_current_pos         (JsonParser           *parser);
0189 JSON_AVAILABLE_IN_1_0
0190 gboolean    json_parser_has_assignment          (JsonParser           *parser,
0191                                                  gchar               **variable_name);
0192 
0193 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
0194 G_DEFINE_AUTOPTR_CLEANUP_FUNC (JsonParser, g_object_unref)
0195 #endif
0196 
0197 G_END_DECLS
0198 
0199 #endif /* __JSON_PARSER_H__ */