[Groonga-commit] groonga/groonga at 7095c70 [master] Add open/close API to grn_output_result_set

Back to archive index

Kouhei Sutou null+****@clear*****
Wed May 25 12:19:52 JST 2016


Kouhei Sutou	2016-05-25 12:19:52 +0900 (Wed, 25 May 2016)

  New Revision: 7095c7018ca9ccfa8afb123cb214acc6f5f74322
  https://github.com/groonga/groonga/commit/7095c7018ca9ccfa8afb123cb214acc6f5f74322

  Message:
    Add open/close API to grn_output_result_set

  Modified files:
    include/groonga/output.h
    lib/ctx.c
    lib/grn_output.h
    lib/output.c

  Modified: include/groonga/output.h (+7 -0)
===================================================================
--- include/groonga/output.h    2016-05-24 23:47:51 +0900 (ef3c82d)
+++ include/groonga/output.h    2016-05-25 12:19:52 +0900 (d5241ae)
@@ -93,6 +93,13 @@ GRN_API void grn_ctx_output_str(grn_ctx *ctx,
 GRN_API void grn_ctx_output_bool(grn_ctx *ctx, grn_bool value);
 GRN_API void grn_ctx_output_obj(grn_ctx *ctx,
                                 grn_obj *value, grn_obj_format *format);
+GRN_API void grn_ctx_output_result_set_open(grn_ctx *ctx,
+                                            grn_obj *result_set,
+                                            grn_obj_format *format,
+                                            uint32_t n_additional_elements);
+GRN_API void grn_ctx_output_result_set_close(grn_ctx *ctx,
+                                             grn_obj *result_set,
+                                             grn_obj_format *format);
 GRN_API void grn_ctx_output_result_set(grn_ctx *ctx,
                                        grn_obj *result_set,
                                        grn_obj_format *format);

  Modified: lib/ctx.c (+26 -0)
===================================================================
--- lib/ctx.c    2016-05-24 23:47:51 +0900 (9bf66f3)
+++ lib/ctx.c    2016-05-25 12:19:52 +0900 (6c2bcc5)
@@ -1772,6 +1772,32 @@ grn_ctx_output_obj(grn_ctx *ctx, grn_obj *value, grn_obj_format *format)
 }
 
 void
+grn_ctx_output_result_set_open(grn_ctx *ctx,
+                               grn_obj *result_set,
+                               grn_obj_format *format,
+                               uint32_t n_additional_elements)
+{
+  grn_output_result_set_open(ctx,
+                             ctx->impl->output.buf,
+                             ctx->impl->output.type,
+                             result_set,
+                             format,
+                             n_additional_elements);
+}
+
+void
+grn_ctx_output_result_set_close(grn_ctx *ctx,
+                                grn_obj *result_set,
+                                grn_obj_format *format)
+{
+  grn_output_result_set_close(ctx,
+                              ctx->impl->output.buf,
+                              ctx->impl->output.type,
+                              result_set,
+                              format);
+}
+
+void
 grn_ctx_output_result_set(grn_ctx *ctx,
                           grn_obj *result_set,
                           grn_obj_format *format)

  Modified: lib/grn_output.h (+17 -0)
===================================================================
--- lib/grn_output.h    2016-05-24 23:47:51 +0900 (a1972c0)
+++ lib/grn_output.h    2016-05-25 12:19:52 +0900 (af99b0c)
@@ -54,6 +54,17 @@ GRN_API void grn_output_bool(grn_ctx *ctx, grn_obj *outbuf,
                              grn_content_type output_type,
                              grn_bool value);
 
