All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_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 
20 #include <aerospike/as_std.h>
21 #include <aerospike/as_util.h>
22 #include <aerospike/as_val.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /******************************************************************************
29  * TYPES
30  ******************************************************************************/
31 
32 struct as_iterator_hooks_s;
33 
34 /**
35  * Iterator Object
36  */
37 typedef struct as_iterator_s {
38 
39  /**
40  * @private
41  * If TRUE, then free this instance.
42  */
43  bool free;
44 
45  /**
46  * Data for the iterator.
47  */
48  void * data;
49 
50  /**
51  * Hooks for subtypes of as_iterator.
52  */
53  const struct as_iterator_hooks_s * hooks;
54 
55 } as_iterator;
56 
57 /**
58  * Iterator Function Hooks
59  */
60 typedef struct as_iterator_hooks_s {
61 
62  /**
63  * Releases the subtype of as_iterator.
64  */
65  bool (* destroy)(as_iterator *);
66 
67  /**
68  * Tests whether there is another element in the iterator.
69  */
70  bool (* has_next)(const as_iterator *);
71 
72  /**
73  * Read the next value.
74  */
75  const as_val * (* next)(as_iterator *);
76 
78 
79 /******************************************************************************
80  * INSTANCE FUNCTIONS
81  ******************************************************************************/
82 
83 /**
84  * Initialize a stack allocated iterator.
85  */
86 AS_EXTERN as_iterator * as_iterator_init(as_iterator * iterator, bool free, void * data, const as_iterator_hooks * hooks);
87 
88 /**
89  * Destroys the iterator and releasing associated resources.
90  */
92 
93 /******************************************************************************
94  * VALUE FUNCTIONS
95  ******************************************************************************/
96 
97 /**
98  * Tests if there are more values available in the iterator.
99  *
100  * @param iterator The iterator to be tested.
101  *
102  * @return true if there are more values, otherwise false.
103  */
104 static inline bool as_iterator_has_next(const as_iterator * iterator)
105 {
106  return as_util_hook(has_next, false, iterator);
107 }
108 
109 /**
110  * Attempts to get the next value from the iterator.
111  * This will return the next value, and iterate past the value.
112  *
113  * @param iterator The iterator to get the next value from.
114  *
115  * @return the next value available in the iterator.
116  */
117 static inline const as_val * as_iterator_next(as_iterator * iterator)
118 {
119  return as_util_hook(next, NULL, iterator);
120 }
121 
122 #ifdef __cplusplus
123 } // end extern "C"
124 #endif
void * data
Definition: as_iterator.h:48
#define as_util_hook(hook, default, object,...)
Definition: as_util.h:34
Definition: as_val.h:61
static bool as_iterator_has_next(const as_iterator *iterator)
Definition: as_iterator.h:104
AS_EXTERN void as_iterator_destroy(as_iterator *iterator)
#define AS_EXTERN
Definition: as_std.h:25
AS_EXTERN as_iterator * as_iterator_init(as_iterator *iterator, bool free, void *data, const as_iterator_hooks *hooks)
uint8_t data[0]
Definition: as_proto.h:38
const struct as_iterator_hooks_s * hooks
Definition: as_iterator.h:53
static const as_val * as_iterator_next(as_iterator *iterator)
Definition: as_iterator.h:117