Iterator

digraph inheritance { rankdir=LR; GBoxed -> WpIterator; }
struct WpIterator

A generic iterator API

struct _WpIteratorMethods

Public Members

guint32 version
voidreset)(WpIterator *self)
gbooleannext)(WpIterator *self, GValue *item)
gbooleanfold)(WpIterator *self, WpIteratorFoldFunc func, GValue *ret, gpointer data)
gbooleanforeach)(WpIterator *self, WpIteratorForeachFunc func, gpointer data)
voidfinalize)(WpIterator *self)
typedef gboolean(* WpIteratorFoldFunc)(const GValue *item, GValue *ret, gpointer data)

A function to be passed to wp_iterator_fold()

Return
TRUE if the fold should continue, FALSE if it should stop.
Parameters
  • item: the item to fold
  • ret: the value collecting the result
  • data: data passed to wp_iterator_fold()

typedef void(* WpIteratorForeachFunc)(const GValue *item, gpointer data)

A function that is called by wp_iterator_foreach().

Parameters

WpIterator* wp_iterator_new(const WpIteratorMethods * methods, size_t user_size)

Constructs an iterator that uses the provided methods to implement its API.

The WpIterator structure is internally allocated with user_size additional space at the end. A pointer to this space can be retrieved with wp_iterator_get_user_data() and is available for implementation-specific storage.

Return
(transfer full): a new custom iterator
Parameters
  • methods: method implementations for the new iterator
  • user_size: size of the user_data structure to be allocated

gpointer wp_iterator_get_user_data(WpIterator * self)

Gets the implementation-specific storage of an iterator.

Note
this only for use by implementations of WpIterator
Return
a pointer to the implementation-specific storage area
Parameters
  • self: an iterator object

WpIterator* wp_iterator_ref(WpIterator * self)

Increases the reference count of an iterator.

Return
(transfer full): self with an additional reference count on it
Parameters
  • self: an iterator object

void wp_iterator_unref(WpIterator * self)

Decreases the reference count on self and frees it when the ref count reaches zero.

Parameters
  • self: (transfer full): an iterator object

void wp_iterator_reset(WpIterator * self)

Resets the iterator so we can iterate again from the beginning.

Parameters
  • self: the iterator

gboolean wp_iterator_next(WpIterator * self, GValue * item)

Gets the next item of the iterator.

Return
TRUE if next iterator was obtained, FALSE when the iterator has no more items to iterate through.
Parameters
  • self: the iterator
  • item: (out): the next item of the iterator

gboolean wp_iterator_fold(WpIterator * self, WpIteratorFoldFunc func, GValue * ret, gpointer data)

Fold a function over the items of the iterator.

Return
TRUE if all the items were processed, FALSE otherwise.
Parameters
  • self: the iterator
  • func: (scope call): the fold function
  • ret: (inout): the accumulator data
  • data: (closure): the user data

gboolean wp_iterator_foreach(WpIterator * self, WpIteratorForeachFunc func, gpointer data)

Iterates over all items of the iterator calling a function.

Return
TRUE if all the items were processed, FALSE otherwise.
Parameters
  • self: the iterator
  • func: (scope call): the foreach function
  • data: (closure): the user data

WpIterator* wp_iterator_new_ptr_array(GPtrArray * items, GType item_type)

Creates an iterator from a pointer array.

Return
(transfer full): a new iterator that iterates over items
Parameters
  • items: (element-type gpointer) (transfer full): the items to iterate over
  • item_type: the type of each item

WP_TYPE_ITERATOR (wp_iterator_get_type ())

The WpIterator GType.

WP_ITERATOR_METHODS_VERSION 0U

The version to set to _WpIteratorMethods::version. This allows future expansion of the struct.