json-reader.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #ifndef __JSON_READER_H__
  23. #define __JSON_READER_H__
  24. #if !defined(__JSON_GLIB_INSIDE__) && !defined(JSON_COMPILATION)
  25. #error "Only <json-glib/json-glib.h> can be included directly."
  26. #endif
  27. #include <json-glib/json-types.h>
  28. G_BEGIN_DECLS
  29. #define JSON_TYPE_READER (json_reader_get_type ())
  30. #define JSON_READER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), JSON_TYPE_READER, JsonReader))
  31. #define JSON_IS_READER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JSON_TYPE_READER))
  32. #define JSON_READER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), JSON_TYPE_READER, JsonReaderClass))
  33. #define JSON_IS_READER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), JSON_TYPE_READER))
  34. #define JSON_READER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), JSON_TYPE_READER, JsonReaderClass))
  35. /**
  36. * JSON_READER_ERROR:
  37. *
  38. * Error domain for #JsonReader errors
  39. *
  40. * Since: 0.12
  41. */
  42. #define JSON_READER_ERROR (json_reader_error_quark ())
  43. typedef struct _JsonReader JsonReader;
  44. typedef struct _JsonReaderPrivate JsonReaderPrivate;
  45. typedef struct _JsonReaderClass JsonReaderClass;
  46. /**
  47. * JsonReaderError:
  48. * @JSON_READER_ERROR_NO_ARRAY: No array found at the current position
  49. * @JSON_READER_ERROR_INVALID_INDEX: Index out of bounds
  50. * @JSON_READER_ERROR_NO_OBJECT: No object found at the current position
  51. * @JSON_READER_ERROR_INVALID_MEMBER: Member not found
  52. * @JSON_READER_ERROR_INVALID_NODE: No valid node found at the current position
  53. * @JSON_READER_ERROR_NO_VALUE: The node at the current position does not
  54. * hold a value
  55. * @JSON_READER_ERROR_INVALID_TYPE: The node at the current position does not
  56. * hold a value of the desired type
  57. *
  58. * Error codes enumeration for #JsonReader errors
  59. *
  60. * Since: 0.12
  61. */
  62. typedef enum {
  63. JSON_READER_ERROR_NO_ARRAY,
  64. JSON_READER_ERROR_INVALID_INDEX,
  65. JSON_READER_ERROR_NO_OBJECT,
  66. JSON_READER_ERROR_INVALID_MEMBER,
  67. JSON_READER_ERROR_INVALID_NODE,
  68. JSON_READER_ERROR_NO_VALUE,
  69. JSON_READER_ERROR_INVALID_TYPE
  70. } JsonReaderError;
  71. /**
  72. * JsonReader:
  73. *
  74. * The `JsonReader` structure contains only private data and should
  75. * be accessed using the provided API
  76. *
  77. * Since: 0.12
  78. */
  79. struct _JsonReader
  80. {
  81. /*< private >*/
  82. GObject parent_instance;
  83. JsonReaderPrivate *priv;
  84. };
  85. /**
  86. * JsonReaderClass:
  87. *
  88. * The `JsonReaderClass` structure contains only private data
  89. *
  90. * Since: 0.12
  91. */
  92. struct _JsonReaderClass
  93. {
  94. /*< private >*/
  95. GObjectClass parent_class;
  96. void (*_json_padding0) (void);
  97. void (*_json_padding1) (void);
  98. void (*_json_padding2) (void);
  99. void (*_json_padding3) (void);
  100. void (*_json_padding4) (void);
  101. };
  102. JSON_AVAILABLE_IN_1_0
  103. GQuark json_reader_error_quark (void);
  104. JSON_AVAILABLE_IN_1_0
  105. GType json_reader_get_type (void) G_GNUC_CONST;
  106. JSON_AVAILABLE_IN_1_0
  107. JsonReader * json_reader_new (JsonNode *node);
  108. JSON_AVAILABLE_IN_1_0
  109. void json_reader_set_root (JsonReader *reader,
  110. JsonNode *root);
  111. JSON_AVAILABLE_IN_1_0
  112. const GError * json_reader_get_error (JsonReader *reader);
  113. JSON_AVAILABLE_IN_1_0
  114. gboolean json_reader_is_array (JsonReader *reader);
  115. JSON_AVAILABLE_IN_1_0
  116. gboolean json_reader_read_element (JsonReader *reader,
  117. guint index_);
  118. JSON_AVAILABLE_IN_1_0
  119. void json_reader_end_element (JsonReader *reader);
  120. JSON_AVAILABLE_IN_1_0
  121. gint json_reader_count_elements (JsonReader *reader);
  122. JSON_AVAILABLE_IN_1_0
  123. gboolean json_reader_is_object (JsonReader *reader);
  124. JSON_AVAILABLE_IN_1_0
  125. gboolean json_reader_read_member (JsonReader *reader,
  126. const gchar *member_name);
  127. JSON_AVAILABLE_IN_1_0
  128. void json_reader_end_member (JsonReader *reader);
  129. JSON_AVAILABLE_IN_1_0
  130. gint json_reader_count_members (JsonReader *reader);
  131. JSON_AVAILABLE_IN_1_0
  132. gchar ** json_reader_list_members (JsonReader *reader);
  133. JSON_AVAILABLE_IN_1_0
  134. const gchar * json_reader_get_member_name (JsonReader *reader);
  135. JSON_AVAILABLE_IN_1_0
  136. gboolean json_reader_is_value (JsonReader *reader);
  137. JSON_AVAILABLE_IN_1_0
  138. JsonNode * json_reader_get_value (JsonReader *reader);
  139. JSON_AVAILABLE_IN_1_0
  140. gint64 json_reader_get_int_value (JsonReader *reader);
  141. JSON_AVAILABLE_IN_1_0
  142. gdouble json_reader_get_double_value (JsonReader *reader);
  143. JSON_AVAILABLE_IN_1_0
  144. const gchar * json_reader_get_string_value (JsonReader *reader);
  145. JSON_AVAILABLE_IN_1_0
  146. gboolean json_reader_get_boolean_value (JsonReader *reader);
  147. JSON_AVAILABLE_IN_1_0
  148. gboolean json_reader_get_null_value (JsonReader *reader);
  149. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  150. G_DEFINE_AUTOPTR_CLEANUP_FUNC (JsonReader, g_object_unref)
  151. #endif
  152. G_END_DECLS
  153. #endif /* __JSON_READER_H__ */