[json-glib] [node] Make JsonNode completely private
- From: Emmanuele Bassi <ebassi src gnome org>
- To: svn-commits-list gnome org
- Subject: [json-glib] [node] Make JsonNode completely private
- Date: Tue, 9 Jun 2009 06:34:57 -0400 (EDT)
commit 069cdc8c4ea9024b1583f074815e16e9ddf7db7f
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Tue Jun 9 11:05:23 2009 +0100
[node] Make JsonNode completely private
The JsonNode structure has always been meant to be completely
opaque; we indirectly exposed the :type member, but only for
access through the JSON_NODE_TYPE() macro.
Since that macro has become a proxy for the json_node_get_node_type()
function we can safely move everything into a private, uninstalled
header file and let JsonNode be completely opaque to the developer.
---
json-glib/Makefile.am | 1 +
json-glib/json-array.c | 9 +-----
json-glib/json-generator.c | 2 +
json-glib/json-gobject.c | 2 +
json-glib/json-node.c | 2 +-
json-glib/json-object.c | 9 +-----
json-glib/json-parser.c | 2 +
json-glib/json-types-private.h | 61 ++++++++++++++++++++++++++++++++++++++++
json-glib/json-types.h | 38 +++++++++---------------
json-glib/tests/node-test.c | 8 ++--
10 files changed, 89 insertions(+), 45 deletions(-)
diff --git a/json-glib/Makefile.am b/json-glib/Makefile.am
index e08307d..9a5328b 100644
--- a/json-glib/Makefile.am
+++ b/json-glib/Makefile.am
@@ -40,6 +40,7 @@ source_h = \
source_h_private = \
$(srcdir)/json-scanner.h \
+ $(srcdir)/json-types-private.h \
$(NULL)
source_c = \
diff --git a/json-glib/json-array.c b/json-glib/json-array.c
index 301e050..dda971f 100644
--- a/json-glib/json-array.c
+++ b/json-glib/json-array.c
@@ -21,7 +21,7 @@
#include "config.h"
#endif
-#include "json-types.h"
+#include "json-types-private.h"
/**
* SECTION:json-array
@@ -40,13 +40,6 @@
* To retrieve the length of the array, use json_array_get_length().
*/
-struct _JsonArray
-{
- GPtrArray *elements;
-
- volatile gint ref_count;
-};
-
GType
json_array_get_type (void)
{
diff --git a/json-glib/json-generator.c b/json-glib/json-generator.c
index 813dd07..472b74f 100644
--- a/json-glib/json-generator.c
+++ b/json-glib/json-generator.c
@@ -32,6 +32,8 @@
#include <stdlib.h>
#include <string.h>
+#include "json-types-private.h"
+
#include "json-marshal.h"
#include "json-generator.h"
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index 0c9351a..35b191b 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -39,6 +39,8 @@
#include <string.h>
#include <stdlib.h>
+#include "json-types-private.h"
+
#include "json-gobject.h"
#include "json-parser.h"
#include "json-generator.h"
diff --git a/json-glib/json-node.c b/json-glib/json-node.c
index 04570dd..c844ce4 100644
--- a/json-glib/json-node.c
+++ b/json-glib/json-node.c
@@ -23,7 +23,7 @@
#include <glib.h>
-#include "json-types.h"
+#include "json-types-private.h"
/**
* SECTION:json-node
diff --git a/json-glib/json-object.c b/json-glib/json-object.c
index 6397954..66c347c 100644
--- a/json-glib/json-object.c
+++ b/json-glib/json-object.c
@@ -24,7 +24,7 @@
#include <glib.h>
-#include "json-types.h"
+#include "json-types-private.h"
/**
* SECTION:json-object
@@ -48,13 +48,6 @@
* use json_object_get_size().
*/
-struct _JsonObject
-{
- GHashTable *members;
-
- volatile gint ref_count;
-};
-
GType
json_object_get_type (void)
{
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index 8224576..87799de 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -31,6 +31,8 @@
#include <string.h>
+#include "json-types-private.h"
+
#include "json-marshal.h"
#include "json-parser.h"
#include "json-scanner.h"
diff --git a/json-glib/json-types-private.h b/json-glib/json-types-private.h
new file mode 100644
index 0000000..b59151b
--- /dev/null
+++ b/json-glib/json-types-private.h
@@ -0,0 +1,61 @@
+/* json-types-private.h - JSON data types private header
+ *
+ * This file is part of JSON-GLib
+ * Copyright (C) 2007 OpenedHand Ltd
+ * Copyright (C) 2009 Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:
+ * Emmanuele Bassi <ebassi linux intel com>
+ */
+
+#ifndef __JSON_TYPES_PRIVATE_H__
+#define __JSON_TYPES_PRIVATE_H__
+
+#include "json-types.h"
+
+G_BEGIN_DECLS
+
+struct _JsonNode
+{
+ /*< private >*/
+ JsonNodeType type;
+
+ union {
+ JsonObject *object;
+ JsonArray *array;
+ GValue value;
+ } data;
+
+ JsonNode *parent;
+};
+
+struct _JsonArray
+{
+ GPtrArray *elements;
+
+ volatile gint ref_count;
+};
+
+struct _JsonObject
+{
+ GHashTable *members;
+
+ volatile gint ref_count;
+};
+
+G_END_DECLS
+
+#endif /* __JSON_TYPES_PRIVATE_H__ */
diff --git a/json-glib/json-types.h b/json-glib/json-types.h
index f797c05..1538488 100644
--- a/json-glib/json-types.h
+++ b/json-glib/json-types.h
@@ -2,19 +2,23 @@
*
* This file is part of JSON-GLib
* Copyright (C) 2007 OpenedHand Ltd.
+ * Copyright (C) 2009 Intel Corp.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
* Author:
- * Emmanuele Bassi <ebassi openedhand com>
+ * Emmanuele Bassi <ebassi linux intel com>
*/
#ifndef __JSON_TYPES_H__
@@ -36,6 +40,14 @@ G_BEGIN_DECLS
#define JSON_TYPE_OBJECT (json_object_get_type ())
#define JSON_TYPE_ARRAY (json_array_get_type ())
+/**
+ * JsonNode:
+ * @type: the type of node
+ *
+ * A generic container of JSON data types. The contents of the #JsonNode
+ * structure are private and should only be accessed via the provided
+ * functions and never directly.
+ */
typedef struct _JsonNode JsonNode;
/**
@@ -106,28 +118,6 @@ typedef void (* JsonArrayForeach) (JsonArray *array,
JsonNode *element_node,
gpointer user_data);
-/**
- * JsonNode:
- * @type: the type of node
- *
- * A generic container of JSON data types. The contents of the #JsonNode
- * structure are private and should only be accessed via the provided
- * functions and never directly.
- */
-struct _JsonNode
-{
- /*< private >*/
- JsonNodeType type;
-
- union {
- JsonObject *object;
- JsonArray *array;
- GValue value;
- } data;
-
- JsonNode *parent;
-};
-
/*
* JsonNode
*/
diff --git a/json-glib/tests/node-test.c b/json-glib/tests/node-test.c
index 1a9294b..8ccc402 100644
--- a/json-glib/tests/node-test.c
+++ b/json-glib/tests/node-test.c
@@ -8,7 +8,7 @@ test_copy_null (void)
JsonNode *node = json_node_new (JSON_NODE_NULL);
JsonNode *copy = json_node_copy (node);
- g_assert_cmpint (node->type, ==, copy->type);
+ g_assert_cmpint (json_node_get_node_type (node), ==, json_node_get_node_type (copy));
g_assert_cmpint (json_node_get_value_type (node), ==, json_node_get_value_type (copy));
g_assert_cmpstr (json_node_type_name (node), ==, json_node_type_name (copy));
@@ -25,7 +25,7 @@ test_copy_value (void)
json_node_set_string (node, "hello");
copy = json_node_copy (node);
- g_assert_cmpint (node->type, ==, copy->type);
+ g_assert_cmpint (json_node_get_node_type (node), ==, json_node_get_node_type (copy));
g_assert_cmpstr (json_node_type_name (node), ==, json_node_type_name (copy));
g_assert_cmpstr (json_node_get_string (node), ==, json_node_get_string (copy));
@@ -48,7 +48,7 @@ test_copy_object (void)
copy = json_node_copy (node);
- g_assert_cmpint (node->type, ==, copy->type);
+ g_assert_cmpint (json_node_get_node_type (node), ==, json_node_get_node_type (copy));
g_assert (json_node_get_object (node) == json_node_get_object (copy));
json_node_free (copy);
@@ -60,7 +60,7 @@ test_null (void)
{
JsonNode *node = json_node_new (JSON_NODE_NULL);
- g_assert_cmpint (node->type, ==, JSON_NODE_NULL);
+ g_assert_cmpint (json_node_get_node_type (node), ==, JSON_NODE_NULL);
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]