[json-glib] [node] Add HOLDS macros for quick type checking
- From: Emmanuele Bassi <ebassi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [json-glib] [node] Add HOLDS macros for quick type checking
- Date: Mon, 28 Sep 2009 17:24:34 +0000 (UTC)
commit d5bebce0286aef5c4b4110c16c22a8ef3dc38405
Author: Emmanuele Bassi <ebassi gnome org>
Date: Mon Sep 28 18:15:48 2009 +0100
[node] Add HOLDS macros for quick type checking
JsonNode should mimick GValue's API and have macros for easy type checking
doc/reference/json-glib-sections.txt | 7 ++++-
json-glib/json-types.h | 51 ++++++++++++++++++++++++++++++++++
json-glib/tests/node-test.c | 2 +-
3 files changed, 58 insertions(+), 2 deletions(-)
---
diff --git a/doc/reference/json-glib-sections.txt b/doc/reference/json-glib-sections.txt
index 86a049c..2fa0058 100644
--- a/doc/reference/json-glib-sections.txt
+++ b/doc/reference/json-glib-sections.txt
@@ -84,8 +84,13 @@ json_array_get_type
<FILE>json-node</FILE>
<TITLE>JSON Node</TITLE>
JsonNodeType
-JSON_NODE_TYPE
JsonNode
+JSON_NODE_TYPE
+JSON_NODE_HOLDS
+JSON_NODE_HOLDS_VALUE
+JSON_NODE_HOLDS_OBJECT
+JSON_NODE_HOLDS_ARRAY
+JSON_NODE_HOLDS_NULL
json_node_new
json_node_copy
json_node_free
diff --git a/json-glib/json-types.h b/json-glib/json-types.h
index 3ea885f..5793179 100644
--- a/json-glib/json-types.h
+++ b/json-glib/json-types.h
@@ -40,6 +40,57 @@ G_BEGIN_DECLS
*/
#define JSON_NODE_TYPE(node) (json_node_get_node_type ((node)))
+/**
+ * JSON_NODE_HOLDS:
+ * @node: a #JsonNode
+ * @t: a #JsonNodeType
+ *
+ * Evaluates to %TRUE if the @node holds type @t
+ *
+ * Since: 0.10
+ */
+#define JSON_NODE_HOLDS(node,t) (json_node_get_node_type ((node)) == (t))
+
+/**
+ * JSON_NODE_HOLDS_VALUE:
+ * @node: a #JsonNode
+ *
+ * Evaluates to %TRUE if @node holds a %JSON_NODE_VALUE
+ *
+ * Since: 0.10
+ */
+#define JSON_NODE_HOLDS_VALUE(node) (JSON_NODE_HOLDS ((node), JSON_NODE_VALUE))
+
+/**
+ * JSON_NODE_HOLDS_OBJECT:
+ * @node: a #JsonNode
+ *
+ * Evaluates to %TRUE if @node holds a %JSON_NODE_OBJECT
+ *
+ * Since: 0.10
+ */
+#define JSON_NODE_HOLDS_OBJECT(node) (JSON_NODE_HOLDS ((node), JSON_NODE_OBJECT))
+
+/**
+ * JSON_NODE_HOLDS_ARRAY:
+ * @node: a #JsonNode
+ *
+ * Evaluates to %TRUE if @node holds a %JSON_NODE_ARRAY
+ *
+ * Since: 0.10
+ */
+#define JSON_NODE_HOLDS_ARRAY(node) (JSON_NODE_HOLDS ((node), JSON_NODE_ARRAY))
+
+/**
+ * JSON_NODE_HOLDS_NULL:
+ * @node: a #JsonNode
+ *
+ * Evaluates to %TRUE if @node holds a %JSON_NODE_NULL
+ *
+ * Since: 0.10
+ */
+#define JSON_NODE_HOLDS_NULL(node) (JSON_NODE_HOLDS ((node), JSON_NODE_NULL))
+
#define JSON_TYPE_NODE (json_node_get_type ())
#define JSON_TYPE_OBJECT (json_object_get_type ())
#define JSON_TYPE_ARRAY (json_array_get_type ())
diff --git a/json-glib/tests/node-test.c b/json-glib/tests/node-test.c
index 7c0336d..da979a4 100644
--- a/json-glib/tests/node-test.c
+++ b/json-glib/tests/node-test.c
@@ -60,7 +60,7 @@ test_null (void)
{
JsonNode *node = json_node_new (JSON_NODE_NULL);
- g_assert_cmpint (json_node_get_node_type (node), ==, JSON_NODE_NULL);
+ g_assert (JSON_NODE_HOLDS_NULL (node));
g_assert_cmpint (json_node_get_value_type (node), ==, G_TYPE_INVALID);
g_assert_cmpstr (json_node_type_name (node), ==, "NULL");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]