Loading...
Searching...
No Matches
as_arraylist_iterator.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2018 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18#pragma once
19
22#include <aerospike/as_std.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/******************************************************************************
29 * TYPES
30 ******************************************************************************/
31
32/**
33 * Iterator for as_arraylist.
34 *
35 * To use the iterator, you can either initialize a stack allocated variable,
36 * using `as_arraylist_iterator_init()`:
37 *
38 * ~~~~~~~~~~{.c}
39 * as_arraylist_iterator it;
40 * as_arraylist_iterator_init(&it, &list);
41 * ~~~~~~~~~~
42 *
43 * Or you can create a new heap allocated variable, using
44 * `as_arraylist_iterator_new()`:
45 *
46 * ~~~~~~~~~~{.c}
47 * as_arraylist_iterator * it = as_arraylist_iterator_new(&list);
48 * ~~~~~~~~~~
49 *
50 * To iterate, use `as_arraylist_iterator_has_next()` and
51 * `as_arraylist_iterator_next()`:
52 *
53 * ~~~~~~~~~~{.c}
54 * while ( as_arraylist_iterator_has_next(&it) ) {
55 * const as_val * val = as_arraylist_iterator_next(&it);
56 * }
57 * ~~~~~~~~~~
58 *
59 * When you are finished using the iterator, then you should release the
60 * iterator and associated resources:
61 *
62 * ~~~~~~~~~~{.c}
63 * as_arraylist_iterator_destroy(it);
64 * ~~~~~~~~~~
65 *
66 *
67 * The `as_arraylist_iterator` is a subtype of `as_iterator`. This allows you
68 * to alternatively use `as_iterator` functions, by typecasting
69 * `as_arraylist_iterator` to `as_iterator`.
70 *
71 * ~~~~~~~~~~{.c}
72 * as_arraylist_iterator it;
73 * as_iterator * i = (as_iterator *) as_arraylist_iterator_init(&it, &list);
74 *
75 * while ( as_iterator_has_next(i) ) {
76 * const as_val * as_iterator_next(i);
77 * }
78 *
79 * as_iterator_destroy(i);
80 * ~~~~~~~~~~
81 *
82 * Each of the `as_iterator` functions proxy to the `as_arraylist_iterator`
83 * functions. So, calling `as_iterator_destroy()` is equivalent to calling
84 * `as_arraylist_iterator_destroy()`.
85 *
86 * @extends as_iterator
87 */
88typedef struct as_arraylist_iterator_s {
89
90 /**
91 * as_arraylist_iterator is an as_iterator.
92 * You can cast as_arraylist_iterator to as_iterator.
93 */
95
96 /**
97 * The as_arraylist being iterated over
98 */
100
101 /**
102 * The current position of the iteration
103 */
104 uint32_t pos;
105
107
108/******************************************************************************
109 * FUNCTIONS
110 *****************************************************************************/
111
112/**
113 * Initializes a stack allocated as_iterator for as_arraylist.
114 *
115 * @param iterator The iterator to initialize.
116 * @param list The list to iterate.
117 *
118 * @return On success, the initialized iterator. Otherwise NULL.
119 *
120 * @relatesalso as_arraylist_iterator
121 */
123
124/**
125 * Creates a new heap allocated as_iterator for as_arraylist.
126 *
127 * @param list The list to iterate.
128 *
129 * @return On success, the new iterator. Otherwise NULL.
130 *
131 * @relatesalso as_arraylist_iterator
132 */
134
135/**
136 * Destroy the iterator and releases resources used by the iterator.
137 *
138 * @param iterator The iterator to release
139 *
140 * @relatesalso as_arraylist_iterator
141 */
143
144/******************************************************************************
145 * ITERATOR FUNCTIONS
146 *****************************************************************************/
147
148/**
149 * Tests if there are more values available in the iterator.
150 *
151 * @param iterator The iterator to be tested.
152 *
153 * @return true if there are more values. Otherwise false.
154 *
155 * @relatesalso as_arraylist_iterator
156 */
158
159/**
160 * Attempts to get the next value from the iterator.
161 * This will return the next value, and iterate past the value.
162 *
163 * @param iterator The iterator to get the next value from.
164 *
165 * @return The next value in the list if available. Otherwise NULL.
166 *
167 * @relatesalso as_arraylist_iterator
168 */
170
171#ifdef __cplusplus
172} // end extern "C"
173#endif
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN as_arraylist_iterator * as_arraylist_iterator_init(as_arraylist_iterator *iterator, const as_arraylist *list)
const as_arraylist * list
AS_EXTERN bool as_arraylist_iterator_has_next(const as_arraylist_iterator *iterator)
AS_EXTERN as_arraylist_iterator * as_arraylist_iterator_new(const as_arraylist *list)
AS_EXTERN void as_arraylist_iterator_destroy(as_arraylist_iterator *iterator)
AS_EXTERN const as_val * as_arraylist_iterator_next(as_arraylist_iterator *iterator)