Debian Codegraph @

include/groonga/output.h

raw symbols SCIP
1 /*
2 Copyright (C) 2009-2018 Brazil
3 Copyright (C) 2018-2025 Sutou Kouhei <[email protected]>
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 as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #pragma once
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 typedef struct _grn_obj_format grn_obj_format;
27
28 #define GRN_OBJ_FORMAT_WITH_COLUMN_NAMES (0x01 << 0)
29 #define GRN_OBJ_FORMAT_AS_ARRAY (0x01 << 3)
30 /* Deprecated since 4.0.1. It will be removed at 5.0.0.
31 Use GRN_OBJ_FORMAT_AS_ARRAY instead.*/
32 #define GRN_OBJ_FORMAT_ASARRAY GRN_OBJ_FORMAT_AS_ARRAY
33 #define GRN_OBJ_FORMAT_WITH_WEIGHT (0x01 << 4)
34 /* Format weight as float32.
35 Since 10.0.3 */
36 #define GRN_OBJ_FORMAT_WEIGHT_FLOAT32 (0x01 << 5)
37 /* Call grn_ctx_output_flush() internally for each 1024 records in a table.
38 The "1024" value may be changed.
39 Since 10.0.3 */
40 #define GRN_OBJ_FORMAT_AUTO_FLUSH (0x01 << 6)
41
42 struct _grn_obj_format {
43 grn_obj columns;
44 const void *min;
45 const void *max;
46 unsigned int min_size;
47 unsigned int max_size;
48 int nhits;
49 int offset;
50 int limit;
51 int hits_offset;
52 uint32_t flags;
53 grn_obj *expression;
54 };
55
56 GRN_API grn_rc
57 grn_output_range_normalize(grn_ctx *ctx, int size, int *offset, int *limit);
58
59 #define GRN_OBJ_FORMAT_INIT(format, \
60 format_nhits, \
61 format_offset, \
62 format_limit, \
63 format_hits_offset) \
64 do { \
65 GRN_PTR_INIT(&(format)->columns, GRN_OBJ_VECTOR, GRN_ID_NIL); \
66 (format)->nhits = (format_nhits); \
67 (format)->offset = (format_offset); \
68 (format)->limit = (format_limit); \
69 (format)->hits_offset = (format_hits_offset); \
70 (format)->flags = 0; \
71 (format)->expression = NULL; \
72 } while (0)
73
74 /* Deprecated since 10.0.0. Use grn_obj_format_fin() instead. */
75 #define GRN_OBJ_FORMAT_FIN(ctx, format) grn_obj_format_fin((ctx), (format))
76 GRN_API grn_rc
77 grn_obj_format_fin(grn_ctx *ctx, grn_obj_format *format);
78
79 GRN_API void
80 grn_output_obj(grn_ctx *ctx,
81 grn_obj *outbuf,
82 grn_content_type output_type,
83 grn_obj *obj,
84 grn_obj_format *format);
85 GRN_API void
86 grn_output_envelope(grn_ctx *ctx,
87 grn_rc rc,
88 grn_obj *head,
89 grn_obj *body,
90 grn_obj *foot,
91 const char *file,
92 int line);
93 GRN_API void
94 grn_output_envelope_open(grn_ctx *ctx, grn_obj *output);
95 GRN_API void
96 grn_output_envelope_close(
97 grn_ctx *ctx, grn_obj *output, grn_rc rc, const char *file, int line);
98
99 GRN_API void
100 grn_output_array_open(grn_ctx *ctx,
101 grn_obj *outbuf,
102 grn_content_type output_type,
103 const char *name,
104 int n_elements);
105 GRN_API void
106 grn_output_array_close(grn_ctx *ctx,
107 grn_obj *outbuf,
108 grn_content_type output_type);
109 GRN_API void
110 grn_output_map_open(grn_ctx *ctx,
111 grn_obj *outbuf,
112 grn_content_type output_type,
113 const char *name,
114 int n_elements);
115 GRN_API void
116 grn_output_map_close(grn_ctx *ctx,
117 grn_obj *outbuf,
118 grn_content_type output_type);
119 GRN_API void
120 grn_output_null(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type);
121 GRN_API void
122 grn_output_int32(grn_ctx *ctx,
123 grn_obj *outbuf,
124 grn_content_type output_type,
125 int32_t value);
126 GRN_API void
127 grn_output_uint32(grn_ctx *ctx,
128 grn_obj *outbuf,
129 grn_content_type output_type,
130 uint32_t value);
131 GRN_API void
132 grn_output_int64(grn_ctx *ctx,
133 grn_obj *outbuf,
134 grn_content_type output_type,
135 int64_t value);
136 GRN_API void
137 grn_output_uint64(grn_ctx *ctx,
138 grn_obj *outbuf,
139 grn_content_type output_type,
140 uint64_t value);
141 #ifdef GRN_HAVE_BFLOAT16
142 GRN_API void
143 grn_output_bfloat16(grn_ctx *ctx,
144 grn_obj *outbuf,
145 grn_content_type output_type,
146 grn_bfloat16 value);
147 #endif
148 GRN_API void
149 grn_output_float32(grn_ctx *ctx,
150 grn_obj *outbuf,
151 grn_content_type output_type,
152 float value);
153 GRN_API void
154 grn_output_float(grn_ctx *ctx,
155 grn_obj *outbuf,
156 grn_content_type output_type,
157 double value);
158 GRN_API void
159 grn_output_cstr(grn_ctx *ctx,
160 grn_obj *outbuf,
161 grn_content_type output_type,
162 const char *value);
163 GRN_API void
164 grn_output_str(grn_ctx *ctx,
165 grn_obj *outbuf,
166 grn_content_type output_type,
167 const char *value,
168 size_t value_len);
169 GRN_API void
170 grn_output_binary(grn_ctx *ctx,
171 grn_obj *outbuf,
172 grn_content_type output_type,
173 const uint8_t *value,
174 size_t value_len);
175 GRN_API void
176 grn_output_json(grn_ctx *ctx,
177 grn_obj *outbuf,
178 grn_content_type output_type,
179 const uint8_t *value,
180 size_t value_len);
181 GRN_API void
182 grn_output_bool(grn_ctx *ctx,
183 grn_obj *outbuf,
184 grn_content_type output_type,
185 bool value);
186
187 GRN_API void
188 grn_ctx_output_flush(grn_ctx *ctx, int flags);
189 GRN_API void
190 grn_ctx_output_array_open(grn_ctx *ctx, const char *name, int nelements);
191 GRN_API void
192 grn_ctx_output_array_close(grn_ctx *ctx);
193 GRN_API void
194 grn_ctx_output_map_open(grn_ctx *ctx, const char *name, int nelements);
195 GRN_API void
196 grn_ctx_output_map_close(grn_ctx *ctx);
197 GRN_API void
198 grn_ctx_output_null(grn_ctx *ctx);
199 GRN_API void
200 grn_ctx_output_int32(grn_ctx *ctx, int32_t value);
201 GRN_API void
202 grn_ctx_output_uint32(grn_ctx *ctx, uint32_t value);
203 GRN_API void
204 grn_ctx_output_int64(grn_ctx *ctx, int64_t value);
205 GRN_API void
206 grn_ctx_output_uint64(grn_ctx *ctx, uint64_t value);
207 GRN_API void
208 grn_ctx_output_float32(grn_ctx *ctx, float value);
209 GRN_API void
210 grn_ctx_output_float(grn_ctx *ctx, double value);
211 GRN_API void
212 grn_ctx_output_cstr(grn_ctx *ctx, const char *value);
213 GRN_API void
214 grn_ctx_output_str(grn_ctx *ctx, const char *value, size_t value_len);
215 GRN_API void
216 grn_ctx_output_bool(grn_ctx *ctx, bool value);
217 GRN_API void
218 grn_ctx_output_obj(grn_ctx *ctx, grn_obj *value, grn_obj_format *format);
219 GRN_API void
220 grn_ctx_output_result_set_open_metadata(grn_ctx *ctx,
221 grn_obj *result_set,
222 grn_obj_format *format,
223 uint32_t n_additional_elements);
224 GRN_API void
225 grn_ctx_output_result_set_open(grn_ctx *ctx,
226 grn_obj *result_set,
227 grn_obj_format *format,
228 uint32_t n_additional_elements);
229 GRN_API void
230 grn_ctx_output_result_set_close(grn_ctx *ctx,
231 grn_obj *result_set,
232 grn_obj_format *format);
233 GRN_API void
234 grn_ctx_output_result_set(grn_ctx *ctx,
235 grn_obj *result_set,
236 grn_obj_format *format);
237 GRN_API void
238 grn_ctx_output_table_columns(grn_ctx *ctx,
239 grn_obj *table,
240 grn_obj_format *format);
241 GRN_API void
242 grn_ctx_output_table_records_open(grn_ctx *ctx, int n_records);
243 GRN_API void
244 grn_ctx_output_table_records_content(grn_ctx *ctx,
245 grn_obj *table,
246 grn_obj_format *format);
247 GRN_API void
248 grn_ctx_output_table_records_close(grn_ctx *ctx);
249 GRN_API void
250 grn_ctx_output_table_records(grn_ctx *ctx,
251 grn_obj *table,
252 grn_obj_format *format);
253
254 /**
255 * \brief Get the current output type of the context.
256 *
257 * \note Normally, you don't need to call this function unless you need to
258 * check the output type explicitly.
259 *
260 * \param ctx The context object.
261 *
262 * \return Return the output type of the context, which is one of the values
263 * defined in \ref grn_content_type. Return \ref GRN_CONTENT_NONE if the
264 * context is invalid.
265 */
266 GRN_API grn_content_type
267 grn_ctx_get_output_type(grn_ctx *ctx);
268 /**
269 * \brief Set the output type for the context when executing a command.
270 *
271 * The output type determines the format of the result when executing a command
272 * using \ref grn_expr_exec. If you use \ref grn_ctx_send, the new output type
273 * isn't used because \ref grn_ctx_send sets the output type internally based on
274 * the command.
275 *
276 * \note Normally, you don't need to call this function unless you need to
277 * change the output type explicitly when executing a command using \ref
278 * grn_expr_exec.
279 *
280 * \param ctx The context object.
281 * \param type The new output type to set.
282 *
283 * \return \ref GRN_SUCCESS on success, the appropriate \ref grn_rc on error.
284 * For example, \ref GRN_INVALID_ARGUMENT is returned if `type` is
285 * invalid.
286 */
287 GRN_API grn_rc
288 grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type);
289 GRN_API const char *
290 grn_ctx_get_mime_type(grn_ctx *ctx);
291
292 /* obsolete */
293 GRN_API grn_rc
294 grn_text_otoj(grn_ctx *ctx,
295 grn_obj *bulk,
296 grn_obj *obj,
297 grn_obj_format *format);
298
299 #ifdef __cplusplus
300 }
301 #endif