You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2012/12/05 00:03:02 UTC

[lucy-commits] [2/9] git commit: refs/heads/c-bindings-wip1 - Initial Doc implementation for C bindings

Initial Doc implementation for C bindings


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/61483f11
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/61483f11
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/61483f11

Branch: refs/heads/c-bindings-wip1
Commit: 61483f11648760157fa887ff26cf3d071effaaa9
Parents: 27a89bf
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Nov 25 20:39:34 2012 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Dec 5 00:00:32 2012 +0100

----------------------------------------------------------------------
 c/src/Lucy/Document/Doc.c |   57 ++++++++++++++++++++++++++++++----------
 1 files changed, 43 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/61483f11/c/src/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Document/Doc.c b/c/src/Lucy/Document/Doc.c
index db1d8f7..a855ba3 100644
--- a/c/src/Lucy/Document/Doc.c
+++ b/c/src/Lucy/Document/Doc.c
@@ -23,42 +23,66 @@
 
 lucy_Doc*
 lucy_Doc_init(lucy_Doc *self, void *fields, int32_t doc_id) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_Doc*);
+    lucy_Hash *hash;
+
+    if (fields) {
+        hash = (lucy_Hash *)CFISH_CERTIFY(fields, LUCY_HASH);
+        CFISH_INCREF(hash);
+    }
+    else {
+        hash = lucy_Hash_new(0);
+    }
+    self->fields = hash;
+    self->doc_id = doc_id;
+
+    return self;
 }
 
 void
 lucy_Doc_set_fields(lucy_Doc *self, void *fields) {
-    THROW(LUCY_ERR, "TODO");
+    CFISH_DECREF(self->fields);
+    self->fields = CFISH_CERTIFY(fields, LUCY_HASH);
 }
 
 uint32_t
 lucy_Doc_get_size(lucy_Doc *self) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(uint32_t);
+    lucy_Hash *hash = (lucy_Hash *)self->fields;
+    return Lucy_Hash_Get_Size(hash);
 }
 
 void
 lucy_Doc_store(lucy_Doc *self, const lucy_CharBuf *field, lucy_Obj *value) {
-    THROW(LUCY_ERR, "TODO");
+    lucy_Hash *hash = (lucy_Hash *)self->fields;
+    Lucy_Hash_Store(hash, (lucy_Obj *)field, value);
+    CFISH_INCREF(value);
 }
 
 void
 lucy_Doc_serialize(lucy_Doc *self, lucy_OutStream *outstream) {
-    THROW(LUCY_ERR, "TODO");
+    lucy_Hash *hash = (lucy_Hash *)self->fields;
+    Lucy_Hash_Serialize(hash, outstream);
+    Lucy_OutStream_Write_C32(outstream, self->doc_id);
 }
 
 lucy_Doc*
 lucy_Doc_deserialize(lucy_Doc *self, lucy_InStream *instream) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_Doc*);
+     lucy_Hash *hash = (lucy_Hash*)Lucy_VTable_Make_Obj(LUCY_HASH);
+     self->fields = Lucy_Hash_Deserialize(hash, instream);
+     self->doc_id = Lucy_InStream_Read_C32(instream);
+     return self;
 }
 
 lucy_Obj*
 lucy_Doc_extract(lucy_Doc *self, lucy_CharBuf *field,
                  lucy_ViewCharBuf *target) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(lucy_Obj*);
+    lucy_Hash *hash = (lucy_Hash *)self->fields;
+    lucy_Obj  *obj  = Lucy_Hash_Fetch(hash, (lucy_Obj *)field);
+
+    if (obj && Lucy_Obj_Is_A(obj, LUCY_CHARBUF)) {
+        Lucy_ViewCB_Assign(target, (lucy_CharBuf *)obj);
+    }
+
+    return obj;
 }
 
 void*
@@ -81,13 +105,18 @@ lucy_Doc_load(lucy_Doc *self, lucy_Obj *dump) {
 
 bool
 lucy_Doc_equals(lucy_Doc *self, lucy_Obj *other) {
-    THROW(LUCY_ERR, "TODO");
-    UNREACHABLE_RETURN(bool);
+    lucy_Doc *twin = (lucy_Doc*)other;
+
+    if (twin == self)                    { return true;  }
+    if (!Lucy_Obj_Is_A(other, LUCY_DOC)) { return false; }
+
+    return Lucy_Hash_Equals(self->fields, twin->fields);
 }
 
 void
 lucy_Doc_destroy(lucy_Doc *self) {
-    THROW(LUCY_ERR, "TODO");
+    CFISH_DECREF(self->fields);
+    LUCY_SUPER_DESTROY(self, LUCY_DOC);
 }