[Groonga-commit] groonga/groonga at 5d11db0 [master] mrb: OutputColumns

Back to archive index
Kouhei Sutou null+****@clear*****
Tue Dec 25 17:01:50 JST 2018


Kouhei Sutou	2018-12-25 17:01:50 +0900 (Tue, 25 Dec 2018)

  Revision: 5d11db04b175dfb260d69ee291a98a13b72cbca2
  https://github.com/groonga/groonga/commit/5d11db04b175dfb260d69ee291a98a13b72cbca2

  Message:
    mrb: OutputColumns

  Added files:
    lib/mrb/mrb_output_columns.c
    lib/mrb/mrb_output_columns.h
  Modified files:
    lib/ctx_impl_mrb.c
    lib/mrb/sources.am

  Modified: lib/ctx_impl_mrb.c (+3 -0)
===================================================================
--- lib/ctx_impl_mrb.c    2018-12-25 17:01:12 +0900 (3b734a0fa)
+++ lib/ctx_impl_mrb.c    2018-12-25 17:01:50 +0900 (9800ed1f3)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2013-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -71,6 +72,7 @@
 # include "mrb/mrb_thread.h"
 # include "mrb/mrb_window_definition.h"
 # include "mrb/mrb_locale_output.h"
+# include "mrb/mrb_output_columns.h"
 
 # include <mruby/array.h>
 # include <mruby/string.h>
@@ -205,6 +207,7 @@ mrb_groonga_init(mrb_state *mrb, mrb_value self)
   grn_mrb_thread_init(ctx);
   grn_mrb_window_definition_init(ctx);
   grn_mrb_locale_output_init(ctx);
+  grn_mrb_output_columns_init(ctx);
 
   grn_mrb_load(ctx, "initialize/post.rb");
 

  Added: lib/mrb/mrb_output_columns.c (+101 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_output_columns.c    2018-12-25 17:01:50 +0900 (233f3ca57)
@@ -0,0 +1,101 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "../grn_ctx_impl.h"
+#include <string.h>
+
+#ifdef GRN_WITH_MRUBY
+#include <mruby.h>
+#include <mruby/class.h>
+#include <mruby/data.h>
+#include <mruby/hash.h>
+#include <mruby/array.h>
+#include <mruby/string.h>
+
+#include "mrb_converter.h"
+#include "mrb_ctx.h"
+#include "mrb_output_columns.h"
+
+static struct mrb_data_type mrb_grn_output_columns_type = {
+  "Groonga::OutputColumns",
+  NULL
+};
+
+static mrb_value
+mrb_grn_output_columns_initialize(mrb_state *mrb, mrb_value self)
+{
+  mrb_value mrb_output_columns_ptr;
+
+  mrb_get_args(mrb, "o", &mrb_output_columns_ptr);
+  DATA_TYPE(self) = &mrb_grn_output_columns_type;
+  DATA_PTR(self) = mrb_cptr(mrb_output_columns_ptr);
+  return self;
+}
+
+static mrb_value
+mrb_grn_output_columns_apply(mrb_state *mrb, mrb_value self)
+{
+  grn_ctx *ctx = (grn_ctx *)mrb->ud;
+  mrb_value *mrb_columns;
+  mrb_int n_mrb_columns;
+  grn_obj *output_columns;
+  grn_obj columns;
+  mrb_value mrb_exception;
+
+  mrb_get_args(mrb, "a", &mrb_columns, &n_mrb_columns);
+
+  output_columns = DATA_PTR(self);
+  GRN_PTR_INIT(&columns, GRN_OBJ_VECTOR, GRN_ID_NIL);
+  {
+    mrb_int i;
+    for (i = 0; i < n_mrb_columns; i++) {
+      grn_obj *column = GRN_MRB_DATA_PTR(mrb_columns[i]);
+      GRN_PTR_PUT(ctx, &columns, column);
+    }
+  }
+  grn_output_columns_apply(ctx, output_columns, &columns);
+  mrb_exception = grn_mrb_ctx_to_exception(mrb);
+  GRN_OBJ_FIN(ctx, &columns);
+  if (!mrb_nil_p(mrb_exception)) {
+    mrb_exc_raise(mrb, mrb_exception);
+  }
+
+  return mrb_nil_value();
+}
+
+void
+grn_mrb_output_columns_init(grn_ctx *ctx)
+{
+  grn_mrb_data *data = &(ctx->impl->mrb);
+  mrb_state *mrb = data->state;
+  struct RClass *module = data->module;
+  struct RClass *object_class = data->object_class;
+  struct RClass *klass;
+
+  klass = mrb_define_class_under(mrb, module, "OutputColumns", object_class);
+  MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
+
+  mrb_define_method(mrb, klass, "initialize",
+                    mrb_grn_output_columns_initialize,
+                    MRB_ARGS_REQ(1));
+
+  mrb_define_method(mrb, klass, "apply",
+                    mrb_grn_output_columns_apply,
+                    MRB_ARGS_REQ(1));
+}
+#endif

  Added: lib/mrb/mrb_output_columns.h (+32 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_output_columns.h    2018-12-25 17:01:50 +0900 (103be1b32)
@@ -0,0 +1,32 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#pragma once
+
+#include "../grn_ctx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void grn_mrb_output_columns_init(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+

  Modified: lib/mrb/sources.am (+2 -0)
===================================================================
--- lib/mrb/sources.am    2018-12-25 17:01:12 +0900 (b0a6d2c63)
+++ lib/mrb/sources.am    2018-12-25 17:01:50 +0900 (4077112ef)
@@ -57,6 +57,8 @@ libgrnmrb_la_SOURCES =				\
 	mrb_operator.h				\
 	mrb_options.c				\
 	mrb_options.h				\
+	mrb_output_columns.c			\
+	mrb_output_columns.h			\
 	mrb_patricia_trie.c			\
 	mrb_patricia_trie.h			\
 	mrb_pointer.c				\
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181225/3dbeea7b/attachment-0001.html>


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