[couchdb-glib] Add API to retrieve values from arrays



commit 41f67ff6dfeae5870d1b79480f433bf08356c31b
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Feb 12 18:31:48 2010 +0100

    Add API to retrieve values from arrays

 NEWS                               |   12 ++++
 configure.ac                       |    2 +-
 couchdb-glib/couchdb-array-field.c |  121 ++++++++++++++++++++++++++++++++++++
 couchdb-glib/couchdb-array-field.h |   32 ++++++----
 4 files changed, 153 insertions(+), 14 deletions(-)
---
diff --git a/NEWS b/NEWS
index 8d4c9a4..189baa4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,15 @@
+=============
+Version 0.6.0
+=============
+- Move contacts record code to desktopcouch-glib (Rodrigo Moya)
+- Add categories API for contacts documents (Rodrigo Moya)
+- Don't force callers to pass a GError (Rodrigo Moya)
+- Add replication API (Rodrigo Moya)
+- Add API for compacting databases (Rodrigo Moya)
+- Add API documentation (Rodrigo Moya)
+- Free also the uuid stored in CouchdbStructField object (Rodrigo Moya)
+- Add CouchdbArrayField object (Rodrigo Moya)
+
 ==============
 Version 0.5.99
 ==============
diff --git a/configure.ac b/configure.ac
index 909c4e7..c1ad2b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([couchdb-glib], [0.5.99], [], [couchdb-glib])
+AC_INIT([couchdb-glib], [0.6.0], [], [couchdb-glib])
 
 AC_PREREQ([2.59])
 
diff --git a/couchdb-glib/couchdb-array-field.c b/couchdb-glib/couchdb-array-field.c
index 404187c..adae7aa 100644
--- a/couchdb-glib/couchdb-array-field.c
+++ b/couchdb-glib/couchdb-array-field.c
@@ -226,3 +226,124 @@ couchdb_array_field_remove_element (CouchdbArrayField *array, guint index)
 
 	json_array_remove_element (array->json_array, index);
 }
+
+/**
+ * couchdb_array_field_get_array_element:
+ * @array: A #CouchdbArrayField object
+ * @index: Position of the element to retrieve
+ *
+ * Retrieve an array value on the given position of the array.
+ *
+ * Return value: Value of the element stored in the given position of the array.
+ */
+CouchdbArrayField *
+couchdb_array_field_get_array_element (CouchdbArrayField *array, guint index)
+{
+	JsonArray *json_array;
+	CouchdbArrayField *returned_array = NULL;
+	g_return_val_if_fail (array != NULL, NULL);
+
+	json_array = json_array_get_array_element (array->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_get_element (json_array));
+		}
+	}
+
+	return returned_array;
+}
+
+/**
+ * couchdb_array_field_get_boolean_element:
+ * @array: A #CouchdbArrayField object
+ * @index: Position of the element to retrieve
+ *
+ * Retrieve a boolean value on the given position of the array.
+ *
+ * Return value: Value of the element stored in the given position of the array.
+ */
+gboolean
+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);
+}
+
+/**
+ * couchdb_array_field_get_double_element:
+ * @array: A #CouchdbArrayField object
+ * @index: Position of the element to retrieve
+ *
+ * Retrieve a double value on the given position of the array.
+ *
+ * Return value: Value of the element stored in the given position of the array.
+ */
+gdouble
+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);
+}
+
+/**
+ * couchdb_array_field_get_int_element:
+ * @array: A #CouchdbArrayField object
+ * @index: Position of the element to retrieve
+ *
+ * Retrieve an integer value on the given position of the array.
+ *
+ * Return value: Value of the element stored in the given position of the array.
+ */
+gint
+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);
+}
+
+/**
+ * couchdb_array_field_get_string_element:
+ * @array: A #CouchdbArrayField object
+ * @index: Position of the element to retrieve
+ *
+ * Retrieve a string value on the given position of the array.
+ *
+ * Return value: Value of the element stored in the given position of the array.
+ */
+const gchar *
+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);
+}
+
+/**
+ * couchdb_array_field_get_struct_element:
+ * @array: A #CouchdbArrayField object
+ * @index: Position of the element to retrieve
+ *
+ * Retrieve a struct value on the given position of the array.
+ *
+ * Return value: Value of the element stored in the given position of the array.
+ */
+CouchdbStructField *
+couchdb_array_field_get_string_element (CouchdbArrayField *array, guint index)
+{
+	JsonObject *json_object;
+
+	g_return_val_if_fail (array != NULL, NULL);
+
+	json_object = json_array_get_object_element (array->json_array, index);
+	if (json_object != NULL)
+		return couchdb_struct_field_new_from_json_object (json_object);
+
+	return NULL;
+}
diff --git a/couchdb-glib/couchdb-array-field.h b/couchdb-glib/couchdb-array-field.h
index 168cb69..c4e2f85 100644
--- a/couchdb-glib/couchdb-array-field.h
+++ b/couchdb-glib/couchdb-array-field.h
@@ -29,19 +29,25 @@ G_BEGIN_DECLS
 
 #define COUCHDB_TYPE_ARRAY_FIELD (couchdb_array_field_get_type ())
 
-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);
-void               couchdb_array_field_add_boolean_element (CouchdbArrayField *array, gboolean value);
-void               couchdb_array_field_add_double_element (CouchdbArrayField *array, gdouble value);
-void               couchdb_array_field_add_int_element (CouchdbArrayField *array, gint value);
-void               couchdb_array_field_add_string_element (CouchdbArrayField *array, const gchar *value);
-void               couchdb_array_field_add_struct_element (CouchdbArrayField *array, const CouchdbStructField *value);
-void               couchdb_array_field_remove_element (CouchdbArrayField *array, guint index);
+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);
+void                couchdb_array_field_add_boolean_element (CouchdbArrayField *array, gboolean value);
+void                couchdb_array_field_add_double_element (CouchdbArrayField *array, gdouble value);
+void                couchdb_array_field_add_int_element (CouchdbArrayField *array, gint value);
+void                couchdb_array_field_add_string_element (CouchdbArrayField *array, const gchar *value);
+void                couchdb_array_field_add_struct_element (CouchdbArrayField *array, const CouchdbStructField *value);
+void                couchdb_array_field_remove_element (CouchdbArrayField *array, guint index);
+
+gboolean            couchdb_array_field_get_boolean_element (CouchdbArrayField *array, guint index);
+gdouble             couchdb_array_field_get_double_element (CouchdbArrayField *array, guint index);
+gint                couchdb_array_field_get_int_element (CouchdbArrayField *array, guint index);
+const gchar        *couchdb_array_field_get_string_element (CouchdbArrayField *array, guint index);
+CouchdbStructField *couchdb_array_field_get_struct_element (CouchdbArrayField *array, guint index);
 
 G_END_DECLS
 



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