Loading...
Searching...
No Matches
as_record_iterator.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2024 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#pragma once
18
19#include <aerospike/as_bin.h>
20#include <aerospike/as_bytes.h>
22#include <aerospike/as_key.h>
23#include <aerospike/as_list.h>
24#include <aerospike/as_map.h>
25#include <aerospike/as_rec.h>
26#include <aerospike/as_record.h>
27#include <aerospike/as_string.h>
28#include <aerospike/as_util.h>
29#include <aerospike/as_val.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35//---------------------------------
36// Types
37//---------------------------------
38
39/**
40 * Iterator over bins of a record.
41 *
42 * ## Initialization
43 *
44 * The as_record_iterator can be initialized via:
45 *
46 * - as_record_iterator_init() — initializes a stack allocated
47 * as_record_iterator.
48 * - as_record_iterator_new() — allocated and initializes an
49 * as_record_iterator on the heap.
50 *
51 * Both of the function require the record on which it will iterate.
52 *
53 * To initialize an as_record_iterator on the stack:
54 *
55 * ~~~~~~~~~~{.c}
56 * as_record_iterator it;
57 * as_record_iterator_init(&it, record);
58 * ~~~~~~~~~~
59 *
60 * To initialize an as_record_iterator on the heap:
61 *
62 * ~~~~~~~~~~{.c}
63 * as_record_iterator * it as_record_iterator_new(record);
64 * ~~~~~~~~~~
65 *
66 * ## Destruction
67 *
68 * When you no longer require the iterator, you should release it and
69 * associated resource via as_record_iterator_destroy():
70 *
71 * ~~~~~~~~~~{.c}
72 * as_record_iterator_destroy(it);
73 * ~~~~~~~~~~
74 *
75 * ## Usage
76 *
77 * With an initialized as_record_iterator, you can traverse the bins of
78 * a record.
79 *
80 * Traversal is usually performed by first checking to see if
81 * the there are any bins available to traverse to via
82 * as_record_iterator_has_next(), which returns true if there are more bins,
83 * or false if there are no more bins.
84 *
85 * ~~~~~~~~~~{.c}
86 * as_record_iterator_has_next(&it);
87 * ~~~~~~~~~~
88 *
89 * When you are sure there are more bins, then you will use
90 * as_record_iterator_next() to read the next bin. If there are no bins
91 * available, then NULL is returned.
92 *
93 * ~~~~~~~~~~{.c}
94 * as_bin* bin = as_record_iterator_next(&it);
95 * ~~~~~~~~~~
96 *
97 * If as_record_iterator_next() returns a bin, then you can use the following
98 * functions to get information about the bin:
99 *
100 * - as_bin_get_name() — Get the bin's name.
101 * - as_bin_get_value() — Get the bin's value.
102 * - as_bin_get_type() — Get the bin's values' types.
103 *
104 * Most often, a traversal is performed in a while loop. The following is a
105 * simple example:
106 *
107 * ~~~~~~~~~~{.c}
108 * while ( as_record_iterator_has_next(&it) ) {
109 * as_bin* bin = as_record_iterator_next(&it);
110 * char* name = as_bin_get_name(bin);
111 * as_val* value = (as_val*) as_bin_get_value(bin);
112 * }
113 * ~~~~~~~~~~
114 *
115 * @relates as_record
116 */
117typedef struct as_record_iterator_s {
118
119 /**
120 * @private
121 * If true, then as_record_iterator_destroy() will free this object.
122 */
123 bool _free;
124
125 /**
126 * The record being iterated over.
127 */
129
130 /**
131 * Current position of the iterator
132 */
133 uint32_t pos;
134
136
137//---------------------------------
138// Functions
139//---------------------------------
140
141/**
142 * Create and initialize a heap allocated as_record_iterator for the
143 * specified record.
144 *
145 * ~~~~~~~~~~{.c}
146 * as_record_iterator * it = as_record_iterator_new(rec);
147 *
148 * while (as_record_iterator_has_next(&it)) {
149 * as_bin* bin = as_record_iterator_next(&it);
150 * }
151 *
152 * as_record_iterator_destroy(&it);
153 * ~~~~~~~~~~
154 *
155 * @param record The record to iterate over.
156 *
157 * @return On success, a new as_record_iterator. Otherwise an error occurred.
158 *
159 * @relates as_record_iterator
160 */
163
164/**
165 * Initializes a stack allocated as_record_iterator for the specified record.
166 *
167 * ~~~~~~~~~~{.c}
168 * as_record_iterator it;
169 * as_record_iterator_init(&it, rec);
170 *
171 * while (as_record_iterator_has_next(&it)) {
172 * as_bin* bin = as_record_iterator_next(&it);
173 * }
174 *
175 * as_record_iterator_destroy(&it);
176 * ~~~~~~~~~~
177 *
178 * When you are finished using the `as_record` instance, you should release the
179 * resources allocated to it by calling `as_record_destroy()`.
180 *
181 * @param iterator The iterator to initialize.
182 * @param record The record to iterate over
183 *
184 * @return On success, a new as_record_iterator. Otherwise an error occurred.
185 *
186 * @relates as_record_iterator
187 */
190
191/**
192 * Destroy the as_record_iterator and associated resources.
193 *
194 * @param iterator The iterator to destroy.
195 *
196 * @relates as_record_iterator
197 */
198AS_EXTERN void
200
201/**
202 * Test if there are more bins in the iterator.
203 *
204 * @param iterator The iterator to test.
205 *
206 * @return the number of bins in the record.
207 *
208 * @relates as_record_iterator
209 */
210AS_EXTERN bool
212
213/**
214 * Read the next bin from the iterator.
215 *
216 * @param iterator The iterator to read from.
217 *
218 * @return The next bin from the iterator.
219 *
220 * @relates as_record_iterator
221 */
224
225#ifdef __cplusplus
226} // end extern "C"
227#endif
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN as_record_iterator * as_record_iterator_new(const as_record *record)
AS_EXTERN as_bin * as_record_iterator_next(as_record_iterator *iterator)
AS_EXTERN bool as_record_iterator_has_next(const as_record_iterator *iterator)
AS_EXTERN void as_record_iterator_destroy(as_record_iterator *iterator)
AS_EXTERN as_record_iterator * as_record_iterator_init(as_record_iterator *iterator, const as_record *record)
const as_record * record