diff options
author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-11-13 09:28:57 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-11-13 09:28:57 +0000 |
commit | a7c39c910e08093ee0d0723685005623f26b9eae (patch) | |
tree | 19a4633a1020bce99750a9e62566592d43d45d89 /json-glib/json-generator.c | |
parent | 6132d7325c33e26740b4c955d8ccbe53fd817cd8 (diff) | |
download | json-glib-a7c39c910e08093ee0d0723685005623f26b9eae.tar.gz |
Add the JsonGenerator:root property
JsonGenerator now has a :root property, so it can be constructed using
just g_object_new():
generator = g_object_new (JSON_TYPE_GENERATOR,
"pretty", TRUE,
"indent", 4,
"root", node,
NULL);
This means that the root node is copied inside the generator, instead of
just taking ownership (it was quite confusing). The documentation now
clearly states what happens, and that you can safely free the node after
feeding it to the JsonGenerator.
Diffstat (limited to 'json-glib/json-generator.c')
-rw-r--r-- | json-glib/json-generator.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c index 675bc98..730260e 100644 --- a/json-glib/json-generator.c +++ b/json-glib/json-generator.c @@ -50,7 +50,8 @@ enum PROP_0, PROP_PRETTY, - PROP_INDENT + PROP_INDENT, + PROP_ROOT }; static gchar *dump_value (JsonGenerator *generator, @@ -97,6 +98,10 @@ json_generator_set_property (GObject *gobject, case PROP_INDENT: priv->indent = g_value_get_uint (value); break; + case PROP_ROOT: + json_generator_set_root (JSON_GENERATOR (gobject), + g_value_get_boxed (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; @@ -119,6 +124,9 @@ json_generator_get_property (GObject *gobject, case PROP_INDENT: g_value_set_uint (value, priv->indent); break; + case PROP_ROOT: + g_value_set_boxed (value, priv->root); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); break; @@ -163,6 +171,21 @@ json_generator_class_init (JsonGeneratorClass *klass) 0, G_MAXUINT, 2, G_PARAM_READWRITE)); + /** + * JsonGenerator:root: + * + * The root #JsonNode to be used when constructing a JSON data + * stream. + * + * Since: 0.4 + */ + g_object_class_install_property (gobject_class, + PROP_ROOT, + g_param_spec_boxed ("root", + "Root", + "Root of the JSON data tree", + JSON_TYPE_NODE, + G_PARAM_READWRITE)); } static void @@ -517,6 +540,9 @@ json_generator_to_file (JsonGenerator *generator, * * Sets @node as the root of the JSON data stream to be serialized by * the #JsonGenerator. + * + * Note: the node is copied by the generator object, so it can be safely + * freed after calling this function. */ void json_generator_set_root (JsonGenerator *generator, @@ -531,5 +557,5 @@ json_generator_set_root (JsonGenerator *generator, } if (node) - generator->priv->root = node; + generator->priv->root = json_node_copy (node); } |