| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2020 Collabora Ltd. |
| 4 |
* @author Julian Bouzas <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __WIREPLUMBER_ITERATOR_H__ |
| 10 |
#define __WIREPLUMBER_ITERATOR_H__ |
| 11 |
|
| 12 |
#include <gio/gio.h> |
| 13 |
#include "defs.h" |
| 14 |
|
| 15 |
G_BEGIN_DECLS |
| 16 |
|
| 17 |
/*! |
| 18 |
* \brief A function to be passed to wp_iterator_fold() |
| 19 |
* \param item the item to fold |
| 20 |
* \param ret the value collecting the result |
| 21 |
* \param data data passed to wp_iterator_fold() |
| 22 |
* \returns TRUE if the fold should continue, FALSE if it should stop. |
| 23 |
* \ingroup wpiterator |
| 24 |
*/ |
| 25 |
typedef gboolean (*WpIteratorFoldFunc) (const GValue *item, GValue *ret, |
| 26 |
gpointer data); |
| 27 |
|
| 28 |
/*! |
| 29 |
* \brief A function that is called by wp_iterator_foreach(). |
| 30 |
* \param item the item |
| 31 |
* \param data the data passed to wp_iterator_foreach() |
| 32 |
* \ingroup wpiterator |
| 33 |
*/ |
| 34 |
typedef void (*WpIteratorForeachFunc) (const GValue *item, gpointer data); |
| 35 |
|
| 36 |
/*! |
| 37 |
* \brief The WpIterator GType |
| 38 |
* \ingroup wpiterator |
| 39 |
*/ |
| 40 |
#define WP_TYPE_ITERATOR (wp_iterator_get_type ()) |
| 41 |
WP_API |
| 42 |
GType wp_iterator_get_type (void); |
| 43 |
|
| 44 |
typedef struct _WpIterator WpIterator; |
| 45 |
typedef struct _WpIteratorMethods WpIteratorMethods; |
| 46 |
|
| 47 |
/*! |
| 48 |
* \brief The version to set to _WpIteratorMethods::version. |
| 49 |
* This allows future expansion of the struct |
| 50 |
* \ingroup wpiterator |
| 51 |
*/ |
| 52 |
#define WP_ITERATOR_METHODS_VERSION 0U |
| 53 |
|
| 54 |
struct _WpIteratorMethods |
| 55 |
{ |
| 56 |
guint32 version; |
| 57 |
|
| 58 |
void (*reset) (WpIterator *self); |
| 59 |
gboolean (*next) (WpIterator *self, GValue *item); |
| 60 |
gboolean (*fold) (WpIterator *self, WpIteratorFoldFunc func, |
| 61 |
GValue *ret, gpointer data); |
| 62 |
gboolean (*foreach) (WpIterator *self, WpIteratorForeachFunc func, |
| 63 |
gpointer data); |
| 64 |
void (*finalize) (WpIterator *self); |
| 65 |
}; |
| 66 |
|
| 67 |
/* ref count */ |
| 68 |
|
| 69 |
WP_API |
| 70 |
WpIterator *wp_iterator_ref (WpIterator *self); |
| 71 |
|
| 72 |
WP_API |
| 73 |
void wp_iterator_unref (WpIterator *self); |
| 74 |
|
| 75 |
/* iteration api */ |
| 76 |
|
| 77 |
WP_API |
| 78 |
void wp_iterator_reset (WpIterator *self); |
| 79 |
|
| 80 |
WP_API |
| 81 |
gboolean wp_iterator_next (WpIterator *self, GValue *item); |
| 82 |
|
| 83 |
WP_API |
| 84 |
gboolean wp_iterator_fold (WpIterator *self, WpIteratorFoldFunc func, |
| 85 |
GValue *ret, gpointer data); |
| 86 |
|
| 87 |
WP_API |
| 88 |
gboolean wp_iterator_foreach (WpIterator *self, WpIteratorForeachFunc func, |
| 89 |
gpointer data); |
| 90 |
|
| 91 |
/* constructors */ |
| 92 |
|
| 93 |
WP_API |
| 94 |
WpIterator * wp_iterator_new_ptr_array (GPtrArray * items, GType item_type); |
| 95 |
|
| 96 |
WP_API |
| 97 |
WpIterator * wp_iterator_new (const WpIteratorMethods * methods, |
| 98 |
size_t user_size); |
| 99 |
|
| 100 |
/* private */ |
| 101 |
|
| 102 |
WP_API |
| 103 |
gpointer wp_iterator_get_user_data (WpIterator * self); |
| 104 |
|
| 105 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpIterator, wp_iterator_unref) |
| 106 |
|
| 107 |
G_END_DECLS |
| 108 |
|
| 109 |
#endif |