[couchdb-glib] Make all functions use utility functions and make these remove fields from documents when values are
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Subject: [couchdb-glib] Make all functions use utility functions and make these remove fields from documents when values are
- Date: Mon, 27 Jul 2009 21:52:17 +0000 (UTC)
commit 6f1f608c89454fe8fabcbd78af14bd5159a641be
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Mon Jul 27 23:52:04 2009 +0200
Make all functions use utility functions and make these remove fields from documents when values are NULL
couchdb-glib/couchdb-document-contact.c | 71 +++++++++++++-----------------
couchdb-glib/couchdb-document.c | 11 ++++-
couchdb-glib/couchdb-types.c | 8 +++-
couchdb-glib/utils.c | 1 +
tests/test-list-databases.c | 2 +-
5 files changed, 47 insertions(+), 46 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index ed055ff..6c2076c 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -28,7 +28,7 @@ couchdb_document_contact_get_first_name (CouchDBDocument *document)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
- return json_object_get_string_member (json_node_get_object (document->root_node), "first_name");
+ return couchdb_document_get_string_field (document, "first_name");
}
void
@@ -38,7 +38,7 @@ couchdb_document_contact_set_first_name (CouchDBDocument *document, const char *
g_return_if_fail (couchdb_document_is_contact (document));
g_return_if_fail (first_name != NULL);
- json_object_set_string_member (json_node_get_object (document->root_node), "first_name", first_name);
+ couchdb_document_set_string_field (document, "first_name", first_name);
}
const char *
@@ -47,7 +47,7 @@ couchdb_document_contact_get_last_name (CouchDBDocument *document)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
- return json_object_get_string_member (json_node_get_object (document->root_node), "last_name");
+ return couchdb_document_get_string_field (document, "last_name");
}
void
@@ -57,7 +57,7 @@ couchdb_document_contact_set_last_name (CouchDBDocument *document, const char *l
g_return_if_fail (couchdb_document_is_contact (document));
g_return_if_fail (last_name != NULL);
- json_object_set_string_member (json_node_get_object (document->root_node), "last_name", last_name);
+ couchdb_document_set_string_field (document, "last_name", last_name);
}
const char *
@@ -68,7 +68,7 @@ couchdb_document_contact_get_birth_date (CouchDBDocument *document)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
- return json_object_get_string_member (json_node_get_object (document->root_node), "birth_date");
+ return couchdb_document_get_string_field (document, "birth_date");
}
void
@@ -78,7 +78,7 @@ couchdb_document_contact_set_birth_date (CouchDBDocument *document, const char *
g_return_if_fail (couchdb_document_is_contact (document));
g_return_if_fail (birth_date != NULL);
- json_object_set_string_member (json_node_get_object (document->root_node), "birth_date", birth_date);
+ couchdb_document_set_string_field (document, "birth_date", birth_date);
}
static void
@@ -295,7 +295,7 @@ couchdb_document_contact_email_get_address (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "address");
+ return couchdb_struct_field_get_string_field (sf, "address");
}
void
@@ -304,7 +304,7 @@ couchdb_document_contact_email_set_address (CouchDBStructField *sf, const char *
g_return_if_fail (sf != NULL);
g_return_if_fail (email != NULL);
- json_object_set_string_member (sf->json_object, "address", email);
+ couchdb_struct_field_set_string_field (sf, "address", email);
}
const char *
@@ -312,16 +312,15 @@ couchdb_document_contact_email_get_description (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "description");
+ return couchdb_struct_field_get_string_field (sf, "description");
}
void
couchdb_document_contact_email_set_description (CouchDBStructField *sf, const char *description)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (description != NULL);
- json_object_set_string_member (sf->json_object, "description", description);
+ couchdb_struct_field_set_string_field (sf, "description", description);
}
CouchDBStructField *
@@ -344,7 +343,7 @@ couchdb_document_contact_phone_get_priority (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, 0);
- return json_object_get_int_member (sf->json_object, "priority");
+ return couchdb_struct_field_get_int_field (sf, "priority");
}
void
@@ -352,15 +351,15 @@ couchdb_document_contact_phone_set_priority (CouchDBStructField *sf, gint priori
{
g_return_if_fail (sf != NULL);
- json_object_set_int_member (sf->json_object, "priority", priority);
+ couchdb_struct_field_set_int_field (sf, "priority", priority);
}
const char *
couchdb_document_contact_phone_get_number (CouchDBStructField *sf)
{
- g_return_val_if_fail (sf->json_object, NULL);
+ g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "number");
+ return couchdb_struct_field_get_string_field (sf, "number");
}
void
@@ -369,7 +368,7 @@ couchdb_document_contact_phone_set_number (CouchDBStructField *sf, const char *n
g_return_if_fail (sf != NULL);
g_return_if_fail (number != NULL);
- json_object_set_string_member (sf->json_object, "number", number);
+ couchdb_struct_field_set_string_field (sf, "number", number);
}
const char *
@@ -377,16 +376,15 @@ couchdb_document_contact_phone_get_description (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "description");
+ return couchdb_struct_field_get_string_field (sf, "description");
}
void
couchdb_document_contact_phone_set_description (CouchDBStructField *sf, const char *description)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (description != NULL);
- json_object_set_string_member (sf->json_object, "description", description);
+ couchdb_struct_field_set_string_field (sf, "description", description);
}
CouchDBStructField *
@@ -424,16 +422,15 @@ couchdb_document_contact_address_get_street (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "address1");
+ return couchdb_struct_field_get_string_field (sf, "address1");
}
void
couchdb_document_contact_address_set_street (CouchDBStructField *sf, const char *street)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (street != NULL);
- json_object_set_string_member (sf->json_object, "address1", street);
+ couchdb_struct_field_set_string_field (sf, "address1", street);
}
const char *
@@ -441,16 +438,15 @@ couchdb_document_contact_address_get_city (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "city");
+ return couchdb_struct_field_get_string_field (sf, "city");
}
void
couchdb_document_contact_address_set_city (CouchDBStructField *sf, const char *city)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (city != NULL);
- json_object_set_string_member (sf->json_object, "city", city);
+ couchdb_struct_field_set_string_field (sf, "city", city);
}
const char *
@@ -458,16 +454,15 @@ couchdb_document_contact_address_get_state (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "state");
+ return couchdb_struct_field_get_string_field (sf, "state");
}
void
couchdb_document_contact_address_set_state (CouchDBStructField *sf, const char *state)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (state != NULL);
- json_object_set_string_member (sf->json_object, "state", state);
+ couchdb_struct_field_set_string_field (sf, "state", state);
}
const char *
@@ -475,16 +470,15 @@ couchdb_document_contact_address_get_country (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "country");
+ return couchdb_struct_field_get_string_field (sf, "country");
}
void
couchdb_document_contact_address_set_country (CouchDBStructField *sf, const char *country)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (country != NULL);
- json_object_set_string_member (sf->json_object, "country", country);
+ couchdb_struct_field_set_string_field (sf, "country", country);
}
const char *
@@ -492,16 +486,15 @@ couchdb_document_contact_address_get_postalcode (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "postalcode");
+ return couchdb_struct_field_get_string_field (sf, "postalcode");
}
void
couchdb_document_contact_address_set_postalcode (CouchDBStructField *sf, const char *postalcode)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (postalcode != NULL);
- json_object_set_string_member (sf->json_object, "postalcode", postalcode);
+ couchdb_struct_field_set_string_field (sf, "postalcode", postalcode);
}
const char *
@@ -509,16 +502,15 @@ couchdb_document_contact_address_get_pobox (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "pobox");
+ return couchdb_struct_field_get_string_field (sf, "pobox");
}
void
couchdb_document_contact_address_set_pobox (CouchDBStructField *sf, const char *pobox)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (pobox != NULL);
- json_object_set_string_member (sf->json_object, "pobox", pobox);
+ couchdb_struct_field_set_string_field (sf, "pobox", pobox);
}
const char *
@@ -526,14 +518,13 @@ couchdb_document_contact_address_get_description (CouchDBStructField *sf)
{
g_return_val_if_fail (sf != NULL, NULL);
- return json_object_get_string_member (sf->json_object, "description");
+ return couchdb_struct_field_get_string_field (sf, "description");
}
void
couchdb_document_contact_address_set_description (CouchDBStructField *sf, const char *description)
{
g_return_if_fail (sf != NULL);
- g_return_if_fail (description != NULL);
- json_object_set_string_member (sf->json_object, "description", description);
+ couchdb_struct_field_set_string_field (sf, "description", description);
}
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index a5a6a7f..a45cd2c 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -337,9 +337,14 @@ couchdb_document_set_string_field (CouchDBDocument *document, const char *field,
g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
g_return_if_fail (field != NULL);
- json_object_set_string_member (json_node_get_object (document->root_node),
- field,
- value);
+ if (value) {
+ json_object_set_string_member (json_node_get_object (document->root_node),
+ field,
+ value);
+ } else {
+ /* Remove field if it's a NULL value */
+ couchdb_document_remove_field (document, field);
+ }
}
CouchDBStructField *
diff --git a/couchdb-glib/couchdb-types.c b/couchdb-glib/couchdb-types.c
index 859cf52..c043457 100644
--- a/couchdb-glib/couchdb-types.c
+++ b/couchdb-glib/couchdb-types.c
@@ -366,9 +366,13 @@ couchdb_struct_field_set_string_field (CouchDBStructField *sf, const char *field
{
g_return_if_fail (sf != NULL);
g_return_if_fail (field != NULL);
- g_return_if_fail (value != NULL);
- json_object_set_string_member (sf->json_object, field, value);
+ if (value)
+ json_object_set_string_member (sf->json_object, field, value);
+ else {
+ /* Remove the field if the value is NULL */
+ couchdb_struct_field_remove_field (sf, field);
+ }
}
CouchDBStructField *
diff --git a/couchdb-glib/utils.c b/couchdb-glib/utils.c
index 2a1fab0..83c5473 100644
--- a/couchdb-glib/utils.c
+++ b/couchdb-glib/utils.c
@@ -19,6 +19,7 @@
* Boston, MA 02110-1301, USA.
*/
+#include <string.h>
#include <libsoup/soup-session-async.h>
#include "couchdb-glib.h"
#include "utils.h"
diff --git a/tests/test-list-databases.c b/tests/test-list-databases.c
index e12babb..4dd5efb 100644
--- a/tests/test-list-databases.c
+++ b/tests/test-list-databases.c
@@ -81,7 +81,7 @@ main (int argc, char *argv[])
document = couchdb_document_get (couchdb,
(const char *) sl->data,
couchdb_document_info_get_docid (doc_info),
- error);
+ &error);
if (document) {
char *json;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]