ucx
UAP Common Extensions
Loading...
Searching...
No Matches
iterator.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
37#ifndef UCX_ITERATOR_H
38#define UCX_ITERATOR_H
39
40#include "common.h"
41
49 __attribute__ ((__nonnull__))
50 bool (*valid)(void const *);
51
57 __attribute__ ((__nonnull__))
58 void *(*current)(void const *);
59
63 __attribute__ ((__nonnull__))
64 void *(*current_impl)(void const *);
65
71 __attribute__ ((__nonnull__))
72 void (*next)(void *);
73
79 __attribute__ ((__nonnull__))
80 bool (*flag_removal)(void *);
81
86
90 bool remove;
91};
92
97
102
107
112
117 struct {
121 void const *key;
125 void *value;
126 } kv_data;
127
132 size_t slot;
133
138 size_t index;
139};
140
156
161
166
171
175 void const *src_handle;
176
181 struct {
185 void const *key;
189 void *value;
190 } kv_data;
191
196 size_t slot;
197
202 size_t index;
203};
204
218
227#define cxIteratorValid(iter) (iter).base.valid(&(iter))
228
237#define cxIteratorCurrent(iter) (iter).base.current(&iter)
238
244#define cxIteratorNext(iter) (iter).base.next(&iter)
245
252#define cxIteratorFlagRemoval(iter) (iter).base.flag_removal(&iter)
253
260#define cx_foreach(type, elem, iter) \
261for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter))
262
263#endif // UCX_ITERATOR_H
Common definitions and feature checks.
#define __attribute__(x)
Removes GNU C attributes where they are not supported.
Definition: common.h:127
The base of mutating and non-mutating iterators.
Definition: iterator.h:45
void *(* current_impl)(void const *)
Original implementation in case the function needs to be wrapped.
Definition: iterator.h:64
void *(* current)(void const *)
Returns a pointer to the current element.
Definition: iterator.h:58
bool remove
Internal flag for removing the current element when advancing.
Definition: iterator.h:90
bool(* valid)(void const *)
True iff the iterator points to valid data.
Definition: iterator.h:50
bool(* flag_removal)(void *)
Flag current element for removal, if possible.
Definition: iterator.h:80
bool mutating
Indicates whether this iterator may remove elements.
Definition: iterator.h:85
void(* next)(void *)
Advances the iterator.
Definition: iterator.h:72
Internal iterator struct - use CxIterator.
Definition: iterator.h:160
void * elem_handle
Handle for the current element, if required.
Definition: iterator.h:170
size_t slot
Field for storing a slot number.
Definition: iterator.h:196
void const * key
A pointer to the key.
Definition: iterator.h:185
size_t index
If the iterator is position-aware, contains the index of the element in the underlying collection.
Definition: iterator.h:202
void const * src_handle
Handle for the source collection, if any.
Definition: iterator.h:175
void * value
A pointer to the value.
Definition: iterator.h:189
Internal iterator struct - use CxMutIterator.
Definition: iterator.h:96
size_t slot
Field for storing a slot number.
Definition: iterator.h:132
size_t index
If the iterator is position-aware, contains the index of the element in the underlying collection.
Definition: iterator.h:138
void const * key
A pointer to the key.
Definition: iterator.h:121
void * elem_handle
Handle for the current element, if required.
Definition: iterator.h:106
void * value
A pointer to the value.
Definition: iterator.h:125
void * src_handle
Handle for the source collection, if any.
Definition: iterator.h:111