1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2015 Brazil
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 <groonga/plugin.h>
static grn_obj *
func_vector_size(grn_ctx *ctx, int n_args, grn_obj **args,
grn_user_data *user_data)
{
grn_obj *target;
unsigned int size;
grn_obj *grn_size;
if (n_args != 1) {
GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
"vector_size(): wrong number of arguments (%d for 1)",
n_args);
return NULL;
}
target = args[0];
switch (target->header.type) {
case GRN_VECTOR :
case GRN_PVECTOR :
case GRN_UVECTOR :
size = grn_vector_size(ctx, target);
break;
default :
{
grn_obj inspected;
GRN_TEXT_INIT(&inspected, 0);
grn_inspect(ctx, target, &inspected);
GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
"vector_size(): target object must be vector: <%.*s>",
(int)GRN_TEXT_LEN(&inspected),
GRN_TEXT_VALUE(&inspected));
GRN_OBJ_FIN(ctx, &inspected);
return NULL;
}
break;
}
grn_size = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_UINT32, 0);
if (!grn_size) {
return NULL;
}
GRN_UINT32_SET(ctx, grn_size, size);
return grn_size;
}
grn_rc
GRN_PLUGIN_INIT(grn_ctx *ctx)
{
return ctx->rc;
}
grn_rc
GRN_PLUGIN_REGISTER(grn_ctx *ctx)
{
grn_rc rc = GRN_SUCCESS;
grn_proc_create(ctx, "vector_size", -1, GRN_PROC_FUNCTION, func_vector_size,
NULL, NULL, 0, NULL);
return rc;
}
grn_rc
GRN_PLUGIN_FIN(grn_ctx *ctx)
{
return GRN_SUCCESS;
}
|