[couchdb-glib] Convert CouchdbStructField and CouchdbArrayField to GObject-based classes



commit fe12f27bedef008eb13819f23f5a1e96df40ee3e
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Jun 3 14:01:48 2010 +0200

    Convert CouchdbStructField and CouchdbArrayField to GObject-based classes

 .gitignore                          |    1 +
 couchdb-glib/couchdb-array-field.c  |  128 ++++++++++++-------------------
 couchdb-glib/couchdb-array-field.h  |   13 +++-
 couchdb-glib/couchdb-struct-field.c |  145 +++++++++++++---------------------
 couchdb-glib/couchdb-struct-field.h |   13 +++-
 couchdb-glib/couchdb-types.h        |   17 ++++-
 6 files changed, 140 insertions(+), 177 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 16e1ca9..32df3b2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,6 +71,7 @@ bindings/mono/CouchdbCredentialsType.cs
 bindings/mono/CouchdbDatabase.cs
 bindings/mono/CouchdbDatabaseInfo.cs
 bindings/mono/CouchdbDesignDocument.cs
+bindings/mono/CouchdbDesignDocumentLanguage.cs
 bindings/mono/CouchdbDocument.cs
 bindings/mono/CouchdbDocumentInfo.cs
 bindings/mono/CouchdbSession.cs
diff --git a/couchdb-glib/couchdb-array-field.c b/couchdb-glib/couchdb-array-field.c
index db66b94..36cf130 100644
--- a/couchdb-glib/couchdb-array-field.c
+++ b/couchdb-glib/couchdb-array-field.c
@@ -24,22 +24,40 @@
 #include "couchdb-array-field.h"
 #include "couchdb-struct-field.h"
 
