1 /* 2 * libInstPatch 3 * Copyright (C) 1999-2014 Element Green <element@elementsofsound.org> 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; version 2.1 8 * of the License only. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 * 02110-1301, USA or on the web at http://www.gnu.org. 19 */ 20 #ifndef __IPATCH_ITER_H__ 21 #define __IPATCH_ITER_H__ 22 23 #include <glib.h> 24 #include <glib-object.h> 25 26 typedef struct _IpatchIter IpatchIter; 27 typedef struct _IpatchIterMethods IpatchIterMethods; 28 29 /* boxed type for IpatchIter */ 30 #define IPATCH_TYPE_ITER (ipatch_iter_get_type ()) 31 32 /* list iterator structure */ 33 struct _IpatchIter 34 { 35 /*< private >*/ 36 IpatchIterMethods *methods; /* iterator methods */ 37 gpointer data; /* method defined data */ 38 gpointer data2; /* method defined data */ 39 gpointer data3; /* method defined data */ 40 gpointer data4; /* method defined data */ 41 }; 42 43 /* iterator methods */ 44 struct _IpatchIterMethods 45 { 46 gpointer(*get)(IpatchIter *iter); /* get item method */ 47 gpointer(*next)(IpatchIter *iter); /* next item method */ 48 gpointer(*first)(IpatchIter *iter); /* first item method */ 49 gpointer(*last)(IpatchIter *iter); /* last item method */ 50 gpointer(*index)(IpatchIter *iter, int index); /* index item method */ 51 void (*insert)(IpatchIter *iter, gpointer item); /* insert item method */ 52 void (*remove)(IpatchIter *iter); /* remove current item method */ 53 int (*count)(IpatchIter *iter); /* count items method */ 54 }; 55 56 GType ipatch_iter_get_type(void); 57 IpatchIter *ipatch_iter_alloc(void); 58 void ipatch_iter_free(IpatchIter *iter); 59 IpatchIter *ipatch_iter_duplicate(IpatchIter *iter); 60 61 #define ipatch_iter_get(iter) (((iter)->methods->get)(iter)) 62 #define ipatch_iter_next(iter) (((iter)->methods->next)(iter)) 63 #define ipatch_iter_first(iter) (((iter)->methods->first)(iter)) 64 #define ipatch_iter_last(iter) (((iter)->methods->last)(iter)) 65 #define ipatch_iter_index(iter, pos) (((iter)->methods->index)(iter, pos)) 66 #define ipatch_iter_insert(iter, item) (((iter)->methods->insert)(iter, item)) 67 #define ipatch_iter_remove(iter) (((iter)->methods->remove)(iter)) 68 #define ipatch_iter_count(iter) (((iter)->methods->count)(iter)) 69 70 #define IPATCH_ITER_GSLIST_GET_LIST(iter) ((GSList **)(iter->data)) 71 #define IPATCH_ITER_GSLIST_GET_POS(iter) ((GSList *)(iter->data2)) 72 73 #define IPATCH_ITER_GSLIST_SET_LIST(iter, list) (iter->data = list) 74 #define IPATCH_ITER_GSLIST_SET_POS(iter, pos) (iter->data2 = pos) 75 76 void ipatch_iter_GSList_init(IpatchIter *iter, GSList **list); 77 gpointer ipatch_iter_GSList_get(IpatchIter *iter); 78 gpointer ipatch_iter_GSList_next(IpatchIter *iter); 79 gpointer ipatch_iter_GSList_first(IpatchIter *iter); 80 gpointer ipatch_iter_GSList_last(IpatchIter *iter); 81 gpointer ipatch_iter_GSList_index(IpatchIter *iter, int index); 82 void ipatch_iter_GSList_insert(IpatchIter *iter, gpointer item); 83 void ipatch_iter_GSList_remove(IpatchIter *iter); 84 int ipatch_iter_GSList_count(IpatchIter *iter); 85 86 #define IPATCH_ITER_GLIST_GET_LIST(iter) ((GList **)(iter->data)) 87 #define IPATCH_ITER_GLIST_GET_POS(iter) ((GList *)(iter->data2)) 88 89 #define IPATCH_ITER_GLIST_SET_LIST(iter, list) (iter->data = list) 90 #define IPATCH_ITER_GLIST_SET_POS(iter, pos) (iter->data2 = pos) 91 92 void ipatch_iter_GList_init(IpatchIter *iter, GList **list); 93 gpointer ipatch_iter_GList_get(IpatchIter *iter); 94 gpointer ipatch_iter_GList_next(IpatchIter *iter); 95 gpointer ipatch_iter_GList_first(IpatchIter *iter); 96 gpointer ipatch_iter_GList_last(IpatchIter *iter); 97 gpointer ipatch_iter_GList_index(IpatchIter *iter, int index); 98 void ipatch_iter_GList_insert(IpatchIter *iter, gpointer item); 99 void ipatch_iter_GList_remove(IpatchIter *iter); 100 int ipatch_iter_GList_count(IpatchIter *iter); 101 102 #define IPATCH_ITER_ARRAY_GET_ARRAY(iter) ((gpointer *)(iter->data)) 103 #define IPATCH_ITER_ARRAY_GET_SIZE(iter) (GPOINTER_TO_UINT (iter->data2)) 104 #define IPATCH_ITER_ARRAY_GET_POS(iter) (GPOINTER_TO_INT (iter->data3)) 105 106 #define IPATCH_ITER_ARRAY_SET_ARRAY(iter, array) (iter->data = array) 107 #define IPATCH_ITER_ARRAY_SET_SIZE(iter, size) \ 108 (iter->data2 = GUINT_TO_POINTER (size)) 109 #define IPATCH_ITER_ARRAY_SET_POS(iter, pos) \ 110 (iter->data3 = GINT_TO_POINTER (pos)) 111 112 void ipatch_iter_array_init(IpatchIter *iter, gpointer *array, guint size); 113 gpointer ipatch_iter_array_get(IpatchIter *iter); 114 gpointer ipatch_iter_array_next(IpatchIter *iter); 115 gpointer ipatch_iter_array_first(IpatchIter *iter); 116 gpointer ipatch_iter_array_last(IpatchIter *iter); 117 gpointer ipatch_iter_array_index(IpatchIter *iter, int index); 118 void ipatch_iter_array_insert(IpatchIter *iter, gpointer item); 119 void ipatch_iter_array_remove(IpatchIter *iter); 120 int ipatch_iter_array_count(IpatchIter *iter); 121 122 #endif 123