diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-05-16 20:09:07 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-05-16 20:09:07 +0100 |
commit | 3057a1722e27a13b39ddec4754fb6abda1aea199 (patch) | |
tree | 8a5163c07abc96263e34f3026978d111943a1b3f /json-glib/json-object.c | |
parent | 5778210462b8b7a1a5d98466508276f712ea8c47 (diff) | |
download | json-glib-3057a1722e27a13b39ddec4754fb6abda1aea199.tar.gz |
Add JsonObject iteration function
The json_object_foreach_member() function iterates over a JsonObject
data type.
Diffstat (limited to 'json-glib/json-object.c')
-rw-r--r-- | json-glib/json-object.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/json-glib/json-object.c b/json-glib/json-object.c index 675038a..6397954 100644 --- a/json-glib/json-object.c +++ b/json-glib/json-object.c @@ -831,3 +831,58 @@ json_object_remove_member (JsonObject *object, g_hash_table_remove (object->members, name); g_free (name); } + +typedef struct _ForeachClosure ForeachClosure; + +struct _ForeachClosure +{ + JsonObject *object; + + JsonObjectForeach func; + gpointer data; +}; + +static void +json_object_foreach_internal (gpointer key, + gpointer value, + gpointer data) +{ + ForeachClosure *clos = data; + const gchar *member_name = key; + JsonNode *member_node = value; + + clos->func (clos->object, member_name, member_node, clos->data); +} + +/** + * json_object_foreach_member: + * @object: a #JsonObject + * @func: the function to be called on each member + * @data: data to be passed to the function + * + * Iterates over all members of @object and calls @func on + * each one of them. + * + * It is safe to change the value of a #JsonNode of the @object + * from within the iterator @func, but it is not safe to add or + * remove members from the @object. + * + * Since: 0.8 + */ +void +json_object_foreach_member (JsonObject *object, + JsonObjectForeach func, + gpointer data) +{ + ForeachClosure clos; + + g_return_if_fail (object != NULL); + g_return_if_fail (func != NULL); + + clos.object = object; + clos.func = func; + clos.data = data; + g_hash_table_foreach (object->members, + json_object_foreach_internal, + &clos); +} |