+GRN_API void grn_output_result_set_open(grn_ctx *ctx,
+                                        grn_obj *outbuf,
+                                        grn_content_type output_type,
+                                        grn_obj *result_set,
+                                        grn_obj_format *format,
+                                        uint32_t n_additional_elements);
+GRN_API void grn_output_result_set_close(grn_ctx *ctx,
+                                         grn_obj *outbuf,
+                                         grn_content_type output_type,
+                                         grn_obj *result_set,
+                                         grn_obj_format *format);
 GRN_API void grn_output_result_set(grn_ctx *ctx,
                                    grn_obj *outbuf,
                                    grn_content_type output_type,
@@ -100,6 +111,12 @@ grn_rc grn_output_format_set_columns(grn_ctx *ctx, grn_obj_format *format,
   (grn_ctx_output_bool(ctx, value))
 #define GRN_OUTPUT_OBJ(obj,format)\
   (grn_ctx_output_obj(ctx, obj, format))
+#define GRN_OUTPUT_RESULT_SET_OPEN(result_set,format,n_additional_elements)\
+  (grn_ctx_output_result_set_open(ctx, result_set, format, n_additional_elements))
+#define GRN_OUTPUT_RESULT_SET_CLOSE(result_set,format)\
+  (grn_ctx_output_result_set_close(ctx, result_set, format))
+#define GRN_OUTPUT_RESULT_SET(result_set,format,n_additional_elements)\
+  (grn_ctx_output_result_set(ctx, result_set, format, n_additional_elements))
 #define GRN_OUTPUT_TABLE_COLUMNS(table,format)\
   (grn_ctx_output_table_columns(ctx, table, format))
 #define GRN_OUTPUT_TABLE_RECORDS(table,format)\

  Modified: lib/output.c (+85 -20)
===================================================================
--- lib/output.c    2016-05-24 23:47:51 +0900 (9fc26d4)
+++ lib/output.c    2016-05-25 12:19:52 +0900 (131342f)
@@ -1761,11 +1761,12 @@ grn_output_table_records(grn_ctx *ctx, grn_obj *outbuf,
 }
 
 static void
-grn_output_result_set_v1(grn_ctx *ctx,
-                         grn_obj *outbuf,
-                         grn_content_type output_type,
-                         grn_obj *table,
-                         grn_obj_format *format)
+grn_output_result_set_open_v1(grn_ctx *ctx,
+                              grn_obj *outbuf,
+                              grn_content_type output_type,
+                              grn_obj *table,
+                              grn_obj_format *format,
+                              uint32_t n_additional_elements)
 {
   grn_obj buf;
   GRN_TEXT_INIT(&buf, 0);
@@ -1776,13 +1777,13 @@ grn_output_result_set_v1(grn_ctx *ctx,
       resultset_size++;
     }
     resultset_size += format->limit;
+    resultset_size += n_additional_elements;
     grn_output_array_open(ctx, outbuf, output_type, "RESULTSET", resultset_size);
     grn_output_result_set_n_hits(ctx, outbuf, output_type, format);
     if (format->flags & GRN_OBJ_FORMAT_WITH_COLUMN_NAMES) {
       grn_output_table_columns(ctx, outbuf, output_type, table, format);
     }
     grn_output_table_records(ctx, outbuf, output_type, table, format);
-    grn_output_array_close(ctx, outbuf, output_type);
   } else {
     int i;
     grn_obj *column = grn_obj_column(ctx, table,
@@ -1800,18 +1801,28 @@ grn_output_result_set_v1(grn_ctx *ctx,
       }
       grn_table_cursor_close(ctx, tc);
     }
-    grn_output_array_close(ctx, outbuf, output_type);
     grn_obj_unlink(ctx, column);
   }
   GRN_OBJ_FIN(ctx, &buf);
 }
 
 static void
-grn_output_result_set_v3(grn_ctx *ctx,
-                         grn_obj *outbuf,
-                         grn_content_type output_type,
-                         grn_obj *result_set,
-                         grn_obj_format *format)
+grn_output_result_set_close_v1(grn_ctx *ctx,
+                               grn_obj *outbuf,
+                               grn_content_type output_type,
+                               grn_obj *table,
+                               grn_obj_format *format)
+{
+  grn_output_array_close(ctx, outbuf, output_type);
+}
+
+static void
+grn_output_result_set_open_v3(grn_ctx *ctx,
+                              grn_obj *outbuf,
+                              grn_content_type output_type,
+                              grn_obj *result_set,
+                              grn_obj_format *format,
+                              uint32_t n_additional_elements)
 {
   grn_obj buf;
   GRN_TEXT_INIT(&buf, 0);
@@ -1821,22 +1832,24 @@ grn_output_result_set_v3(grn_ctx *ctx,
     if (format->flags & GRN_OBJ_FORMAT_WITH_COLUMN_NAMES) {
       n_elements++;
     }
+    n_elements += n_additional_elements;
     grn_output_map_open(ctx, outbuf, output_type, "result_set", n_elements);
     grn_output_result_set_n_hits(ctx, outbuf, output_type, format);
     if (format->flags & GRN_OBJ_FORMAT_WITH_COLUMN_NAMES) {
       grn_output_table_columns(ctx, outbuf, output_type, result_set, format);
     }
     grn_output_table_records(ctx, outbuf, output_type, result_set, format);
-    grn_output_map_close(ctx, outbuf, output_type);
   } else {
     grn_obj *column;
     int n_records;
+    int n_elements = 1;
 
     column = grn_obj_column(ctx,
                             result_set,
                             GRN_COLUMN_NAME_KEY,
                             GRN_COLUMN_NAME_KEY_LEN);
-    grn_output_map_open(ctx, outbuf, output_type, "result_set", 1);
+    n_elements += n_additional_elements;
+    grn_output_map_open(ctx, outbuf, output_type, "result_set", n_elements);
     n_records = grn_table_size(ctx, result_set);
     grn_output_cstr(ctx, outbuf, output_type, "keys");
     grn_output_array_open(ctx, outbuf, output_type, "keys", n_records);
@@ -1846,12 +1859,60 @@ grn_output_result_set_v3(grn_ctx *ctx,
       grn_text_esc(ctx, outbuf, GRN_BULK_HEAD(&buf), GRN_BULK_VSIZE(&buf));
     } GRN_TABLE_EACH_END(ctx, cursor);
     grn_output_array_close(ctx, outbuf, output_type);
-    grn_output_map_close(ctx, outbuf, output_type);
     grn_obj_unlink(ctx, column);
   }
   GRN_OBJ_FIN(ctx, &buf);
 }
 
+static void
+grn_output_result_set_close_v3(grn_ctx *ctx,
+                               grn_obj *outbuf,
+                               grn_content_type output_type,
+                               grn_obj *result_set,
+                               grn_obj_format *format)
+{
+  grn_output_map_close(ctx, outbuf, output_type);
+}
+
+void
+grn_output_result_set_open(grn_ctx *ctx,
+                           grn_obj *outbuf,
+                           grn_content_type output_type,
+                           grn_obj *result_set,
+                           grn_obj_format *format,
+                           uint32_t n_additional_elements)
+{
+  if (grn_ctx_get_command_version(ctx) < GRN_COMMAND_VERSION_3) {
+    grn_output_result_set_open_v1(ctx,
+                                  outbuf,
+                                  output_type,
+                                  result_set,
+                                  format,
+                                  n_additional_elements);
+  } else {
+    grn_output_result_set_open_v3(ctx,
+                                  outbuf,
+                                  output_type,
+                                  result_set,
+                                  format,
+                                  n_additional_elements);
+  }
+}
+
+void
+grn_output_result_set_close(grn_ctx *ctx,
+                            grn_obj *outbuf,
+                            grn_content_type output_type,
+                            grn_obj *result_set,
+                            grn_obj_format *format)
+{
+  if (grn_ctx_get_command_version(ctx) < GRN_COMMAND_VERSION_3) {
+    grn_output_result_set_close_v1(ctx, outbuf, output_type, result_set, format);
+  } else {
+    grn_output_result_set_close_v3(ctx, outbuf, output_type, result_set, format);
+  }
+}
+
 void
 grn_output_result_set(grn_ctx *ctx,
                       grn_obj *outbuf,
@@ -1859,11 +1920,15 @@ grn_output_result_set(grn_ctx *ctx,
                       grn_obj *result_set,
                       grn_obj_format *format)
 {
-  if (grn_ctx_get_command_version(ctx) < GRN_COMMAND_VERSION_3) {
-    grn_output_result_set_v1(ctx, outbuf, output_type, result_set, format);
-  } else {
-    grn_output_result_set_v3(ctx, outbuf, output_type, result_set, format);
-  }
+  uint32_t n_additional_elements = 0;
+
+  grn_output_result_set_open(ctx,
+                             outbuf,
+                             output_type,
+                             result_set,
+                             format,
+                             n_additional_elements);
+  grn_output_result_set_close(ctx, outbuf, output_type, result_set, format);
 }
 
 void
-------------- next part --------------
HTML����������������������������...
다운로드 



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