1 /* 2 Copyright(C) 2009-2016 Brazil 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA 17 */ 18 19 #pragma once 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 typedef struct _grn_obj_format grn_obj_format; 26 27 #define GRN_OBJ_FORMAT_WITH_COLUMN_NAMES (0x01<<0) 28 #define GRN_OBJ_FORMAT_AS_ARRAY (0x01<<3) 29 /* Deprecated since 4.0.1. It will be removed at 5.0.0. 30 Use GRN_OBJ_FORMAT_AS_ARRAY instead.*/ 31 #define GRN_OBJ_FORMAT_ASARRAY GRN_OBJ_FORMAT_AS_ARRAY 32 #define GRN_OBJ_FORMAT_WITH_WEIGHT (0x01<<4) 33 34 struct _grn_obj_format { 35 grn_obj columns; 36 const void *min; 37 const void *max; 38 unsigned int min_size; 39 unsigned int max_size; 40 int nhits; 41 int offset; 42 int limit; 43 int hits_offset; 44 int flags; 45 grn_obj *expression; 46 }; 47 48 #define GRN_OBJ_FORMAT_INIT(format,format_nhits,format_offset,format_limit,format_hits_offset) do { \ 49 GRN_PTR_INIT(&(format)->columns, GRN_OBJ_VECTOR, GRN_ID_NIL);\ 50 (format)->nhits = (format_nhits);\ 51 (format)->offset = (format_offset);\ 52 (format)->limit = (format_limit);\ 53 (format)->hits_offset = (format_hits_offset);\ 54 (format)->flags = 0;\ 55 (format)->expression = NULL;\ 56 } while (0) 57 58 #define GRN_OBJ_FORMAT_FIN(ctx,format) do {\ 59 int ncolumns = GRN_BULK_VSIZE(&(format)->columns) / sizeof(grn_obj *);\ 60 grn_obj **columns = (grn_obj **)GRN_BULK_HEAD(&(format)->columns);\ 61 while (ncolumns--) {\ 62 grn_obj *column = *columns;\ 63 columns++;\ 64 if (grn_obj_is_accessor((ctx), column)) {\ 65 grn_obj_close((ctx), column);\ 66 }\ 67 }\ 68 GRN_OBJ_FIN((ctx), &(format)->columns);\ 69 if ((format)->expression) { GRN_OBJ_FIN((ctx), (format)->expression); } \ 70 } while (0) 71 72 GRN_API void grn_output_obj(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type, 73 grn_obj *obj, grn_obj_format *format); 74 GRN_API void grn_output_envelope(grn_ctx *ctx, grn_rc rc, 75 grn_obj *head, grn_obj *body, grn_obj *foot, 76 const char *file, int line); 77 78 GRN_API void grn_ctx_output_flush(grn_ctx *ctx, int flags); 79 GRN_API void grn_ctx_output_array_open(grn_ctx *ctx, 80 const char *name, int nelements); 81 GRN_API void grn_ctx_output_array_close(grn_ctx *ctx); 82 GRN_API void grn_ctx_output_map_open(grn_ctx *ctx, 83 const char *name, int nelements); 84 GRN_API void grn_ctx_output_map_close(grn_ctx *ctx); 85 GRN_API void grn_ctx_output_null(grn_ctx *ctx); 86 GRN_API void grn_ctx_output_int32(grn_ctx *ctx, int value); 87 GRN_API void grn_ctx_output_int64(grn_ctx *ctx, int64_t value); 88 GRN_API void grn_ctx_output_uint64(grn_ctx *ctx, uint64_t value); 89 GRN_API void grn_ctx_output_float(grn_ctx *ctx, double value); 90 GRN_API void grn_ctx_output_cstr(grn_ctx *ctx, const char *value); 91 GRN_API void grn_ctx_output_str(grn_ctx *ctx, 92 const char *value, unsigned int value_len); 93 GRN_API void grn_ctx_output_bool(grn_ctx *ctx, grn_bool value); 94 GRN_API void grn_ctx_output_obj(grn_ctx *ctx, 95 grn_obj *value, grn_obj_format *format); 96 GRN_API void grn_ctx_output_result_set_open(grn_ctx *ctx, 97 grn_obj *result_set, 98 grn_obj_format *format, 99 uint32_t n_additional_elements); 100 GRN_API void grn_ctx_output_result_set_close(grn_ctx *ctx, 101 grn_obj *result_set, 102 grn_obj_format *format); 103 GRN_API void grn_ctx_output_result_set(grn_ctx *ctx, 104 grn_obj *result_set, 105 grn_obj_format *format); 106 GRN_API void grn_ctx_output_table_columns(grn_ctx *ctx, 107 grn_obj *table, 108 grn_obj_format *format); 109 GRN_API void grn_ctx_output_table_records(grn_ctx *ctx, 110 grn_obj *table, 111 grn_obj_format *format); 112 113 114 GRN_API grn_content_type grn_ctx_get_output_type(grn_ctx *ctx); 115 GRN_API grn_rc grn_ctx_set_output_type(grn_ctx *ctx, grn_content_type type); 116 GRN_API const char *grn_ctx_get_mime_type(grn_ctx *ctx); 117 118 /* obsolete */ 119 GRN_API grn_rc grn_text_otoj(grn_ctx *ctx, grn_obj *bulk, grn_obj *obj, 120 grn_obj_format *format); 121 122 #ifdef __cplusplus 123 } 124 #endif 125