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