ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs
iterator.h File Reference

Interface for iterator implementations. More...

#include "common.h"

Go to the source code of this file.

Data Structures

struct  cx_iterator_base_s
 The base of mutating and non-mutating iterators. More...
 
struct  cx_mut_iterator_s
 Internal iterator struct - use CxMutIterator. More...
 
struct  cx_iterator_s
 Internal iterator struct - use CxIterator. More...
 

Macros

#define cxIteratorValid(iter)   (iter).base.valid(&(iter))
 Checks if the iterator points to valid data.
 
#define cxIteratorCurrent(iter)   (iter).base.current(&iter)
 Returns a pointer to the current element.
 
#define cxIteratorNext(iter)   (iter).base.next(&iter)
 Advances the iterator to the next element.
 
#define cxIteratorFlagRemoval(iter)   (iter).base.flag_removal(&iter)
 Flags the current element for removal.
 
#define cx_foreach(type, elem, iter)   for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter))
 Loops over an iterator.
 

Typedefs

typedef struct cx_mut_iterator_s CxMutIterator
 Mutating iterator value type.
 
typedef struct cx_iterator_s CxIterator
 Iterator value type.
 

Detailed Description

Interface for iterator implementations.

Author
Mike Becker
Olaf Wintermann
Version
3.0

Macro Definition Documentation

◆ cx_foreach

#define cx_foreach (   type,
  elem,
  iter 
)    for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter)) != NULL ; cxIteratorNext(iter))

Loops over an iterator.

Parameters
typethe type of the elements
elemthe name of the iteration variable
iterthe iterator

◆ cxIteratorCurrent

#define cxIteratorCurrent (   iter)    (iter).base.current(&iter)

Returns a pointer to the current element.

The behavior is undefined if this iterator is invalid.

Parameters
iterthe iterator
Returns
a pointer to the current element

◆ cxIteratorFlagRemoval

#define cxIteratorFlagRemoval (   iter)    (iter).base.flag_removal(&iter)

Flags the current element for removal.

Parameters
iterthe iterator
Returns
false if this iterator cannot remove the element

◆ cxIteratorNext

#define cxIteratorNext (   iter)    (iter).base.next(&iter)

Advances the iterator to the next element.

Parameters
iterthe iterator

◆ cxIteratorValid

#define cxIteratorValid (   iter)    (iter).base.valid(&(iter))

Checks if the iterator points to valid data.

This is especially false for past-the-end iterators.

Parameters
iterthe iterator
Returns
true iff the iterator points to valid data

Typedef Documentation

◆ CxIterator

typedef struct cx_iterator_s CxIterator

Iterator value type.

An iterator points to a certain element in a (possibly unbounded) chain of elements. Iterators that are based on collections (which have a defined "first" element), are supposed to be "position-aware", which means that they keep track of the current index within the collection.

Note
Objects that are pointed to by an iterator are always mutable through that iterator. However, this iterator cannot mutate the collection itself (add or remove elements) and any mutation of the collection by other means makes this iterator invalid (regardless of what cxIteratorValid() returns).
See also
CxMutIterator

◆ CxMutIterator

Mutating iterator value type.

An iterator points to a certain element in an (possibly unbounded) chain of elements. Iterators that are based on collections (which have a defined "first" element), are supposed to be "position-aware", which means that they keep track of the current index within the collection.

Note
Objects that are pointed to by an iterator are mutable through that iterator. However, if the iterator is based on a collection and the underlying collection is mutated by other means than this iterator (e.g. elements added or removed), the iterator becomes invalid (regardless of what cxIteratorValid() returns) and MUST be re-obtained from the collection.
See also
CxIterator