-struct _CouchdbArrayField {
-	gint ref_count;
+struct _CouchdbArrayFieldPrivate {
 	JsonArray *json_array;
 };
 
-GType
-couchdb_array_field_get_type (void)
+G_DEFINE_TYPE(CouchdbArrayField, couchdb_array_field, G_TYPE_OBJECT)
+
+static void
+couchdb_array_field_finalize (GObject *object)
+{
+	CouchdbArrayField *array = COUCHDB_ARRAY_FIELD (object);
+
+	if (array->priv != NULL) {
+		if (array->priv->json_array != NULL)
+			json_array_unref (array->priv->json_array);
+
+		g_free (array->priv);
+	}
+
+	G_OBJECT_CLASS (couchdb_array_field_parent_class)->finalize (object);
+}
+
+static void
+couchdb_array_field_class_init (CouchdbArrayFieldClass *klass)
 {
-	static GType object_type = 0;
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-	if (G_UNLIKELY (!object_type))
-		object_type = g_boxed_type_register_static (g_intern_static_string ("CouchdbArrayField"),
-							    (GBoxedCopyFunc) couchdb_array_field_ref,
-							    (GBoxedFreeFunc) couchdb_array_field_unref);
+	object_class->finalize = couchdb_array_field_finalize;
+}
 
-	return object_type;
+static void
+couchdb_array_field_init (CouchdbArrayField *array)
+{
+	array->priv = g_new0 (CouchdbArrayFieldPrivate, 1);
+	array->priv->json_array = json_array_new ();
 }
 
 /**
@@ -52,13 +70,7 @@ couchdb_array_field_get_type (void)
 CouchdbArrayField *
 couchdb_array_field_new (void)
 {
-	CouchdbArrayField *array;
-
-	array = g_slice_new (CouchdbArrayField);
-	array->ref_count = 1;
-	array->json_array = json_array_new ();
-
-	return array;
+	return g_object_new (COUCHDB_TYPE_ARRAY_FIELD, NULL);
 }
 
 CouchdbArrayField *
@@ -66,58 +78,14 @@ couchdb_array_field_new_from_json_array (JsonArray *json_array)
 {
 	CouchdbArrayField *array;
 
-	array = g_slice_new (CouchdbArrayField);
-	array->ref_count = 1;
-	array->json_array = json_array_ref (json_array);
-
-	return array;
-}
-
-/**
- * couchdb_array_field_ref:
- * @array: A #CouchdbArrayField object
- *
- * Increments reference count of a #CouchdbArrayField object.
- *
- * Return value: A pointer to the referenced object.
- */
-CouchdbArrayField *
-couchdb_array_field_ref (CouchdbArrayField *array)
-{
-	g_return_val_if_fail (array != NULL, NULL);
-	g_return_val_if_fail (array->ref_count > 0, NULL);
-
-	g_atomic_int_exchange_and_add (&array->ref_count, 1);
+	array = g_object_new (COUCHDB_TYPE_ARRAY_FIELD, NULL);
+	json_array_unref (array->priv->json_array);
+	array->priv->json_array = json_array_ref (json_array);
 
 	return array;
 }
 
 /**
- * couchdb_array_field_unref:
- * @array: A #CouchdbArrayField object
- *
- * Decrements reference count of a #CouchdbArrayField object. When
- * the reference count is equal to 0, the object will be destroyed and
- * the memory it uses freed.
- */
-void
-couchdb_array_field_unref (CouchdbArrayField *array)
-{
-	gint old_ref;
-
-	g_return_if_fail (array != NULL);
-	g_return_if_fail (array->ref_count > 0);
-
-	old_ref = g_atomic_int_get (&array->ref_count);
-	if (old_ref > 1)
-		g_atomic_int_compare_and_exchange (&array->ref_count, old_ref, old_ref - 1);
-	else {
-		json_array_unref (array->json_array);
-		g_slice_free (CouchdbArrayField, array);
-	}
-}
-
-/**
  * couchdb_array_field_get_length:
  * @array: A #CouchdbArrayField object
  *
@@ -130,7 +98,7 @@ couchdb_array_field_get_length (CouchdbArrayField *array)
 {
 	g_return_val_if_fail (array != NULL, 0);
 
-	return json_array_get_length (array->json_array);
+	return json_array_get_length (array->priv->json_array);
 }
 
 /**
@@ -145,7 +113,7 @@ couchdb_array_field_add_array_element (CouchdbArrayField *array, const CouchdbAr
 {
 	g_return_if_fail (array != NULL);
 
-	json_array_add_array_element (array->json_array, json_array_ref (value->json_array));
+	json_array_add_array_element (array->priv->json_array, json_array_ref (value->priv->json_array));
 }
 
 /**
@@ -160,7 +128,7 @@ couchdb_array_field_add_boolean_element (CouchdbArrayField *array, gboolean valu
 {
 	g_return_if_fail (array != NULL);
 
-	json_array_add_boolean_element (array->json_array, value);
+	json_array_add_boolean_element (array->priv->json_array, value);
 }
 
 /**
@@ -175,7 +143,7 @@ couchdb_array_field_add_int_element (CouchdbArrayField *array, gint value)
 {
 	g_return_if_fail (array != NULL);
 
-	json_array_add_int_element (array->json_array, value);
+	json_array_add_int_element (array->priv->json_array, value);
 }
 
 /**
@@ -190,7 +158,7 @@ couchdb_array_field_add_double_element (CouchdbArrayField *array, gdouble value)
 {
 	g_return_if_fail (array != NULL);
 
-	json_array_add_double_element (array->json_array, value);
+	json_array_add_double_element (array->priv->json_array, value);
 }
 
 /**
@@ -205,7 +173,7 @@ couchdb_array_field_add_string_element (CouchdbArrayField *array, const gchar *v
 {
 	g_return_if_fail (array != NULL);
 
-	json_array_add_string_element (array->json_array, value);
+	json_array_add_string_element (array->priv->json_array, value);
 }
 
 /**
@@ -221,7 +189,7 @@ couchdb_array_field_add_struct_element (CouchdbArrayField *array, const CouchdbS
 	g_return_if_fail (array != NULL);
 
 	json_array_add_object_element (
-		array->json_array,
+		array->priv->json_array,
 		json_object_ref (couchdb_struct_field_get_json_object ((CouchdbStructField *) value)));
 }
 
@@ -237,7 +205,7 @@ couchdb_array_field_remove_element (CouchdbArrayField *array, guint index)
 {
 	g_return_if_fail (array != NULL);
 
-	json_array_remove_element (array->json_array, index);
+	json_array_remove_element (array->priv->json_array, index);
 }
 
 /**
@@ -256,13 +224,13 @@ couchdb_array_field_get_array_element (CouchdbArrayField *array, guint index)
 	CouchdbArrayField *returned_array = NULL;
 	g_return_val_if_fail (array != NULL, NULL);
 
-	json_array = json_array_get_array_element (array->json_array, index);
+	json_array = json_array_get_array_element (array->priv->json_array, index);
 	if (json_array) {
 		guint i;
 
 		returned_array = couchdb_array_field_new ();
 		for (i = 0; i < json_array_get_length (json_array); i++) {
-			json_array_add_element (returned_array->json_array,
+			json_array_add_element (returned_array->priv->json_array,
 						json_array_get_element (json_array, index));
 		}
 	}
@@ -284,7 +252,7 @@ couchdb_array_field_get_boolean_element (CouchdbArrayField *array, guint index)
 {
 	g_return_val_if_fail (array != NULL, FALSE);
 
-	return json_array_get_boolean_element (array->json_array, index);
+	return json_array_get_boolean_element (array->priv->json_array, index);
 }
 
 /**
@@ -301,7 +269,7 @@ couchdb_array_field_get_double_element (CouchdbArrayField *array, guint index)
 {
 	g_return_val_if_fail (array != NULL, -1);
 
-	return json_array_get_double_element (array->json_array, index);
+	return json_array_get_double_element (array->priv->json_array, index);
 }
 
 /**
@@ -318,7 +286,7 @@ couchdb_array_field_get_int_element (CouchdbArrayField *array, guint index)
 {
 	g_return_val_if_fail (array != NULL, -1);
 
-	return json_array_get_int_element (array->json_array, index);
+	return json_array_get_int_element (array->priv->json_array, index);
 }
 
 /**
@@ -335,7 +303,7 @@ couchdb_array_field_get_string_element (CouchdbArrayField *array, guint index)
 {
 	g_return_val_if_fail (array != NULL, NULL);
 
-	return json_array_get_string_element (array->json_array, index);
+	return json_array_get_string_element (array->priv->json_array, index);
 }
 
 /**
@@ -354,7 +322,7 @@ couchdb_array_field_get_struct_element (CouchdbArrayField *array, guint index)
 
 	g_return_val_if_fail (array != NULL, NULL);
 
-	json_object = json_array_get_object_element (array->json_array, index);
+	json_object = json_array_get_object_element (array->priv->json_array, index);
 	if (json_object != NULL)
 		return couchdb_struct_field_new_from_json_object (json_object);
 
@@ -366,5 +334,5 @@ couchdb_array_field_get_json_array (CouchdbArrayField *array)
 {
 	g_return_val_if_fail (array != NULL, NULL);
 
-	return array->json_array;
+	return array->priv->json_array;
 }
diff --git a/couchdb-glib/couchdb-array-field.h b/couchdb-glib/couchdb-array-field.h
index 2c26373..7f87000 100644
--- a/couchdb-glib/couchdb-array-field.h
+++ b/couchdb-glib/couchdb-array-field.h
@@ -27,12 +27,19 @@
 
 G_BEGIN_DECLS
 
-#define COUCHDB_TYPE_ARRAY_FIELD (couchdb_array_field_get_type ())
+#define COUCHDB_TYPE_ARRAY_FIELD                (couchdb_array_field_get_type ())
+#define COUCHDB_ARRAY_FIELD(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE_ARRAY_FIELD, CouchdbArrayField))
+#define COUCHDB_IS_ARRAY_FIELD(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE_ARRAY_FIELD))
+#define COUCHDB_ARRAY_FIELD_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE_ARRAY_FIELD, CouchdbArrayFieldClass))
+#define COUCHDB_IS_ARRAY_FIELD_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_ARRAY_FIELD))
+#define COUCHDB_ARRAY_FIELD_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_ARRAY_FIELD, CouchdbArrayFieldClass))
+
+typedef struct {
+	GObjectClass parent_class;
+} CouchdbArrayFieldClass;
 
 GType               couchdb_array_field_get_type (void);
 CouchdbArrayField  *couchdb_array_field_new (void);
-CouchdbArrayField  *couchdb_array_field_ref (CouchdbArrayField *array);
-void                couchdb_array_field_unref (CouchdbArrayField *array);
 
 guint               couchdb_array_field_get_length (CouchdbArrayField *array);
 void                couchdb_array_field_add_array_element (CouchdbArrayField *array, const CouchdbArrayField *value);
diff --git a/couchdb-glib/couchdb-struct-field.c b/couchdb-glib/couchdb-struct-field.c
index 4b3a3f4..002eff6 100644
--- a/couchdb-glib/couchdb-struct-field.c
+++ b/couchdb-glib/couchdb-struct-field.c
@@ -25,25 +25,45 @@
 #include "utils.h"
 #include "couchdb-struct-field.h"
 
-struct _CouchdbStructField {
-	gint ref_count;
+struct _CouchdbStructFieldPrivate {
 	JsonObject *json_object;
 
 	/* Extra data needed for some specific StructField's */
 	char *uuid; /* the UUID of this item */
 };
 
