rroonga 0.9.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +217 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +211 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/libruby-groonga.a +0 -0
  16. data/ext/rb-grn-accessor.c +52 -0
  17. data/ext/rb-grn-array-cursor.c +36 -0
  18. data/ext/rb-grn-array.c +210 -0
  19. data/ext/rb-grn-column.c +573 -0
  20. data/ext/rb-grn-context.c +655 -0
  21. data/ext/rb-grn-database.c +472 -0
  22. data/ext/rb-grn-encoding-support.c +64 -0
  23. data/ext/rb-grn-encoding.c +257 -0
  24. data/ext/rb-grn-exception.c +1110 -0
  25. data/ext/rb-grn-expression-builder.c +75 -0
  26. data/ext/rb-grn-expression.c +735 -0
  27. data/ext/rb-grn-fix-size-column.c +166 -0
  28. data/ext/rb-grn-hash-cursor.c +38 -0
  29. data/ext/rb-grn-hash.c +294 -0
  30. data/ext/rb-grn-index-column.c +488 -0
  31. data/ext/rb-grn-logger.c +504 -0
  32. data/ext/rb-grn-object.c +1369 -0
  33. data/ext/rb-grn-operation.c +198 -0
  34. data/ext/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/rb-grn-patricia-trie.c +488 -0
  36. data/ext/rb-grn-procedure.c +52 -0
  37. data/ext/rb-grn-query.c +260 -0
  38. data/ext/rb-grn-record.c +40 -0
  39. data/ext/rb-grn-snippet.c +334 -0
  40. data/ext/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/rb-grn-table-cursor.c +247 -0
  42. data/ext/rb-grn-table-key-support.c +731 -0
  43. data/ext/rb-grn-table.c +2141 -0
  44. data/ext/rb-grn-type.c +181 -0
  45. data/ext/rb-grn-utils.c +769 -0
  46. data/ext/rb-grn-variable-size-column.c +36 -0
  47. data/ext/rb-grn-variable.c +108 -0
  48. data/ext/rb-grn-view-accessor.c +53 -0
  49. data/ext/rb-grn-view-cursor.c +35 -0
  50. data/ext/rb-grn-view-record.c +41 -0
  51. data/ext/rb-grn-view.c +421 -0
  52. data/ext/rb-grn.h +700 -0
  53. data/ext/rb-groonga.c +117 -0
  54. data/extconf.rb +266 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/groonga.rb +90 -0
  70. data/lib/groonga/context.rb +184 -0
  71. data/lib/groonga/expression-builder.rb +285 -0
  72. data/lib/groonga/patricia-trie.rb +53 -0
  73. data/lib/groonga/record.rb +311 -0
  74. data/lib/groonga/schema.rb +1191 -0
  75. data/lib/groonga/view-record.rb +56 -0
  76. data/license/GPL +340 -0
  77. data/license/LGPL +504 -0
  78. data/license/RUBY +59 -0
  79. data/misc/grnop2ruby.rb +49 -0
  80. data/pkg-config.rb +333 -0
  81. data/test-unit/Rakefile +40 -0
  82. data/test-unit/TODO +5 -0
  83. data/test-unit/bin/testrb +5 -0
  84. data/test-unit/html/classic.html +15 -0
  85. data/test-unit/html/index.html +25 -0
  86. data/test-unit/html/index.html.ja +27 -0
  87. data/test-unit/lib/test/unit.rb +323 -0
  88. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  89. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  90. data/test-unit/lib/test/unit/attribute.rb +125 -0
  91. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  92. data/test-unit/lib/test/unit/collector.rb +36 -0
  93. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  94. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  95. data/test-unit/lib/test/unit/collector/load.rb +136 -0
  96. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  97. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  98. data/test-unit/lib/test/unit/color.rb +96 -0
  99. data/test-unit/lib/test/unit/diff.rb +724 -0
  100. data/test-unit/lib/test/unit/error.rb +130 -0
  101. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  102. data/test-unit/lib/test/unit/failure.rb +136 -0
  103. data/test-unit/lib/test/unit/fixture.rb +176 -0
  104. data/test-unit/lib/test/unit/notification.rb +129 -0
  105. data/test-unit/lib/test/unit/omission.rb +191 -0
  106. data/test-unit/lib/test/unit/pending.rb +150 -0
  107. data/test-unit/lib/test/unit/priority.rb +180 -0
  108. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  109. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  110. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  111. data/test-unit/lib/test/unit/testcase.rb +476 -0
  112. data/test-unit/lib/test/unit/testresult.rb +89 -0
  113. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  114. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  115. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  116. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  117. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  118. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  119. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  120. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  121. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  122. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  123. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  124. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  125. data/test-unit/lib/test/unit/version.rb +7 -0
  126. data/test-unit/sample/adder.rb +13 -0
  127. data/test-unit/sample/subtracter.rb +12 -0
  128. data/test-unit/sample/test_adder.rb +20 -0
  129. data/test-unit/sample/test_subtracter.rb +20 -0
  130. data/test-unit/sample/test_user.rb +23 -0
  131. data/test-unit/test/collector/test-descendant.rb +133 -0
  132. data/test-unit/test/collector/test-load.rb +348 -0
  133. data/test-unit/test/collector/test_dir.rb +406 -0
  134. data/test-unit/test/collector/test_objectspace.rb +100 -0
  135. data/test-unit/test/run-test.rb +15 -0
  136. data/test-unit/test/test-attribute.rb +86 -0
  137. data/test-unit/test/test-color-scheme.rb +67 -0
  138. data/test-unit/test/test-color.rb +47 -0
  139. data/test-unit/test/test-diff.rb +518 -0
  140. data/test-unit/test/test-emacs-runner.rb +60 -0
  141. data/test-unit/test/test-fixture.rb +287 -0
  142. data/test-unit/test/test-notification.rb +33 -0
  143. data/test-unit/test/test-omission.rb +81 -0
  144. data/test-unit/test/test-pending.rb +70 -0
  145. data/test-unit/test/test-priority.rb +119 -0
  146. data/test-unit/test/test-testcase.rb +544 -0
  147. data/test-unit/test/test_assertions.rb +1151 -0
  148. data/test-unit/test/test_error.rb +26 -0
  149. data/test-unit/test/test_failure.rb +33 -0
  150. data/test-unit/test/test_testresult.rb +113 -0
  151. data/test-unit/test/test_testsuite.rb +129 -0
  152. data/test-unit/test/testunit-test-util.rb +14 -0
  153. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  154. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  155. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  156. data/test-unit/test/util/test_observable.rb +102 -0
  157. data/test-unit/test/util/test_procwrapper.rb +36 -0
  158. data/test/.gitignore +1 -0
  159. data/test/groonga-test-utils.rb +133 -0
  160. data/test/run-test.rb +58 -0
  161. data/test/test-array.rb +97 -0
  162. data/test/test-column.rb +316 -0
  163. data/test/test-context-select.rb +93 -0
  164. data/test/test-context.rb +73 -0
  165. data/test/test-database.rb +113 -0
  166. data/test/test-encoding.rb +33 -0
  167. data/test/test-exception.rb +93 -0
  168. data/test/test-expression-builder.rb +156 -0
  169. data/test/test-expression.rb +134 -0
  170. data/test/test-fix-size-column.rb +65 -0
  171. data/test/test-gqtp.rb +72 -0
  172. data/test/test-hash.rb +312 -0
  173. data/test/test-index-column.rb +81 -0
  174. data/test/test-logger.rb +37 -0
  175. data/test/test-patricia-trie.rb +189 -0
  176. data/test/test-procedure.rb +37 -0
  177. data/test/test-query.rb +22 -0
  178. data/test/test-record.rb +279 -0
  179. data/test/test-remote.rb +54 -0
  180. data/test/test-schema-view.rb +90 -0
  181. data/test/test-schema.rb +459 -0
  182. data/test/test-snippet.rb +130 -0
  183. data/test/test-table-cursor.rb +153 -0
  184. data/test/test-table-offset-and-limit.rb +102 -0
  185. data/test/test-table-select-normalize.rb +53 -0
  186. data/test/test-table-select.rb +150 -0
  187. data/test/test-table.rb +690 -0
  188. data/test/test-type.rb +71 -0
  189. data/test/test-variable-size-column.rb +98 -0
  190. data/test/test-variable.rb +28 -0
  191. data/test/test-vector-column.rb +76 -0
  192. data/test/test-version.rb +31 -0
  193. data/test/test-view.rb +72 -0
  194. data/text/TUTORIAL.ja.rdoc +392 -0
  195. data/text/expression.rdoc +284 -0
  196. data/vendor/local/bin/grntest.exe +0 -0
  197. data/vendor/local/bin/groonga.exe +0 -0
  198. data/vendor/local/bin/libgroonga.dll +0 -0
  199. data/vendor/local/bin/libmecab.dll +0 -0
  200. data/vendor/local/include/groonga.h +2285 -0
  201. data/vendor/local/lib/libgroonga.lib +0 -0
  202. metadata +280 -0
