diff options
| author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-10-01 12:57:46 +0100 |
|---|---|---|
| committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-10-01 12:57:46 +0100 |
| commit | 88b11be5eec1da769328e93189bc2f3316c9cd0a (patch) | |
| tree | 5ed59cecd38b1a51a8bbcf9964948d0e7e1fbc4b /json-glib/json-data.c | |
| parent | c11ebd32f73a1e21d6097bf9eba8e12f7e35497a (diff) | |
| download | json-glib-88b11be5eec1da769328e93189bc2f3316c9cd0a.tar.gz | |
Add JsonNode, a generic container for JSON types
This huge commit removes JsonData and adds JsonNode, the generic container
for fundamental and complex data types extracted from a JSON stream. The
contents of a JsonNode can be extracted from it in form of a GValue for
fundamental types (integers, floats, strings, booleans) or in form of
JsonObject and JsonArray objects. JsonObject and JsonArray now accept
JsonNodes instead of GValues.
The JsonParser object builds the data model tree when parsing a JSON stream;
the tree can be recursed by getting the root node and walking it using the
GValue API for the fundamental types and the objects/arrays API for complex
types.
The API has been updated and the tests now recurse through the generated
data model tree.
Diffstat (limited to 'json-glib/json-data.c')
| -rw-r--r-- | json-glib/json-data.c | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/json-glib/json-data.c b/json-glib/json-data.c deleted file mode 100644 index ce6f7ab..0000000 --- a/json-glib/json-data.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "config.h" - -#include <glib.h> - -#include "json-types.h" -#include "json-private.h" - -JsonData * -json_data_new (JsonDataType type) -{ - JsonData *data; - - data = g_slice_new (JsonData); - data->type = type; - - return data; -} - -void -json_data_set_object (JsonData *data, - JsonObject *object) -{ - g_return_if_fail (data != NULL); - g_return_if_fail (JSON_DATA_TYPE (data) == JSON_DATA_OBJECT); - g_return_if_fail (object != NULL); - - data->data.object = object; -} - -/** - * json_data_get_object: - * @data: a #JsonData - * - * Retrieves the #JsonObject stored inside a #JsonData - * - * Return value: the #JsonObject - */ -JsonObject * -json_data_get_object (JsonData *data) -{ - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (JSON_DATA_TYPE (data) == JSON_DATA_OBJECT, NULL); - - return data->data.object; -} - -void -json_data_set_array (JsonData *data, - JsonArray *array) -{ - g_return_if_fail (data != NULL); - g_return_if_fail (JSON_DATA_TYPE (data) == JSON_DATA_ARRAY); - g_return_if_fail (array != NULL); - - data->data.array = array; -} - -/** - * json_data_get_array: - * @data: a #JsonData - * - * Retrieves the #JsonArray stored inside a #JsonData - * - * Return value: the #JsonArray - */ -JsonArray * -json_data_get_array (JsonData *data) -{ - g_return_val_if_fail (data != NULL, NULL); - g_return_val_if_fail (JSON_DATA_TYPE (data) == JSON_DATA_ARRAY, NULL); - - return data->data.array; -} - -void -json_data_free (JsonData *data) -{ - if (data) - { - switch (data->type) - { - case JSON_DATA_OBJECT: - json_object_unref (data->data.object); - break; - - case JSON_DATA_ARRAY: - json_array_unref (data->data.array); - break; - } - - g_slice_free (JsonData, data); - } -} |