-GType
-couchdb_struct_field_get_type (void)
+G_DEFINE_TYPE(CouchdbStructField, couchdb_struct_field, G_TYPE_OBJECT)
+
+static void
+couchdb_struct_field_finalize (GObject *object)
+{
+	CouchdbStructField *sf = COUCHDB_STRUCT_FIELD (object);
+
+	if (sf->priv != NULL) {
+		if (sf->priv->json_object != NULL)
+			json_object_unref (sf->priv->json_object);
+		if (sf->priv->uuid != NULL)
+			g_free (sf->priv->uuid);
+
+		g_free (sf->priv);
+	}
+
+	G_OBJECT_CLASS (couchdb_struct_field_parent_class)->finalize (object);
+}
+
+static void
+couchdb_struct_field_class_init (CouchdbStructFieldClass *klass)
 {
-	static GType object_type = 0;
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-	if (G_UNLIKELY (!object_type))
-		object_type = g_boxed_type_register_static (g_intern_static_string ("CouchdbStructField"),
-							    (GBoxedCopyFunc) couchdb_struct_field_ref,
-							    (GBoxedFreeFunc) couchdb_struct_field_unref);
+	object_class->finalize = couchdb_struct_field_finalize;
+}
 
-	return object_type;
+static void
+couchdb_struct_field_init (CouchdbStructField *sf)
+{
+	sf->priv = g_new0 (CouchdbStructFieldPrivate, 1);
+	sf->priv->json_object = json_object_new ();
 }
 
 /**
@@ -57,14 +77,7 @@ couchdb_struct_field_get_type (void)
 CouchdbStructField *
 couchdb_struct_field_new (void)
 {
-	CouchdbStructField *sf;
-
-	sf = g_slice_new (CouchdbStructField);
-	sf->ref_count = 1;
-	sf->json_object = json_object_new ();
-	sf->uuid = NULL;
-
-	return sf;
+	return g_object_new (COUCHDB_TYPE_STRUCT_FIELD, NULL);
 }
 
 /**
@@ -106,60 +119,14 @@ couchdb_struct_field_new_from_json_object (JsonObject *json_object)
 {
 	CouchdbStructField *sf;
 
-	sf = g_slice_new (CouchdbStructField);
-	sf->ref_count = 1;
-	sf->json_object = json_object_ref (json_object);
-	sf->uuid = NULL;
-
-	return sf;
-}
-
-/**
- * couchdb_struct_field_ref:
- * @sf: A #CouchdbStructField object
- *
- * Increments reference count of a #CouchdbStructField object.
- *
- * Return value: A pointer to the referenced object.
- */
-CouchdbStructField *
-couchdb_struct_field_ref (CouchdbStructField *sf)
-{
-	g_return_val_if_fail (sf != NULL, NULL);
-	g_return_val_if_fail (sf->ref_count > 0, NULL);
-
-	g_atomic_int_exchange_and_add (&sf->ref_count, 1);
+	sf = g_object_new (COUCHDB_TYPE_STRUCT_FIELD, NULL);
+	json_object_unref (sf->priv->json_object);
+	sf->priv->json_object = json_object_ref (json_object);
 
 	return sf;
 }
 
 /**
- * couchdb_struct_field_unref:
- * @sf: A #CouchdbStructField object
- *
- * Decrements reference count of a #CouchdbStructField object. When
- * the reference count is equal to 0, the object will be destroyed and
- * the memory it uses freed.
- */
-void
-couchdb_struct_field_unref (CouchdbStructField *sf)
-{
-	gint old_ref;
-
-	g_return_if_fail (sf != NULL);
-	g_return_if_fail (sf->ref_count > 0);
-
-	old_ref = g_atomic_int_get (&sf->ref_count);
-	if (old_ref > 1)
-		g_atomic_int_compare_and_exchange (&sf->ref_count, old_ref, old_ref - 1);
-	else {
-		g_free (sf->uuid);
-		json_object_unref (sf->json_object);
-		g_slice_free (CouchdbStructField, sf);
-	}
-}
-
-/**
  * couchdb_struct_field_has_field:
  * @sf: A #CouchdbStructField object
  * @field: Name of the field to check
@@ -174,7 +141,7 @@ couchdb_struct_field_has_field (CouchdbStructField *sf, const char *field)
 	g_return_val_if_fail (sf != NULL, FALSE);
 	g_return_val_if_fail (field != NULL, FALSE);
 
-	return json_object_has_member (sf->json_object, field);
+	return json_object_has_member (sf->priv->json_object, field);
 }
 
 /**
@@ -190,7 +157,7 @@ couchdb_struct_field_remove_field (CouchdbStructField *sf, const char *field)
 	g_return_if_fail (sf != NULL);
 	g_return_if_fail (field != NULL);
 
-	json_object_remove_member (sf->json_object, field);
+	json_object_remove_member (sf->priv->json_object, field);
 }
 
 /**
@@ -208,11 +175,11 @@ couchdb_struct_field_get_array_field (CouchdbStructField *sf, const char *field)
 	g_return_val_if_fail (sf != NULL, NULL);
 	g_return_val_if_fail (field != NULL, NULL);
 
-	if (!json_object_has_member (sf->json_object, field))
+	if (!json_object_has_member (sf->priv->json_object, field))
 		return NULL;
 
 	return couchdb_array_field_new_from_json_array (
-		json_object_get_array_member (sf->json_object, field));
+		json_object_get_array_member (sf->priv->json_object, field));
 }
 
 /**
@@ -230,7 +197,7 @@ couchdb_struct_field_set_array_field (CouchdbStructField *sf, const char *field,
 	g_return_if_fail (field != NULL);
 	g_return_if_fail (value != NULL);
 
-	json_object_set_array_member (sf->json_object, field, json_array_ref (couchdb_array_field_get_json_array (value)));
+	json_object_set_array_member (sf->priv->json_object, field, json_array_ref (couchdb_array_field_get_json_array (value)));
 }
 
 /**
@@ -248,7 +215,7 @@ couchdb_struct_field_get_boolean_field (CouchdbStructField *sf, const char *fiel
 	g_return_val_if_fail (sf != NULL, FALSE);
 	g_return_val_if_fail (field != NULL, FALSE);
 
-	return json_object_get_boolean_member (sf->json_object, field);
+	return json_object_get_boolean_member (sf->priv->json_object, field);
 }
 
 /**
@@ -265,7 +232,7 @@ couchdb_struct_field_set_boolean_field (CouchdbStructField *sf, const char *fiel
 	g_return_if_fail (sf != NULL);
 	g_return_if_fail (field != NULL);
 
-	json_object_set_boolean_member (sf->json_object, field, value);
+	json_object_set_boolean_member (sf->priv->json_object, field, value);
 }
 
 /**
@@ -283,7 +250,7 @@ couchdb_struct_field_get_double_field (CouchdbStructField *sf, const char *field
 	g_return_val_if_fail (sf != NULL, 0);
 	g_return_val_if_fail (field != NULL, 0);
 
-	return json_object_get_double_member (sf->json_object, field);
+	return json_object_get_double_member (sf->priv->json_object, field);
 }
 
 /**
@@ -300,7 +267,7 @@ couchdb_struct_field_set_double_field (CouchdbStructField *sf, const char *field
 	g_return_if_fail (sf != NULL);
 	g_return_if_fail (field != NULL);
 
-	json_object_set_double_member (sf->json_object, field, value);
+	json_object_set_double_member (sf->priv->json_object, field, value);
 }
 
 /**
@@ -318,7 +285,7 @@ couchdb_struct_field_get_int_field (CouchdbStructField *sf, const char *field)
 	g_return_val_if_fail (sf != NULL, 0);
 	g_return_val_if_fail (field != NULL, 0);
 
-	return json_object_get_int_member (sf->json_object, field);
+	return json_object_get_int_member (sf->priv->json_object, field);
 }
 
 /**
@@ -335,7 +302,7 @@ couchdb_struct_field_set_int_field (CouchdbStructField *sf, const char *field, g
 	g_return_if_fail (sf != NULL);
 	g_return_if_fail (field != NULL);
 
-	json_object_set_int_member (sf->json_object, field, value);
+	json_object_set_int_member (sf->priv->json_object, field, value);
 }
 
 /**
@@ -353,7 +320,7 @@ couchdb_struct_field_get_string_field (CouchdbStructField *sf, const char *field
 	g_return_val_if_fail (sf != NULL, NULL);
 	g_return_val_if_fail (field != NULL, NULL);
 
-	return json_object_get_string_member (sf->json_object, field);
+	return json_object_get_string_member (sf->priv->json_object, field);
 }
 
 /**
@@ -371,7 +338,7 @@ couchdb_struct_field_set_string_field (CouchdbStructField *sf, const char *field
 	g_return_if_fail (field != NULL);
 
 	if (value)
-		json_object_set_string_member (sf->json_object, field, value);
+		json_object_set_string_member (sf->priv->json_object, field, value);
 	else {
 		/* Remove the field if the value is NULL */
 		couchdb_struct_field_remove_field (sf, field);
