[Groonga-commit] groonga/groonga at 54a3b87 [master] Add grn_ctx_is_opened()

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Sep 10 16:00:28 JST 2015


Kouhei Sutou	2015-09-10 16:00:28 +0900 (Thu, 10 Sep 2015)

  New Revision: 54a3b87a69385845a5bbe9516f0660dc40e57e4f
  https://github.com/groonga/groonga/commit/54a3b87a69385845a5bbe9516f0660dc40e57e4f

  Message:
    Add grn_ctx_is_opened()
    
    It returns whether object with the ID is opened or not.

  Modified files:
    include/groonga/groonga.h
    lib/db.c

  Modified: include/groonga/groonga.h (+1 -0)
===================================================================
--- include/groonga/groonga.h    2015-09-10 14:20:19 +0900 (08d434f)
+++ include/groonga/groonga.h    2015-09-10 16:00:28 +0900 (c66146e)
@@ -473,6 +473,7 @@ typedef enum {
 } grn_builtin_tokenizer;
 
 GRN_API grn_obj *grn_ctx_at(grn_ctx *ctx, grn_id id);
+GRN_API grn_bool grn_ctx_is_opened(grn_ctx *ctx, grn_id id);
 
 GRN_API grn_obj *grn_type_create(grn_ctx *ctx, const char *name, unsigned int name_size,
                                  grn_obj_flags flags, unsigned int size);

  Modified: lib/db.c (+32 -0)
===================================================================
--- lib/db.c    2015-09-10 14:20:19 +0900 (24a0bf3)
+++ lib/db.c    2015-09-10 16:00:28 +0900 (902f72c)
@@ -9322,6 +9322,38 @@ exit :
   GRN_API_RETURN(res);
 }
 
+grn_bool
+grn_ctx_is_opened(grn_ctx *ctx, grn_id id)
+{
+  grn_bool is_opened = GRN_FALSE;
+
+  if (!ctx || !ctx->impl || !id) {
+    return GRN_FALSE;
+  }
+
+  GRN_API_ENTER;
+  if (id & GRN_OBJ_TMP_OBJECT) {
+    if (ctx->impl->values) {
+      grn_obj **tmp_obj;
+      tmp_obj = _grn_array_get_value(ctx, ctx->impl->values,
+                                     id & ~GRN_OBJ_TMP_OBJECT);
+      if (tmp_obj) {
+        is_opened = GRN_TRUE;
+      }
+    }
+  } else {
+    grn_db *s = (grn_db *)ctx->impl->db;
+    if (s) {
+      db_value *vp;
+      vp = grn_tiny_array_at(&s->values, id);
+      if (vp && vp->ptr) {
+        is_opened = GRN_TRUE;
+      }
+    }
+  }
+  GRN_API_RETURN(is_opened);
+}
+
 grn_obj *
 grn_obj_open(grn_ctx *ctx, unsigned char type, grn_obj_flags flags, grn_id domain)
 {
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index