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-1301 USA |
17 | */ |
18 | |
19 | #pragma once |
20 | |
21 | #ifdef __cplusplus |
22 | extern "C" { |
23 | #endif |
24 | |
25 | typedef struct _grn_array grn_array; |
26 | typedef struct _grn_array_cursor grn_array_cursor; |
27 | |
28 | GRN_API grn_array *grn_array_create(grn_ctx *ctx, const char *path, |
29 | unsigned int value_size, unsigned int flags); |
30 | GRN_API grn_array *grn_array_open(grn_ctx *ctx, const char *path); |
31 | GRN_API grn_rc grn_array_close(grn_ctx *ctx, grn_array *array); |
32 | GRN_API grn_id grn_array_add(grn_ctx *ctx, grn_array *array, void **value); |
33 | GRN_API grn_id grn_array_push(grn_ctx *ctx, grn_array *array, |
34 | void (*func)(grn_ctx *ctx, grn_array *array, |
35 | grn_id id, void *func_arg), |
36 | void *func_arg); |
37 | GRN_API grn_id grn_array_pull(grn_ctx *ctx, grn_array *array, grn_bool blockp, |
38 | void (*func)(grn_ctx *ctx, grn_array *array, |
39 | grn_id id, void *func_arg), |
40 | void *func_arg); |
41 | GRN_API void grn_array_unblock(grn_ctx *ctx, grn_array *array); |
42 | GRN_API int grn_array_get_value(grn_ctx *ctx, grn_array *array, grn_id id, void *valuebuf); |
43 | GRN_API grn_rc grn_array_set_value(grn_ctx *ctx, grn_array *array, grn_id id, |
44 | const void *value, int flags); |
45 | GRN_API grn_array_cursor *grn_array_cursor_open(grn_ctx *ctx, grn_array *array, |
46 | grn_id min, grn_id max, |
47 | int offset, int limit, int flags); |
48 | GRN_API grn_id grn_array_cursor_next(grn_ctx *ctx, grn_array_cursor *cursor); |
49 | GRN_API int grn_array_cursor_get_value(grn_ctx *ctx, grn_array_cursor *cursor, void **value); |
50 | GRN_API grn_rc grn_array_cursor_set_value(grn_ctx *ctx, grn_array_cursor *cursor, |
51 | const void *value, int flags); |
52 | GRN_API grn_rc grn_array_cursor_delete(grn_ctx *ctx, grn_array_cursor *cursor, |
53 | grn_table_delete_optarg *optarg); |
54 | GRN_API void grn_array_cursor_close(grn_ctx *ctx, grn_array_cursor *cursor); |
55 | GRN_API grn_rc grn_array_delete_by_id(grn_ctx *ctx, grn_array *array, grn_id id, |
56 | grn_table_delete_optarg *optarg); |
57 | |
58 | GRN_API grn_id grn_array_next(grn_ctx *ctx, grn_array *array, grn_id id); |
59 | |
60 | GRN_API void *_grn_array_get_value(grn_ctx *ctx, grn_array *array, grn_id id); |
61 | |
62 | #define GRN_ARRAY_EACH(ctx,array,head,tail,id,value,block) do {\ |
63 | grn_array_cursor *_sc = grn_array_cursor_open(ctx, array, head, tail, 0, -1, 0); \ |
64 | if (_sc) {\ |
65 | grn_id id;\ |
66 | while ((id = grn_array_cursor_next(ctx, _sc))) {\ |
67 | grn_array_cursor_get_value(ctx, _sc, (void **)(value));\ |
68 | block\ |
69 | }\ |
70 | grn_array_cursor_close(ctx, _sc); \ |
71 | }\ |
72 | } while (0) |
73 | |
74 | #define GRN_ARRAY_EACH_BEGIN(ctx, array, cursor, head, tail, id) do {\ |
75 | grn_array_cursor *cursor;\ |
76 | cursor = grn_array_cursor_open((ctx), (array), (head), (tail), 0, -1, 0);\ |
77 | if (cursor) {\ |
78 | grn_id id;\ |
79 | while ((id = grn_array_cursor_next(ctx, cursor))) { |
80 | |
81 | #define GRN_ARRAY_EACH_END(ctx, cursor)\ |
82 | }\ |
83 | grn_array_cursor_close(ctx, cursor);\ |
84 | }\ |
85 | } while (0) |
86 | |
87 | #ifdef __cplusplus |
88 | } |
89 | #endif |
90 | |