@@ -393,11 +360,11 @@ couchdb_struct_field_get_struct_field (CouchdbStructField *sf, const char *field
 	g_return_val_if_fail (sf != NULL, NULL);
 	g_return_val_if_fail (field != NULL, NULL);
 
-	if (!json_object_has_member (sf->json_object, field))
+	if (!json_object_has_member (sf->priv->json_object, field))
 		return NULL;
 
 	return couchdb_struct_field_new_from_json_object (
-		json_object_get_object_member (sf->json_object, field));
+		json_object_get_object_member (sf->priv->json_object, field));
 }
 
 /**
@@ -415,7 +382,7 @@ couchdb_struct_field_set_struct_field (CouchdbStructField *sf, const char *field
 	g_return_if_fail (field != NULL);
 	g_return_if_fail (value != NULL);
 
-	json_object_set_object_member (sf->json_object, field, json_object_ref (value->json_object));
+	json_object_set_object_member (sf->priv->json_object, field, json_object_ref (value->priv->json_object));
 }
 
 /**
@@ -440,7 +407,7 @@ couchdb_struct_field_get_uuid (CouchdbStructField *sf)
 {
 	g_return_val_if_fail (sf != NULL, NULL);
 
-	return (const char *) sf->uuid;
+	return (const char *) sf->priv->uuid;
 }
 
 /**
@@ -456,10 +423,10 @@ couchdb_struct_field_set_uuid (CouchdbStructField *sf, const char *uuid)
 {
 	g_return_if_fail (sf != NULL);
 
-	if (sf->uuid)
-		g_free (sf->uuid);
+	if (sf->priv->uuid)
+		g_free (sf->priv->uuid);
 
-	sf->uuid = g_strdup (uuid);
+	sf->priv->uuid = g_strdup (uuid);
 }
 
 /**
@@ -482,7 +449,7 @@ couchdb_struct_field_to_string (CouchdbStructField *sf)
 	g_return_val_if_fail (sf != NULL, NULL);
 
 	node = json_node_new (JSON_NODE_OBJECT);
-	json_node_set_object (node, sf->json_object);
+	json_node_set_object (node, sf->priv->json_object);
 
 	generator = json_generator_new ();
 	json_generator_set_root (generator, node);
@@ -500,6 +467,6 @@ couchdb_struct_field_get_json_object (CouchdbStructField *sf)
 {
 	g_return_val_if_fail (sf != NULL, NULL);
 	
-	return sf->json_object;
+	return sf->priv->json_object;
 }
 
diff --git a/couchdb-glib/couchdb-struct-field.h b/couchdb-glib/couchdb-struct-field.h
index e816f79..037dd28 100644
--- a/couchdb-glib/couchdb-struct-field.h
+++ b/couchdb-glib/couchdb-struct-field.h
@@ -32,13 +32,20 @@
 
 G_BEGIN_DECLS
 
-#define COUCHDB_TYPE_STRUCT_FIELD  (couchdb_struct_field_get_type ())
+#define COUCHDB_TYPE_STRUCT_FIELD                (couchdb_struct_field_get_type ())
+#define COUCHDB_STRUCT_FIELD(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE_STRUCT_FIELD, CouchdbStructField))
+#define COUCHDB_IS_STRUCT_FIELD(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE_STRUCT_FIELD))
+#define COUCHDB_STRUCT_FIELD_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE_STRUCT_FIELD, CouchdbStructFieldClass))
+#define COUCHDB_IS_STRUCT_FIELD_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_STRUCT_FIELD))
+#define COUCHDB_STRUCT_FIELD_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_STRUCT_FIELD, CouchdbStructFieldClass))
+
+typedef struct {
+	GObjectClass parent_class;
+} CouchdbStructFieldClass;
 
 GType               couchdb_struct_field_get_type (void);
 CouchdbStructField *couchdb_struct_field_new (void);
 CouchdbStructField *couchdb_struct_field_new_from_string (const char *str);
-CouchdbStructField *couchdb_struct_field_ref (CouchdbStructField *sf);
-void                couchdb_struct_field_unref (CouchdbStructField *sf);
 
 gboolean            couchdb_struct_field_has_field (CouchdbStructField *sf, const char *field);
 void                couchdb_struct_field_remove_field (CouchdbStructField *sf, const char *field);
diff --git a/couchdb-glib/couchdb-types.h b/couchdb-glib/couchdb-types.h
index 9065927..c4881e7 100644
--- a/couchdb-glib/couchdb-types.h
+++ b/couchdb-glib/couchdb-types.h
@@ -25,13 +25,26 @@
 #define __COUCHDB_TYPES_H__
 
 #include <glib.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
-typedef struct _CouchdbArrayField CouchdbArrayField;
 typedef struct _CouchdbDatabaseInfo CouchdbDatabaseInfo;
 typedef struct _CouchdbDocumentInfo CouchdbDocumentInfo;
-typedef struct _CouchdbStructField CouchdbStructField;
+
+typedef struct _CouchdbArrayFieldPrivate CouchdbArrayFieldPrivate;
+
+typedef struct {
+	GObject parent;
+	CouchdbArrayFieldPrivate *priv;
+} CouchdbArrayField;
+
+typedef struct _CouchdbStructFieldPrivate CouchdbStructFieldPrivate;
+
+typedef struct {
+	GObject parent;
+	CouchdbStructFieldPrivate *priv;
+} CouchdbStructField;
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]