[couchdb-glib] Add array fields for CouchdbStructField and hide internal API
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Add array fields for CouchdbStructField and hide internal API
- Date: Fri, 12 Feb 2010 18:04:57 +0000 (UTC)
commit 660c19385f7fdf26f3d042001e77629b171cbf04
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Fri Feb 12 18:41:47 2010 +0100
Add array fields for CouchdbStructField and hide internal API
couchdb-glib/couchdb-array-field.c | 12 +++++++++
couchdb-glib/couchdb-array-field.h | 1 +
couchdb-glib/couchdb-struct-field.c | 46 ++++++++++++++++++++++++++++++++--
couchdb-glib/couchdb-struct-field.h | 7 +----
couchdb-glib/utils.h | 6 ++++
5 files changed, 64 insertions(+), 8 deletions(-)
---
diff --git a/couchdb-glib/couchdb-array-field.c b/couchdb-glib/couchdb-array-field.c
index adae7aa..a448ede 100644
--- a/couchdb-glib/couchdb-array-field.c
+++ b/couchdb-glib/couchdb-array-field.c
@@ -60,6 +60,18 @@ couchdb_array_field_new (void)
return array;
}
+CouchdbArrayField *
+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
diff --git a/couchdb-glib/couchdb-array-field.h b/couchdb-glib/couchdb-array-field.h
index c4e2f85..2c26373 100644
--- a/couchdb-glib/couchdb-array-field.h
+++ b/couchdb-glib/couchdb-array-field.h
@@ -43,6 +43,7 @@ void couchdb_array_field_add_string_element (CouchdbArrayField *a
void couchdb_array_field_add_struct_element (CouchdbArrayField *array, const CouchdbStructField *value);
void couchdb_array_field_remove_element (CouchdbArrayField *array, guint index);
+CouchdbArrayField *couchdb_array_field_get_array_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);
diff --git a/couchdb-glib/couchdb-struct-field.c b/couchdb-glib/couchdb-struct-field.c
index 39c6239..a48cdec 100644
--- a/couchdb-glib/couchdb-struct-field.c
+++ b/couchdb-glib/couchdb-struct-field.c
@@ -200,6 +200,46 @@ couchdb_struct_field_remove_field (CouchdbStructField *sf, const char *field)
}
/**
+ * couchdb_struct_field_get_array_field:
+ * @sf: A #CouchdbStructField object
+ * @field: Name of the field
+ *
+ * Retrieve the value of an array field from the given struct field.
+ *
+ * Return value: The value of the given field.
+ */
+CouchdbArrayField *
+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))
+ return NULL;
+
+ return couchdb_array_field_new_from_json_array (
+ json_object_get_array_member (sf->json_object, field));
+}
+
+/**
+ * couchdb_struct_field_set_array_field:
+ * @sf: A #CouchdbStructField object
+ * @field: Name of the field
+ * @calue: Value to set the field to
+ *
+ * Set the value of an array field in the given struct field.
+ */
+void
+couchdb_struct_field_set_struct_field (CouchdbStructField *sf, const char *field, CouchdbArrayField *value)
+{
+ g_return_if_fail (sf != NULL);
+ 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)));
+}
+
+/**
* couchdb_struct_field_get_boolean_field:
* @sf: A #CouchdbStructField object
* @field: Name of the field
@@ -211,8 +251,8 @@ couchdb_struct_field_remove_field (CouchdbStructField *sf, const char *field)
gboolean
couchdb_struct_field_get_boolean_field (CouchdbStructField *sf, const char *field)
{
- g_return_val_if_fail (sf != NULL, 0);
- g_return_val_if_fail (field != NULL, 0);
+ 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);
}
@@ -367,7 +407,7 @@ couchdb_struct_field_get_struct_field (CouchdbStructField *sf, const char *field
}
/**
- * couchdb_struct_field_set_string_field:
+ * couchdb_struct_field_set_struct_field:
* @sf: A #CouchdbStructField object
* @field: Name of the field
* @calue: Value to set the field to
diff --git a/couchdb-glib/couchdb-struct-field.h b/couchdb-glib/couchdb-struct-field.h
index 0987239..ef1d81f 100644
--- a/couchdb-glib/couchdb-struct-field.h
+++ b/couchdb-glib/couchdb-struct-field.h
@@ -26,7 +26,6 @@
#include <glib.h>
#include <glib-object.h>
-#include <json-glib/json-glib.h>
#include "couchdb-session.h"
#include "couchdb-types.h"
@@ -43,6 +42,8 @@ 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);
+CouchdbArrayField *couchdb_struct_field_get_array_field (CouchdbStructField *sf, const char *field);
+void couchdb_struct_field_set_array_field (CouchdbStructField *sf, const char *field, CouchdbArrayField *value);
gboolean couchdb_struct_field_get_boolean_field (CouchdbStructField *sf, const char *field);
void couchdb_struct_field_set_boolean_field (CouchdbStructField *sf, const char *field, gboolean value);
gdouble couchdb_struct_field_get_double_field (CouchdbStructField *sf, const char *field);
@@ -59,10 +60,6 @@ void couchdb_struct_field_set_uuid (CouchdbStructField *sf, const
char *couchdb_struct_field_to_string (CouchdbStructField *sf);
-CouchdbStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_object);
-
-JsonObject *couchdb_struct_field_get_json_object (CouchdbStructField *sf);
-
G_END_DECLS
#endif /* __COUCHDB_STRUCT_FIELD__ */
diff --git a/couchdb-glib/utils.h b/couchdb-glib/utils.h
index 14fbfdc..3eebe66 100644
--- a/couchdb-glib/utils.h
+++ b/couchdb-glib/utils.h
@@ -37,4 +37,10 @@ GQuark couchdb_error_quark (void);
char* generate_uuid (void);
+/* Private API */
+CouchdbArrayField *couchdb_array_field_new_from_json_array (JsonArray *json_array);
+JsonArray *couchdb_array_field_get_json_array (CouchdbArrayField *array);
+CouchdbStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_object);
+JsonObject *couchdb_struct_field_get_json_object (CouchdbStructField *sf);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]