[Groonga-commit] groonga/groonga at e7d927b [master] Add output type accessor

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Oct 23 22:31:00 JST 2014


Kouhei Sutou	2014-10-23 22:31:00 +0900 (Thu, 23 Oct 2014)

  New Revision: e7d927b31ae9034a05941594644ffcb25cfb8994
  https://github.com/groonga/groonga/commit/e7d927b31ae9034a05941594644ffcb25cfb8994

  Message:
    Add output type accessor
    
    It's not needed for normal Groonga C API users. Language bindings
    developers may want to use it.

  Modified files:
    doc/source/reference/api/grn_ctx.rst
    include/groonga.h
    lib/ctx.c
    test/unit/core/test-context.c

  Modified: doc/source/reference/api/grn_ctx.rst (+23 -0)
===================================================================
--- doc/source/reference/api/grn_ctx.rst    2014-10-23 21:54:13 +0900 (928eaab)
+++ doc/source/reference/api/grn_ctx.rst    2014-10-23 22:31:00 +0900 (f9acebb)
@@ -117,3 +117,26 @@ Reference
    ctx、またはctxが使用するdbからidに対応するオブジェクトを検索して返す。idに一致するオブジェクトが存在しなければNULLを返す。
 
    :param id: 検索しようとするオブジェクトのidを指定します。
+
+.. c:function:: grn_content_type grn_ctx_get_output_type(grn_ctx *ctx)
+
+   Gets the current output type of the context.
+
+   Normally, this function isn't needed.
+
+   :param ctx: The context object.
+   :return: The output type of the context.
+
+.. c:function:: grn_rc grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type)
+
+   Sets the new output type to the context. It is used by executing a
+   command by :c:func:`grn_expr_exec()`. If you use
+   :c:func:`grn_ctx_send()`, the new output type isn't
+   used. :c:func:`grn_ctx_send()` sets output type from command line
+   internally.
+
+   Normally, this function isn't needed.
+
+   :param ctx: The context object.
+   :param type: The new output type.
+   :return: ``GRN_SUCCESS`` on success, not ``GRN_SUCCESS`` on error.

  Modified: include/groonga.h (+2 -0)
===================================================================
--- include/groonga.h    2014-10-23 21:54:13 +0900 (b1e876a)
+++ include/groonga.h    2014-10-23 22:31:00 +0900 (a248da0)
@@ -1307,6 +1307,8 @@ GRN_API void grn_ctx_output_obj(grn_ctx *ctx,
                                 grn_obj *value, grn_obj_format *format);
 
 
+GRN_API grn_content_type grn_ctx_get_output_type(grn_ctx *ctx);
+GRN_API grn_rc grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type);
 GRN_API const char *grn_ctx_get_mime_type(grn_ctx *ctx);
 GRN_API void grn_ctx_recv_handler_set(grn_ctx *,
                                       void (*func)(grn_ctx *, int, void *),

  Modified: lib/ctx.c (+24 -0)
===================================================================
--- lib/ctx.c    2014-10-23 21:54:13 +0900 (98194cd)
+++ lib/ctx.c    2014-10-23 22:31:00 +0900 (e5f4ea4)
@@ -1428,6 +1428,30 @@ grn_ctx_get_command_version(grn_ctx *ctx)
   }
 }
 
+grn_content_type
+grn_ctx_get_output_type(grn_ctx *ctx)
+{
+  if (ctx->impl) {
+    return ctx->impl->output_type;
+  } else {
+    return GRN_CONTENT_NONE;
+  }
+}
+
+grn_rc
+grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type)
+{
+  grn_rc rc = GRN_SUCCESS;
+
+  if (ctx->impl) {
+    ctx->impl->output_type = type;
+  } else {
+    rc = GRN_INVALID_ARGUMENT;
+  }
+
+  return rc;
+}
+
 const char *
 grn_ctx_get_mime_type(grn_ctx *ctx)
 {

  Modified: test/unit/core/test-context.c (+11 -0)
===================================================================
--- test/unit/core/test-context.c    2014-10-23 21:54:13 +0900 (39b8fc0)
+++ test/unit/core/test-context.c    2014-10-23 22:31:00 +0900 (640a8c5)
@@ -29,6 +29,7 @@ void test_dynamic_malloc_change(void);
 void test_command_version(void);
 void test_support_zlib(void);
 void test_support_lzo(void);
+void test_output_type(void);
 
 static grn_ctx *context;
 static grn_obj *database;
@@ -159,3 +160,13 @@ test_support_lzo(void)
   cut_assert_false(support_p);
 #endif
 }
+
+void
+test_output_type(void)
+{
+  cut_assert_ensure_database();
+
+  cut_assert_equal_int(GRN_CONTENT_NONE, grn_ctx_get_output_type(context));
+  grn_test_assert(grn_ctx_set_output_type(context, GRN_CONTENT_JSON));
+  cut_assert_equal_int(GRN_CONTENT_JSON, grn_ctx_get_output_type(context));
+}
-------------- next part --------------
HTML����������������������������...
下载 



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