data/ext/rb-grn-type.c ADDED
@@ -0,0 +1,181 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License version 2.1 as published by the Free Software Foundation.
8
+
9
+ This library is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public
15
+ License along with this library; if not, write to the Free Software
16
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+ */
18
+
19
+ #include "rb-grn.h"
20
+
21
+ #define SELF(object) (RVAL2GRNTYPE(object))
22
+
23
+ VALUE rb_cGrnType;
24
+
25
+ /*
26
+ * Document-class: Groonga::Type
27
+ *
28
+ * groongaのテーブルの主キーや、カラムの値の型のためのオブジェ
29
+ * クト。型として使用可能なものはgroongaで予め定義済みの型、ユ
30
+ * ーザが定義する型、またはユーザが定義したテーブル。
31
+ */
32
+
33
+
34
+ grn_obj *
35
+ rb_grn_type_from_ruby_object (VALUE object)
36
+ {
37
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnType))) {
38
+ rb_raise(rb_eTypeError, "not a groonga type");
39
+ }
40
+
41
+ return RVAL2GRNOBJECT(object, NULL);
42
+ }
43
+
44
+ VALUE
45
+ rb_grn_type_to_ruby_object (grn_ctx *context, grn_obj *type,
46
+ rb_grn_boolean owner)
47
+ {
48
+ return GRNOBJECT2RVAL(rb_cGrnType, context, type, owner);
49
+ }
50
+
51
+ /*
52
+ * call-seq:
53
+ * Groonga::Type.new(name, options={})
54
+ *
55
+ * 名前が_name_の型を作成する。_options_に指定可能な値は以下の通
56
+ * り。
57
+ *
58
+ * [+:type+]
59
+ * :integer(符号付き整数)、:int(:integerの省略
60
+ * 形)、:unsigned_integer(符号なし整
61
+ * 数)、:uint(:unsigned_integerの省略形)、:float(浮動小
62
+ * 数点数)、:variable(可変長文字列)のいずれかを指定する。
63
+ * 省略した場合は:variableを指定したものと扱う。
64
+ *
65
+ * :variableを指定した場合は必ず+:size+を指定しなければいけない。
66
+ *
67
+ * [+:context+]
68
+ * 型の作成時に利用するGroonga::Contextを指定する。省略すると
69
+ * Groonga::Context.defaultを用いる。
70
+ *
71
+ * [+:size+]
72
+ * +:option+が:variableの場合は最大長、それ以外の場合は長さを
73
+ * 指定する(単位:byte)。
74
+ */
75
+ static VALUE
76
+ rb_grn_type_initialize (int argc, VALUE *argv, VALUE self)
77
+ {
78
+ grn_ctx *context;
79
+ grn_obj *type;
80
+ const char *name = NULL;
81
+ unsigned name_size, size = 0;
82
+ grn_obj_flags flags = 0;
83
+ VALUE rb_name, options, rb_context, rb_type, rb_size;
84
+
85
+ rb_scan_args(argc, argv, "11", &rb_name, &options);
86
+
87
+ rb_grn_scan_options(options,
88
+ "context", &rb_context,
89
+ "type", &rb_type,
90
+ "size", &rb_size,
91
+ NULL);
92
+
93
+ name = StringValuePtr(rb_name);
94
+ name_size = RSTRING_LEN(rb_name);
95
+
96
+ context = rb_grn_context_ensure(&rb_context);
97
+
98
+ if (NIL_P(rb_type) ||
99
+ rb_grn_equal_option(rb_type, "variable")) {
100
+ flags = GRN_OBJ_KEY_VAR_SIZE;
101
+ } else if (rb_grn_equal_option(rb_type, "integer") ||
102
+ rb_grn_equal_option(rb_type, "int")) {
103
+ flags = GRN_OBJ_KEY_INT;
104
+ size = sizeof(int);
105
+ } else if (rb_grn_equal_option(rb_type, "unsigned_integer") ||
106
+ rb_grn_equal_option(rb_type, "uint")) {
107
+ flags = GRN_OBJ_KEY_UINT;
108
+ size = sizeof(unsigned int);
109
+ } else if (rb_grn_equal_option(rb_type, "float")) {
110
+ flags = GRN_OBJ_KEY_FLOAT;
111
+ size = sizeof(double);
112
+ } else {
113
+ rb_raise(rb_eArgError,
114
+ ":type should be one of "
115
+ "[:integer, :int, :unsigned_integer, :uint, "
116
+ ":float, :variable]: %s",
117
+ rb_grn_inspect(options));
118
+ }
119
+
120
+ if (NIL_P(rb_size)) {
121
+ if (size == 0)
122
+ rb_raise(rb_eArgError, "size is missing: %s",
123
+ rb_grn_inspect(options));
124
+ } else {
125
+ size = NUM2UINT(rb_size);
126
+ }
127
+
128
+ type = grn_type_create(context, name, name_size, flags, size);
129
+ rb_grn_object_assign(Qnil, self, rb_context, context, type);
130
+ rb_grn_context_check(context, rb_ary_new4(argc, argv));
131
+
132
+ return Qnil;
133
+ }
134
+
135
+ void
136
+ rb_grn_init_type (VALUE mGrn)
137
+ {
138
+ rb_cGrnType = rb_define_class_under(mGrn, "Type", rb_cGrnObject);
139
+
140
+ rb_define_method(rb_cGrnType, "initialize", rb_grn_type_initialize, -1);
141
+
142
+ /* 任意のテーブルに属する全てのレコード(Object型はv1.2で
143
+ サポートされます)。 */
144
+ rb_define_const(rb_cGrnType, "OBJECT", INT2NUM(GRN_DB_OBJECT));
145
+ /* bool型。trueとfalse。 */
146
+ rb_define_const(rb_cGrnType, "BOOLEAN", INT2NUM(GRN_DB_BOOL));
147
+ /* bool型。trueとfalse。 */
148
+ rb_define_const(rb_cGrnType, "BOOL", INT2NUM(GRN_DB_BOOL));
149
+ /* 8bit符号付き整数。 */
150
+ rb_define_const(rb_cGrnType, "INT8", INT2NUM(GRN_DB_INT8));
151
+ /* 8bit符号なし整数。 */
152
+ rb_define_const(rb_cGrnType, "UINT8", INT2NUM(GRN_DB_UINT8));
153
+ /* 16bit符号付き整数。 */
154
+ rb_define_const(rb_cGrnType, "INT16", INT2NUM(GRN_DB_INT16));
155
+ /* 16bit符号なし整数。 */
156
+ rb_define_const(rb_cGrnType, "UINT16", INT2NUM(GRN_DB_UINT16));
157
+ /* 32bit符号付き整数。 */
158
+ rb_define_const(rb_cGrnType, "INT32", INT2NUM(GRN_DB_INT32));
159
+ /* 32bit符号なし整数。 */
160
+ rb_define_const(rb_cGrnType, "UINT32", INT2NUM(GRN_DB_UINT32));
161
+ /* 64bit符号付き整数。 */
162
+ rb_define_const(rb_cGrnType, "INT64", INT2NUM(GRN_DB_INT64));
163
+ /* 64bit符号なし整数。 */
164
+ rb_define_const(rb_cGrnType, "UINT64", INT2NUM(GRN_DB_UINT64));
165
+ /* ieee754形式の64bit浮動小数点数。 */
166
+ rb_define_const(rb_cGrnType, "FLOAT", INT2NUM(GRN_DB_FLOAT));
167
+ /* 1970年1月1日0時0分0秒からの経過マイクロ秒数を64bit符
168
+ 号付き整数で表現した値。 */
169
+ rb_define_const(rb_cGrnType, "TIME", INT2NUM(GRN_DB_TIME));
170
+ /* 4Kbyte以下の文字列。 */
171
+ rb_define_const(rb_cGrnType, "SHORT_TEXT", INT2NUM(GRN_DB_SHORT_TEXT));
172
+ /* 64Kbyte以下の文字列。 */
173
+ rb_define_const(rb_cGrnType, "TEXT", INT2NUM(GRN_DB_TEXT));
174
+ /* 2Gbyte以下の文字列。 */
175
+ rb_define_const(rb_cGrnType, "LONG_TEXT", INT2NUM(GRN_DB_LONG_TEXT));
176
+ rb_define_const(rb_cGrnType, "DELIMIT", INT2NUM(GRN_DB_DELIMIT));
177
+ rb_define_const(rb_cGrnType, "UNIGRAM", INT2NUM(GRN_DB_UNIGRAM));
178
+ rb_define_const(rb_cGrnType, "BIGRAM", INT2NUM(GRN_DB_BIGRAM));
179
+ rb_define_const(rb_cGrnType, "TRIGRAM", INT2NUM(GRN_DB_TRIGRAM));
180
+ rb_define_const(rb_cGrnType, "MECAB", INT2NUM(GRN_DB_MECAB));
181
+ }
@@ -0,0 +1,769 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /* vim: set sts=4 sw=4 ts=8 noet: */
3
+ /*
4
+ Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
5
+
6
+ This library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License version 2.1 as published by the Free Software Foundation.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ */
19
+
20
+ #include "rb-grn.h"
21
+
22
+ #include <stdarg.h>
23
+
24
+ const char *
25
+ rb_grn_inspect (VALUE object)
26
+ {
27
+ VALUE inspected;
28
+
29
+ inspected = rb_funcall(object, rb_intern("inspect"), 0);
30
+ return StringValueCStr(inspected);
31
+ }
32
+
33
+ void
34
+ rb_grn_scan_options (VALUE options, ...)
35
+ {
36
+ VALUE available_keys;
37
+ const char *key;
38
+ VALUE *value;
39
+ va_list args;
40
+
41
+ if (NIL_P(options))
42
+ options = rb_hash_new();
43
+ else
44
+ options = rb_funcall(options, rb_intern("dup"), 0);
45
+
46
+ Check_Type(options, T_HASH);
47
+
48
+ available_keys = rb_ary_new();
49
+ va_start(args, options);
50
+ key = va_arg(args, const char *);
51
+ while (key) {
52
+ VALUE rb_key;
53
+ value = va_arg(args, VALUE *);
54
+
55
+ rb_key = RB_GRN_INTERN(key);
56
+ rb_ary_push(available_keys, rb_key);
57
+ *value = rb_funcall(options, rb_intern("delete"), 1, rb_key);
58
+
59
+ key = va_arg(args, const char *);
60
+ }
61
+ va_end(args);
62
+
63
+ if (RVAL2CBOOL(rb_funcall(options, rb_intern("empty?"), 0)))
64
+ return;
65
+
66
+ rb_raise(rb_eArgError,
67
+ "unexpected key(s) exist: %s: available keys: %s",
68
+ rb_grn_inspect(rb_funcall(options, rb_intern("keys"), 0)),
69
+ rb_grn_inspect(available_keys));
70
+ }
71
+
72
+ rb_grn_boolean
73
+ rb_grn_equal_option (VALUE option, const char *key)
74
+ {
75
+ VALUE key_string, key_symbol;
76
+
77
+ key_string = rb_str_new2(key);
78
+ if (RVAL2CBOOL(rb_funcall(option, rb_intern("=="), 1, key_string)))
79
+ return RB_GRN_TRUE;
80
+
81
+ key_symbol = rb_str_intern(key_string);
82
+ if (RVAL2CBOOL(rb_funcall(option, rb_intern("=="), 1, key_symbol)))
83
+ return RB_GRN_TRUE;
84
+
85
+ return RB_GRN_FALSE;
86
+ }
87
+
88
+ static VALUE
89
+ rb_grn_bulk_to_ruby_object_by_range_id (grn_ctx *context, grn_obj *bulk,
90
+ grn_id range_id,
91
+ VALUE related_object, VALUE *rb_value)
92
+ {
93
+ rb_grn_boolean success = RB_GRN_TRUE;
94
+
95
+ switch (range_id) {
96
+ case GRN_DB_VOID:
97
+ *rb_value = rb_str_new(GRN_TEXT_VALUE(bulk), GRN_TEXT_LEN(bulk));
98
+ break;
99
+ case GRN_DB_BOOL:
100
+ *rb_value = GRN_BOOL_VALUE(bulk) ? Qtrue : Qfalse;
101
+ break;
102
+ case GRN_DB_INT32:
103
+ *rb_value = INT2NUM(GRN_INT32_VALUE(bulk));
104
+ break;
105
+ case GRN_DB_UINT32:
106
+ *rb_value = UINT2NUM(GRN_UINT32_VALUE(bulk));
107
+ break;
108
+ case GRN_DB_INT64:
109
+ *rb_value = LL2NUM(GRN_INT64_VALUE(bulk));
110
+ break;
111
+ case GRN_DB_UINT64:
112
+ *rb_value = ULL2NUM(GRN_UINT64_VALUE(bulk));
113
+ break;
114
+ case GRN_DB_FLOAT:
115
+ *rb_value = rb_float_new(GRN_FLOAT_VALUE(bulk));
116
+ break;
117
+ case GRN_DB_TIME:
118
+ {
119
+ int64_t time_value, sec, usec;
120
+
121
+ time_value = GRN_TIME_VALUE(bulk);
122
+ GRN_TIME_UNPACK(time_value, sec, usec);
123
+ *rb_value = rb_funcall(rb_cTime, rb_intern("at"), 2,
124
+ LL2NUM(sec), LL2NUM(usec));
125
+ }
126
+ break;
127
+ case GRN_DB_SHORT_TEXT:
128
+ case GRN_DB_TEXT:
129
+ case GRN_DB_LONG_TEXT:
130
+ *rb_value = rb_grn_context_rb_string_new(context,
131
+ GRN_TEXT_VALUE(bulk),
132
+ GRN_TEXT_LEN(bulk));
133
+ break;
134
+ default:
135
+ success = RB_GRN_FALSE;
136
+ break;
137
+ }
138
+
139
+ return success;
140
+ }
141
+
142
+ static VALUE
143
+ rb_grn_bulk_to_ruby_object_by_range_type (grn_ctx *context, grn_obj *bulk,
144
+ grn_obj *range, grn_id range_id,
145
+ VALUE related_object, VALUE *rb_value)
146
+ {
147
+ rb_grn_boolean success = RB_GRN_TRUE;
148
+
149
+ if (!range && range_id != GRN_ID_NIL) {
150
+ range = grn_ctx_at(context, range_id);
151
+ }
152
+
153
+ if (!range)
154
+ return RB_GRN_FALSE;
155
+
156
+ switch (range->header.type) {
157
+ case GRN_TABLE_HASH_KEY:
158
+ case GRN_TABLE_PAT_KEY:
159
+ case GRN_TABLE_NO_KEY:
160
+ {
161
+ grn_id id;
162
+
163
+ id = *((grn_id *)GRN_BULK_HEAD(bulk));
164
+ if (id == GRN_ID_NIL) {
165
+ *rb_value = Qnil;
166
+ } else {
167
+ VALUE rb_range;
168
+
169
+ rb_range = GRNOBJECT2RVAL(Qnil, context, range, RB_GRN_FALSE);
170
+ *rb_value = rb_grn_record_new(rb_range, id, Qnil);
171
+ }
172
+ }
173
+ break;
174
+ case GRN_TYPE:
175
+ if (range->header.flags & GRN_OBJ_KEY_VAR_SIZE) {
176
+ *rb_value = rb_grn_context_rb_string_new(context,
177
+ GRN_BULK_HEAD(bulk),
178
+ GRN_BULK_VSIZE(bulk));
179
+ } else {
180
+ switch (range->header.flags & GRN_OBJ_KEY_MASK) {
181
+ case GRN_OBJ_KEY_UINT:
182
+ *rb_value = INT2NUM(GRN_UINT32_VALUE(bulk));
183
+ break;
184
+ case GRN_OBJ_KEY_INT:
185
+ *rb_value = INT2NUM(GRN_INT32_VALUE(bulk));
186
+ break;
187
+ case GRN_OBJ_KEY_FLOAT:
188
+ *rb_value = rb_float_new(GRN_FLOAT_VALUE(bulk));
189
+ break;
190
+ default:
191
+ success = RB_GRN_FALSE;
192
+ }
193
+ break;
194
+ }
195
+ break;
196
+ default:
197
+ success = RB_GRN_FALSE;
198
+ break;
199
+ }
200
+
201
+ return success;
202
+ }
203
+
204
+ VALUE
205
+ rb_grn_bulk_to_ruby_object (grn_ctx *context, grn_obj *bulk,
206
+ grn_obj *range, VALUE related_object)
207
+ {
208
+ grn_id range_id;
209
+ VALUE rb_value = Qnil;
210
+
211
+ if (GRN_BULK_EMPTYP(bulk))
212
+ return Qnil;
213
+
214
+ range_id = bulk->header.domain;
215
+ if (rb_grn_bulk_to_ruby_object_by_range_id(context, bulk, range_id,
216
+ related_object, &rb_value))
217
+ return rb_value;
218
+
219
+ if (rb_grn_bulk_to_ruby_object_by_range_type(context, bulk,
220
+ range, range_id,
221
+ related_object, &rb_value))
222
+ return rb_value;
223
+
224
+ return rb_grn_context_rb_string_new(context,
225
+ GRN_BULK_HEAD(bulk),
226
+ GRN_BULK_VSIZE(bulk));
227
+ }
228
+
229
+ grn_obj *
230
+ rb_grn_bulk_from_ruby_object (VALUE object, grn_ctx *context, grn_obj *bulk)
231
+ {
232
+ if (bulk && bulk->header.domain == GRN_DB_TIME)
233
+ return rb_grn_bulk_from_ruby_object_with_type(
234
+ object, context, bulk, bulk->header.domain,
235
+ grn_ctx_at(context, bulk->header.domain));
236
+
237
+ if (!bulk) {
238
+ bulk = grn_obj_open(context, GRN_BULK, 0, GRN_ID_NIL);
239
+ rb_grn_context_check(context, object);
240
+ }
241
+
242
+ switch (TYPE(object)) {
243
+ case T_NIL:
244
+ grn_obj_reinit(context, bulk, GRN_DB_VOID, 0);
245
+ break;
246
+ case T_STRING:
247
+ grn_obj_reinit(context, bulk, GRN_DB_TEXT, 0);
248
+ GRN_TEXT_SET(context, bulk, RSTRING_PTR(object), RSTRING_LEN(object));
249
+ break;
250
+ case T_FIXNUM:
251
+ grn_obj_reinit(context, bulk, GRN_DB_INT32, 0);
252
+ GRN_INT32_SET(context, bulk, NUM2INT(object));
253
+ break;
254
+ case T_BIGNUM:
255
+ {
256
+ int64_t int64_value;
257
+ int64_value = NUM2LL(object);
258
+ if (int64_value <= INT32_MAX) {
259
+ grn_obj_reinit(context, bulk, GRN_DB_INT32, 0);
260
+ GRN_INT32_SET(context, bulk, int64_value);
261
+ } else {
262
+ grn_obj_reinit(context, bulk, GRN_DB_INT64, 0);
263
+ GRN_INT64_SET(context, bulk, int64_value);
264
+ }
265
+ }
266
+ break;
267
+ case T_FLOAT:
268
+ grn_obj_reinit(context, bulk, GRN_DB_FLOAT, 0);
269
+ GRN_FLOAT_SET(context, bulk, NUM2DBL(object));
270
+ break;
271
+ case T_TRUE:
272
+ grn_obj_reinit(context, bulk, GRN_DB_BOOL, 0);
273
+ GRN_BOOL_SET(context, bulk, GRN_TRUE);
274
+ break;
275
+ case T_FALSE:
276
+ grn_obj_reinit(context, bulk, GRN_DB_BOOL, 0);
277
+ GRN_BOOL_SET(context, bulk, GRN_FALSE);
278
+ break;
279
+ default:
280
+ if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cTime))) {
281
+ VALUE sec, usec;
282
+ int64_t time_value;
283
+
284
+ sec = rb_funcall(object, rb_intern("to_i"), 0);
285
+ usec = rb_funcall(object, rb_intern("usec"), 0);
286
+ time_value = GRN_TIME_PACK(NUM2LL(sec), NUM2LL(usec));
287
+ grn_obj_reinit(context, bulk, GRN_DB_TIME, 0);
288
+ GRN_TIME_SET(context, bulk, time_value);
289
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnObject))) {
290
+ grn_obj *grn_object;
291
+ grn_id id_value;
292
+
293
+ grn_object = RVAL2GRNOBJECT(object, &context);
294
+ grn_obj_reinit(context, bulk, grn_object->header.domain, 0);
295
+ id_value = grn_obj_id(context, grn_object);
296
+ GRN_RECORD_SET(context, bulk, id_value);
297
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnRecord))) {
298
+ grn_obj *table;
299
+ grn_id id_value;
300
+
301
+ table = RVAL2GRNOBJECT(rb_funcall(object, rb_intern("table"), 0),
302
+ &context);
303
+ id_value = NUM2UINT(rb_funcall(object, rb_intern("id"), 0));
304
+ grn_obj_reinit(context, bulk, grn_obj_id(context, table), 0);
305
+ GRN_RECORD_SET(context, bulk, id_value);
306
+ } else {
307
+ rb_raise(rb_eTypeError,
308
+ "bulked object should be one of "
309
+ "[nil, true, false, String, Integer, Float, Time, "
310
+ "Groonga::Object, Groonga::Record]: %s",
311
+ rb_grn_inspect(object));
312
+ }
313
+ break;
314
+ }
315
+
316
+ return bulk;
317
+ }
318
+
319
+ grn_obj *
320
+ rb_grn_bulk_from_ruby_object_with_type (VALUE object, grn_ctx *context,
321
+ grn_obj *bulk,
322
+ grn_id type_id, grn_obj *type)
323
+ {
324
+ const char *string;
325
+ unsigned int size;
326
+ int32_t int32_value;
327
+ uint32_t uint32_value;
328
+ int64_t int64_value;
329
+ uint64_t uint64_value;
330
+ int64_t time_value;
331
+ double double_value;
332
+ grn_id range;
333
+ VALUE rb_type_object;
334
+ grn_obj_flags flags = 0;
335
+
336
+ switch (type_id) {
337
+ case GRN_DB_INT32:
338
+ int32_value = NUM2INT(object);
339
+ string = (const char *)&int32_value;
340
+ size = sizeof(int32_value);
341
+ break;
342
+ case GRN_DB_UINT32:
343
+ uint32_value = NUM2UINT(object);
344
+ string = (const char *)&uint32_value;
345
+ size = sizeof(uint32_value);
346
+ break;
347
+ case GRN_DB_INT64:
348
+ int64_value = NUM2LL(object);
349
+ string = (const char *)&int64_value;
350
+ size = sizeof(int64_value);
351
+ break;
352
+ case GRN_DB_UINT64:
353
+ uint64_value = NUM2ULL(object);
354
+ string = (const char *)&uint64_value;
355
+ size = sizeof(uint64_value);
356
+ break;
357
+ case GRN_DB_FLOAT:
358
+ double_value = NUM2DBL(object);
359
+ string = (const char *)&double_value;
360
+ size = sizeof(double_value);
361
+ break;
362
+ case GRN_DB_TIME:
363
+ {
364
+ VALUE rb_sec, rb_usec;
365
+ int64_t sec;
366
+ int32_t usec;
367
+
368
+ switch (TYPE(object)) {
369
+ case T_FIXNUM:
370
+ case T_BIGNUM:
371
+ sec = NUM2LL(object);
372
+ usec = 0;
373
+ break;
374
+ case T_FLOAT:
375
+ rb_sec = rb_funcall(object, rb_intern("to_i"), 0);
376
+ rb_usec = rb_funcall(object, rb_intern("remainder"), 1,
377
+ INT2NUM(1));
378
+
379
+ sec = NUM2LL(rb_sec);
380
+ usec = (int32_t)(NUM2DBL(rb_usec) * 1000000);
381
+ break;
382
+ case T_NIL:
383
+ sec = 0;
384
+ usec = 0;
385
+ break;
386
+ default:
387
+ sec = NUM2LL(rb_funcall(object, rb_intern("to_i"), 0));
388
+ usec = NUM2INT(rb_funcall(object, rb_intern("usec"), 0));
389
+ break;
390
+ }
391
+
392
+ time_value = GRN_TIME_PACK(sec, usec);
393
+ }
394
+ string = (const char *)&time_value;
395
+ size = sizeof(time_value);
396
+ break;
397
+ case GRN_DB_SHORT_TEXT:
398
+ case GRN_DB_TEXT:
399
+ case GRN_DB_LONG_TEXT:
400
+ string = StringValuePtr(object);
401
+ size = RSTRING_LEN(object);
402
+ range = grn_obj_get_range(context, type);
403
+ if (size > range)
404
+ rb_raise(rb_eArgError,
405
+ "string is too large: expected: %u <= %u",
406
+ size, range);
407
+ flags |= GRN_OBJ_DO_SHALLOW_COPY;
408
+ break;
409
+ case GRN_DB_VOID:
410
+ case GRN_DB_DELIMIT:
411
+ case GRN_DB_UNIGRAM:
412
+ case GRN_DB_BIGRAM:
413
+ case GRN_DB_TRIGRAM:
414
+ case GRN_DB_MECAB:
415
+ rb_type_object = GRNOBJECT2RVAL(Qnil, context, type, RB_GRN_FALSE);
416
+ rb_raise(rb_eArgError,
417
+ "unbulkable type: %s",
418
+ rb_grn_inspect(rb_type_object));
419
+ break;
420
+ default:
421
+ return RVAL2GRNBULK(object, context, bulk);
422
+ break;
423
+ }
424
+
425
+ if (!bulk) {
426
+ bulk = grn_obj_open(context, GRN_BULK, flags, GRN_ID_NIL);
427
+ rb_grn_context_check(context, object);
428
+ }
429
+ GRN_TEXT_SET(context, bulk, string, size);
430
+
431
+ return bulk;
432
+ }
433
+
434
+
435
+ VALUE
436
+ rb_grn_vector_to_ruby_object (grn_ctx *context, grn_obj *vector)
437
+ {
438
+ VALUE array;
439
+ grn_obj value;
440
+ unsigned int i, n;
441
+
442
+ if (!vector)
443
+ return Qnil;
444
+
445
+ GRN_VOID_INIT(&value);
446
+ n = grn_vector_size(context, vector);
447
+ array = rb_ary_new2(n);
448
+ for (i = 0; i < n; i++) {
449
+ const char *_value;
450
+ unsigned int weight, length;
451
+ grn_id domain;
452
+
453
+ length = grn_vector_get_element(context, vector, i,
454
+ &_value, &weight, &domain);
455
+ grn_obj_reinit(context, &value, domain, 0);
456
+ grn_bulk_write(context, &value, _value, length);
457
+ rb_ary_push(array, GRNOBJ2RVAL(Qnil, context, &value, Qnil));
458
+ /* UINT2NUM(weight); */ /* TODO: How handle weight? */
459
+ }
460
+ GRN_OBJ_FIN(context, &value);
461
+
462
+ return array;
463
+ }
464
+
465
+ grn_obj *
466
+ rb_grn_vector_from_ruby_object (VALUE object, grn_ctx *context, grn_obj *vector)
467
+ {
468
+ VALUE *values;
469
+ grn_obj value;
470
+ int i, n;
471
+
472
+ if (vector)
473
+ GRN_OBJ_INIT(vector, GRN_VECTOR, 0, GRN_ID_NIL);
474
+ else
475
+ vector = grn_obj_open(context, GRN_VECTOR, 0, 0);
476
+
477
+ if (NIL_P(object))
478
+ return vector;
479
+
480
+ GRN_VOID_INIT(&value);
481
+ n = RARRAY_LEN(object);
482
+ values = RARRAY_PTR(object);
483
+ for (i = 0; i < n; i++) {
484
+ grn_obj *_value = &value;
485
+ RVAL2GRNOBJ(values[i], context, &_value);
486
+ grn_vector_add_element(context, vector,
487
+ GRN_BULK_HEAD(&value),
488
+ GRN_BULK_VSIZE(&value),
489
+ 0,
490
+ value.header.domain);
491
+ }
492
+ GRN_OBJ_FIN(context, &value);
493
+
494
+ return vector;
495
+ }
496
+
497
+ VALUE
498
+ rb_grn_uvector_to_ruby_object (grn_ctx *context, grn_obj *uvector)
499
+ {
500
+ VALUE array;
501
+ grn_id *current, *end;
502
+
503
+ if (!uvector)
504
+ return Qnil;
505
+
506
+ array = rb_ary_new();
507
+ current = (grn_id *)GRN_BULK_HEAD(uvector);
508
+ end = (grn_id *)GRN_BULK_CURR(uvector);
509
+ while (current < end) {
510
+ rb_ary_push(array, UINT2NUM(*current));
511
+ current++;
512
+ }
513
+
514
+ return array;
515
+ }
516
+
517
+ grn_obj *
518
+ rb_grn_uvector_from_ruby_object (VALUE object, grn_ctx *context,
519
+ grn_obj *uvector, VALUE related_object)
520
+ {
521
+ VALUE *values;
522
+ int i, n;
523
+
524
+ if (NIL_P(object))
525
+ return NULL;
526
+
527
+ n = RARRAY_LEN(object);
528
+ values = RARRAY_PTR(object);
529
+ for (i = 0; i < n; i++) {
530
+ VALUE value;
531
+ grn_id id;
532
+ void *grn_value;
533
+
534
+ value = values[i];
535
+ switch (TYPE(value)) {
536
+ case T_FIXNUM:
537
+ id = NUM2UINT(value);
538
+ break;
539
+ default:
540
+ if (RVAL2CBOOL(rb_obj_is_kind_of(value, rb_cGrnRecord))) {
541
+ id = NUM2UINT(rb_funcall(value, rb_intern("id"), 0));
542
+ } else {
543
+ grn_obj_unlink(context, uvector);
544
+ rb_raise(rb_eArgError,
545
+ "uvector value should be one of "
546
+ "[Fixnum, Groonga::Record]: %s (%s): %s",
547
+ rb_grn_inspect(value),
548
+ rb_grn_inspect(object),
549
+ rb_grn_inspect(related_object));
550
+ }
551
+ break;
552
+ }
553
+ grn_value = &id;
554
+ grn_bulk_write(context, uvector, grn_value, sizeof(grn_id));
555
+ }
556
+
557
+ return uvector;
558
+ }
559
+
560
+ VALUE
561
+ rb_grn_value_to_ruby_object (grn_ctx *context,
562
+ grn_obj *value,
563
+ grn_obj *range,
564
+ VALUE related_object)
565
+ {
566
+ if (!value)
567
+ return Qnil;
568
+
569
+ switch (value->header.type) {
570
+ case GRN_VOID:
571
+ return Qnil;
572
+ break;
573
+ case GRN_BULK:
574
+ if (GRN_BULK_EMPTYP(value))
575
+ return Qnil;
576
+ if (value->header.domain == GRN_ID_NIL && range)
577
+ value->header.domain = grn_obj_id(context, range);
578
+ return GRNBULK2RVAL(context, value, range, related_object);
579
+ break;
580
+ case GRN_UVECTOR:
581
+ {
582
+ VALUE rb_value, rb_range = Qnil;
583
+ grn_id *uvector, *uvector_end;
584
+
585
+ rb_value = rb_ary_new();
586
+ if (range)
587
+ rb_range = GRNTABLE2RVAL(context, range, RB_GRN_FALSE);
588
+ uvector = (grn_id *)GRN_BULK_HEAD(value);
589
+ uvector_end = (grn_id *)GRN_BULK_CURR(value);
590
+ for (; uvector < uvector_end; uvector++) {
591
+ VALUE record = Qnil;
592
+ if (*uvector != GRN_ID_NIL)
593
+ record = rb_grn_record_new(rb_range, *uvector, Qnil);
594
+ rb_ary_push(rb_value, record);
595
+ }
596
+ return rb_value;
597
+ }
598
+ break;
599
+ case GRN_VECTOR:
600
+ return GRNVECTOR2RVAL(context, value);
601
+ break;
602
+ default:
603
+ rb_raise(rb_eGrnError,
604
+ "unsupported value type: 0x%0x: %s",
605
+ value->header.type, rb_grn_inspect(related_object));
606
+ break;
607
+ }
608
+
609
+ if (!range)
610
+ return GRNOBJECT2RVAL(Qnil, context, value, RB_GRN_FALSE);
611
+
612
+ return Qnil;
613
+ }
614
+
615
+ grn_id
616
+ rb_grn_id_from_ruby_object (VALUE object, grn_ctx *context, grn_obj *table,
617
+ VALUE related_object)
618
+ {
619
+ VALUE rb_id;
620
+
621
+ if (NIL_P(object))
622
+ return Qnil;
623
+
624
+ if (RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnRecord))) {
625
+ VALUE rb_table;
626
+ rb_table = rb_funcall(object, rb_intern("table"), 0);
627
+ if (table && RVAL2GRNOBJECT(rb_table, &context) != table) {
628
+ VALUE rb_expected_table;
629
+
630
+ rb_expected_table =
631
+ GRNOBJECT2RVAL(Qnil, context, table, RB_GRN_FALSE);
632
+ rb_raise(rb_eGrnError,
633
+ "wrong table: expected <%s>: actual <%s>",
634
+ rb_grn_inspect(rb_expected_table),
635
+ rb_grn_inspect(rb_table));
636
+ }
637
+ rb_id = rb_funcall(object, rb_intern("id"), 0);
638
+ } else {
639
+ rb_id = object;
640
+ }
641
+
642
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_id, rb_cInteger)))
643
+ rb_raise(rb_eGrnError,
644
+ "should be unsigned integer or Groogna::Record: <%s>: <%s>",
645
+ rb_grn_inspect(object),
646
+ rb_grn_inspect(related_object));
647
+
648
+ return NUM2UINT(rb_id);
649
+ }
650
+
651
+ VALUE
652
+ rb_grn_key_to_ruby_object (grn_ctx *context, const void *key, int key_size,
653
+ grn_obj *table, VALUE related_object)
654
+ {
655
+ grn_obj bulk;
656
+
657
+ GRN_OBJ_INIT(&bulk, GRN_BULK, GRN_OBJ_DO_SHALLOW_COPY, table->header.domain);
658
+ GRN_TEXT_SET(context, &bulk, key, key_size);
659
+
660
+ return GRNBULK2RVAL(context, &bulk, NULL, related_object);
661
+ }
662
+
663
+ grn_obj *
664
+ rb_grn_key_from_ruby_object (VALUE rb_key, grn_ctx *context,
665
+ grn_obj *key, grn_id domain_id, grn_obj *domain,
666
+ VALUE related_object)
667
+ {
668
+ grn_id id;
669
+
670
+ if (!domain)
671
+ return RVAL2GRNBULK(rb_key, context, key);
672
+
673
+ switch (domain->header.type) {
674
+ case GRN_TYPE:
675
+ return RVAL2GRNBULK_WITH_TYPE(rb_key, context, key, domain_id, domain);
676
+ break;
677
+ case GRN_TABLE_HASH_KEY:
678
+ case GRN_TABLE_PAT_KEY:
679
+ case GRN_TABLE_NO_KEY:
680
+ id = RVAL2GRNID(rb_key, context, domain, related_object);
681
+ break;
682
+ default:
683
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_key, rb_cInteger)))
684
+ rb_raise(rb_eGrnError,
685
+ "should be unsigned integer: <%s>: <%s>",
686
+ rb_grn_inspect(rb_key),
687
+ rb_grn_inspect(related_object));
688
+
689
+ id = NUM2UINT(rb_key);
690
+ break;
691
+ }
692
+
693
+ GRN_TEXT_SET(context, key, &id, sizeof(id));
694
+ return key;
695
+ }
696
+
697
+ grn_obj *
698
+ rb_grn_obj_from_ruby_object (VALUE rb_object, grn_ctx *context, grn_obj **_obj)
699
+ {
700
+ if (RVAL2CBOOL(rb_obj_is_kind_of(rb_object, rb_cGrnObject))) {
701
+ if (*_obj) {
702
+ grn_obj_unlink(context, *_obj); /* TODO: reduce memory allocation */
703
+ }
704
+ *_obj = RVAL2GRNOBJECT(rb_object, &context);
705
+ } else {
706
+ *_obj = RVAL2GRNBULK(rb_object, context, *_obj);
707
+ }
708
+
709
+ return *_obj;
710
+ }
711
+
712
+ VALUE
713
+ rb_grn_obj_to_ruby_object (VALUE klass, grn_ctx *context,
714
+ grn_obj *obj, VALUE related_object)
715
+ {
716
+ if (!obj)
717
+ return Qnil;
718
+
719
+ /* if (NIL_P(klass)) */
720
+ /* klass = GRNOBJECT2RCLASS(obj); */
721
+
722
+ switch (obj->header.type) {
723
+ case GRN_VOID:
724
+ if (GRN_BULK_VSIZE(obj) > 0)
725
+ return rb_str_new(GRN_BULK_HEAD(obj), GRN_BULK_VSIZE(obj));
726
+ else
727
+ return Qnil;
728
+ break;
729
+ case GRN_BULK:
730
+ return GRNBULK2RVAL(context, obj, NULL, related_object);
731
+ break;
732
+ /* case GRN_PTR: */
733
+ /* case GRN_UVECTOR: */
734
+ /* case GRN_PVECTOR: */
735
+ /* case GRN_VECTOR: */
736
+ /* case GRN_MSG: */
737
+ /* case GRN_QUERY: */
738
+ /* case GRN_ACCESSOR: */
739
+ /* case GRN_SNIP: */
740
+ /* case GRN_PATSNIP: */
741
+ /* case GRN_CURSOR_TABLE_HASH_KEY: */
742
+ /* case GRN_CURSOR_TABLE_PAT_KEY: */
743
+ /* case GRN_CURSOR_TABLE_NO_KEY: */
744
+ /* case GRN_CURSOR_COLUMN_INDEX: */
745
+ /* case GRN_TYPE: */
746
+ /* case GRN_PROC: */
747
+ /* case GRN_EXPR: */
748
+ /* case GRN_TABLE_HASH_KEY: */
749
+ /* case GRN_TABLE_PAT_KEY: */
750
+ /* case GRN_TABLE_NO_KEY: */
751
+ /* case GRN_DB: */
752
+ /* case GRN_COLUMN_FIX_SIZE: */
753
+ /* case GRN_COLUMN_VAR_SIZE: */
754
+ /* case GRN_COLUMN_INDEX: */
755
+ default:
756
+ rb_raise(rb_eTypeError,
757
+ "unsupported groonga object: 0x%x: <%s>",
758
+ obj->header.type,
759
+ rb_grn_inspect(related_object));
760
+ break;
761
+ }
762
+
763
+ return Qnil;
764
+ }
765
+
766
+ void
767
+ rb_grn_init_utils (VALUE mGrn)
768
+ {
769
+ }