diff options
Diffstat (limited to 'json-glib')
-rw-r--r-- | json-glib/json-node.c | 48 | ||||
-rw-r--r-- | json-glib/json-types.h | 8 |
2 files changed, 54 insertions, 2 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 diff --git a/json-glib/json-types.h b/json-glib/json-types.h index 2b4ba14..8cc72f0 100644 --- a/json-glib/json-types.h +++ b/json-glib/json-types.h @@ -31,6 +31,8 @@ G_BEGIN_DECLS * Evaluates to the #JsonNodeType contained by @node */ #define JSON_NODE_TYPE(node) (((JsonNode *) (node))->type) + +#define JSON_TYPE_NODE (json_node_get_type ()) #define JSON_TYPE_OBJECT (json_object_get_type ()) #define JSON_TYPE_ARRAY (json_array_get_type ()) @@ -56,8 +58,8 @@ typedef struct _JsonNode JsonNode; * JsonNodeType: * @JSON_NODE_OBJECT: The node contains a #JsonObject * @JSON_NODE_ARRAY: The node contains a #JsonArray - * @JSON_NODE_VALUE: The node contains a #GValue - * @JSON_NODE_NULL: Special type, for nodes containing %NULL + * @JSON_NODE_VALUE: The node contains a fundamental type + * @JSON_NODE_NULL: Special type, for nodes containing null * * Indicates the content of a #JsonNode. */ @@ -90,9 +92,11 @@ struct _JsonNode JsonNode *parent; }; +GType json_node_get_type (void) G_GNUC_CONST; JsonNode * json_node_new (JsonNodeType type); JsonNode * json_node_copy (JsonNode *node); void json_node_free (JsonNode *node); +GType json_node_get_value_type (JsonNode *node); void json_node_set_object (JsonNode *node, JsonObject *object); |