1/*
2 * udf_arglist.c
3 *
4 * Copyright (C) 2012-2016 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#include "aerospike/as_list.h"
24#include "aerospike/as_list_iterator.h"
25#include "aerospike/as_msgpack.h"
26
27#include "base/proto.h"
28#include "base/udf_arglist.h"
29
30/******************************************************************************
31 * STATIC FUNCTIONS
32 ******************************************************************************/
33
34static bool udf_arglist_foreach(const as_list *, as_list_foreach_callback, void *);
35static as_val *udf_arglist_get(const as_list *, const uint32_t idx);
36
37/******************************************************************************
38 * VARIABLES
39 ******************************************************************************/
40
41const as_list_hooks udf_arglist_hooks = {
42 .destroy = NULL,
43 .hashcode = NULL,
44 .size = NULL,
45 .append = NULL,
46 .prepend = NULL,
47 .get = udf_arglist_get,
48 .set = NULL,
49 .head = NULL,
50 .tail = NULL,
51 .drop = NULL,
52 .take = NULL,
53 .foreach = udf_arglist_foreach,
54 .iterator_init = NULL,
55 .iterator_new = NULL
56};
57
58/******************************************************************************
59 * FUNCTIONS
60 ******************************************************************************/
61
62static bool udf_arglist_foreach(const as_list * l, as_list_foreach_callback callback, void * context) {
63 if (l) {
64 as_list_iterator list_iter;
65 as_iterator* iter = (as_iterator*) &list_iter;
66 as_list_iterator_init(&list_iter, l);
67
68 while (as_iterator_has_next(iter)) {
69 const as_val* v = as_iterator_next(iter);
70 callback((as_val *) v, context);
71 }
72 as_iterator_destroy(iter);
73 }
74
75 return true;
76}
77
78static as_val *udf_arglist_get(const as_list * l, const uint32_t idx) {
79 return as_list_get(l, idx);
80}
81
82