diff options
author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-11-13 09:17:22 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-11-13 09:17:22 +0000 |
commit | f051b948714e4928a7d7f903e891639ce4ba82fd (patch) | |
tree | 99bde50c21599992e38128a2a18612213697c60c /json-glib/json-node.c | |
parent | 45c697263364a975fd6a54373f999f2932436b6f (diff) | |
download | json-glib-f051b948714e4928a7d7f903e891639ce4ba82fd.tar.gz |
Add a GType for JsonNode
We need a GType for nodes if we want to add JsonNode properties or signal
marshallers to a GObject class. We could use pointers, but we'd loose type
safety, so it's a no-no.
Diffstat (limited to 'json-glib/json-node.c')
-rw-r--r-- | json-glib/json-node.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/json-glib/json-node.c b/json-glib/json-node.c index 48ea3bf..03df9fb 100644 --- a/json-glib/json-node.c +++ b/json-glib/json-node.c @@ -42,6 +42,54 @@ * they contain. */ +GType +json_node_get_type (void) +{ + static GType node_type = 0; + + if (G_UNLIKELY (node_type == 0)) + node_type = g_boxed_type_register_static ("JsonNode", + (GBoxedCopyFunc) json_node_copy, + (GBoxedFreeFunc) json_node_free); + + return node_type; +} + +/** + * json_node_get_value_type: + * @node: a #JsonNode + * + * Returns the #GType of the payload of the node. + * + * Return value: a #GType for the payload. + * + * Since: 0.4 + */ +GType +json_node_get_value_type (JsonNode *node) +{ + g_return_val_if_fail (node != NULL, G_TYPE_INVALID); + + switch (node->type) + { + case JSON_NODE_OBJECT: + return JSON_TYPE_OBJECT; + + case JSON_NODE_ARRAY: + return JSON_TYPE_ARRAY; + + case JSON_NODE_NULL: + return G_TYPE_INVALID; + + case JSON_NODE_VALUE: + return G_VALUE_TYPE (&node->value); + + default: + g_assert_not_reached (); + return G_TYPE_INVALID; + } +} + /** * json_node_new: * @type: a #JsonNodeType |