gwenhywfar 4.0.3
|
00001 /*************************************************************************** 00002 $RCSfile$ 00003 ------------------- 00004 cvs : $Id$ 00005 begin : Sat Jun 28 2003 00006 copyright : (C) 2003 by Martin Preuss 00007 email : martin@libchipcard.de 00008 00009 *************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00024 * MA 02111-1307 USA * 00025 * * 00026 ***************************************************************************/ 00027 00035 #ifndef GWENHYWFAR_LIST2_H 00036 #define GWENHYWFAR_LIST2_H 00037 00038 #include <gwenhywfar/gwenhywfarapi.h> 00039 #include <gwenhywfar/types.h> 00040 #include <gwenhywfar/misc.h> 00041 #include <gwenhywfar/list.h> 00042 #include <gwenhywfar/refptr.h> 00043 #include <stdio.h> 00044 #include <stdlib.h> 00045 #include <string.h> 00046 #include <assert.h> 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00052 /* 00053 * This macro should be used in libraries with the 00054 * __declspec(dllexport) declaration as the @c decl argument. 00055 */ 00056 #define GWEN_LIST2_FUNCTION_LIB_DEFS(t, pr, decl) \ 00057 typedef struct t##_LIST2 t##_LIST2; \ 00058 typedef struct t##_LIST2_ITERATOR t##_LIST2_ITERATOR; \ 00059 typedef t* (t##_LIST2_FOREACH)(t *element, void *user_data); \ 00060 \ 00061 decl t##_LIST2 *pr##_List2_new(); \ 00062 decl void pr##_List2_free(t##_LIST2 *l); \ 00063 decl t##_LIST2 *pr##_List2_dup(const t##_LIST2 *l); \ 00064 decl void pr##_List2_Unshare(t##_LIST2 *l); \ 00065 decl void pr##_List2_Dump(t##_LIST2 *l, FILE *f, unsigned int indent); \ 00066 decl void pr##_List2_PushBack(t##_LIST2 *l, t *p); \ 00067 decl void pr##_List2_PushFront(t##_LIST2 *l, t *p); \ 00068 decl t *pr##_List2_GetFront(const t##_LIST2 *l); \ 00069 decl t *pr##_List2_GetBack(const t##_LIST2 *l); \ 00070 decl void pr##_List2_Erase(t##_LIST2 *l, t##_LIST2_ITERATOR *it); \ 00071 decl void pr##_List2_Remove(t##_LIST2 *l, const t *p); \ 00072 decl unsigned int pr##_List2_GetSize(const t##_LIST2 *l); \ 00073 decl int pr##_List2_IsEmpty(const t##_LIST2 *l); \ 00074 decl void pr##_List2_PopBack(t##_LIST2 *l); \ 00075 decl void pr##_List2_PopFront(t##_LIST2 *l); \ 00076 decl void pr##_List2_Clear(t##_LIST2 *l); \ 00077 decl t##_LIST2_ITERATOR *pr##_List2_First(const t##_LIST2 *l); \ 00078 decl t##_LIST2_ITERATOR *pr##_List2_Last(const t##_LIST2 *l); \ 00079 decl t##_LIST2_ITERATOR *pr##_List2Iterator_new(t##_LIST2 *l); \ 00080 decl void pr##_List2Iterator_free(t##_LIST2_ITERATOR *li); \ 00081 decl t *pr##_List2Iterator_Previous(t##_LIST2_ITERATOR *li); \ 00082 decl t *pr##_List2Iterator_Next(t##_LIST2_ITERATOR *li); \ 00083 decl t *pr##_List2Iterator_Data(t##_LIST2_ITERATOR *li); \ 00084 decl void pr##_List2Iterator_IncLinkCount(t##_LIST2_ITERATOR *li); \ 00085 decl unsigned int pr##_List2Iterator_GetLinkCount(const t##_LIST2_ITERATOR *li); \ 00086 decl t##_LIST2_ITERATOR *pr##_List2_FindIter(t##_LIST2 *l, const t *p); \ 00087 decl const t *pr##_List2_Contains(t##_LIST2 *l, const t *p); \ 00088 decl t *pr##_List2_ForEach(t##_LIST2 *l, t##_LIST2_FOREACH, void *user_data); 00089 00092 #define GWEN_LIST2_FUNCTION_DEFS(t, pr) \ 00093 GWEN_LIST2_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG) 00094 00095 00099 #define GWEN_LIST2_FUNCTIONS(t, pr) \ 00100 t##_LIST2 *pr##_List2_new() { \ 00101 return (t##_LIST2*)GWEN_List_new(); \ 00102 } \ 00103 \ 00104 void pr##_List2_free(t##_LIST2 *l) { \ 00105 GWEN_List_free((GWEN_LIST*)l); \ 00106 } \ 00107 \ 00108 t##_LIST2 *pr##_List2_dup(const t##_LIST2 *l) {\ 00109 return (t##_LIST2*)GWEN_List_dup((const GWEN_LIST*)l); \ 00110 }\ 00111 \ 00112 void pr##_List2_Unshare(t##_LIST2 *l) { \ 00113 GWEN_List_Unshare((GWEN_LIST*)l); \ 00114 } \ 00115 \ 00116 void pr##_List2_Dump(t##_LIST2 *l, FILE *f, unsigned int indent) { \ 00117 GWEN_List_Dump((GWEN_LIST*) l, f, indent); \ 00118 } \ 00119 \ 00120 void pr##_List2_PushBack(t##_LIST2 *l, t *p) { \ 00121 GWEN_List_PushBack((GWEN_LIST*) l, p); \ 00122 } \ 00123 \ 00124 void pr##_List2_PushFront(t##_LIST2 *l, t *p) { \ 00125 GWEN_List_PushFront((GWEN_LIST*) l, p); \ 00126 } \ 00127 \ 00128 t *pr##_List2_GetFront(const t##_LIST2 *l) { \ 00129 return (t*) GWEN_List_GetFront((const GWEN_LIST*) l); \ 00130 }\ 00131 \ 00132 t *pr##_List2_GetBack(const t##_LIST2 *l) { \ 00133 return (t*) GWEN_List_GetBack((const GWEN_LIST*) l); \ 00134 } \ 00135 \ 00136 void pr##_List2_Erase(t##_LIST2 *l, t##_LIST2_ITERATOR *it) { \ 00137 GWEN_List_Erase((GWEN_LIST*) l, (GWEN_LIST_ITERATOR*) it); \ 00138 } \ 00139 \ 00140 void pr##_List2_Remove(t##_LIST2 *l, const t *p){ \ 00141 GWEN_List_Remove((GWEN_LIST*) l, p); \ 00142 } \ 00143 \ 00144 unsigned int pr##_List2_GetSize(const t##_LIST2 *l){ \ 00145 return GWEN_List_GetSize((const GWEN_LIST*) l); \ 00146 }\ 00147 \ 00148 int pr##_List2_IsEmpty(const t##_LIST2 *l){ \ 00149 return GWEN_List_IsEmpty((const GWEN_LIST*) l); \ 00150 }\ 00151 \ 00152 void pr##_List2_PopBack(t##_LIST2 *l){ \ 00153 GWEN_List_PopBack((GWEN_LIST*) l); \ 00154 }\ 00155 \ 00156 void pr##_List2_PopFront(t##_LIST2 *l){ \ 00157 GWEN_List_PopFront((GWEN_LIST*) l); \ 00158 }\ 00159 \ 00160 void pr##_List2_Clear(t##_LIST2 *l){ \ 00161 GWEN_List_Clear((GWEN_LIST*) l); \ 00162 }\ 00163 \ 00164 \ 00165 t##_LIST2_ITERATOR *pr##_List2_First(const t##_LIST2 *l) { \ 00166 return (t##_LIST2_ITERATOR*) GWEN_List_First((const GWEN_LIST*) l); \ 00167 }\ 00168 \ 00169 t##_LIST2_ITERATOR *pr##_List2_Last(const t##_LIST2 *l) { \ 00170 return (t##_LIST2_ITERATOR*) GWEN_List_Last((const GWEN_LIST*) l); \ 00171 }\ 00172 \ 00173 t##_LIST2_ITERATOR *pr##_List2Iterator_new(t##_LIST2 *l) { \ 00174 return (t##_LIST2_ITERATOR*) GWEN_ListIterator_new((GWEN_LIST*) l); \ 00175 }\ 00176 \ 00177 void pr##_List2Iterator_free(t##_LIST2_ITERATOR *li) {\ 00178 GWEN_ListIterator_free((GWEN_LIST_ITERATOR*)li); \ 00179 } \ 00180 \ 00181 t *pr##_List2Iterator_Previous(t##_LIST2_ITERATOR *li) { \ 00182 return (t*) GWEN_ListIterator_Previous((GWEN_LIST_ITERATOR*)li); \ 00183 }\ 00184 \ 00185 t *pr##_List2Iterator_Next(t##_LIST2_ITERATOR *li) { \ 00186 return (t*) GWEN_ListIterator_Next((GWEN_LIST_ITERATOR*)li); \ 00187 }\ 00188 \ 00189 t *pr##_List2Iterator_Data(t##_LIST2_ITERATOR *li) { \ 00190 return (t*) GWEN_ListIterator_Data((GWEN_LIST_ITERATOR*)li); \ 00191 } \ 00192 \ 00193 void pr##_List2Iterator_IncLinkCount(t##_LIST2_ITERATOR *li) { \ 00194 GWEN_ListIterator_IncLinkCount((GWEN_LIST_ITERATOR*)li); \ 00195 } \ 00196 \ 00197 unsigned int pr##_List2Iterator_GetLinkCount(const t##_LIST2_ITERATOR *li){\ 00198 return GWEN_ListIterator_GetLinkCount((const GWEN_LIST_ITERATOR*)li); \ 00199 } \ 00200 \ 00201 t##_LIST2_ITERATOR *pr##_List2_FindIter(t##_LIST2 *l, const t *p){ \ 00202 return (t##_LIST2_ITERATOR*) GWEN_List_FindIter((GWEN_LIST *)l, p); \ 00203 } \ 00204 \ 00205 const t *pr##_List2_Contains(t##_LIST2 *l, const t *p){ \ 00206 return (const t*) GWEN_List_Contains((GWEN_LIST*)l, p); \ 00207 } \ 00208 \ 00209 t *pr##_List2_ForEach(t##_LIST2 *l, t##_LIST2_FOREACH fn, void *user_data){ \ 00210 t##_LIST2_ITERATOR *it; \ 00211 t *el; \ 00212 if (!l) return 0; \ 00213 \ 00214 it=pr##_List2_First(l); \ 00215 if (!it) \ 00216 return 0; \ 00217 el=pr##_List2Iterator_Data(it); \ 00218 while(el) { \ 00219 el=fn(el, user_data); \ 00220 if (el) { \ 00221 pr##_List2Iterator_free(it); \ 00222 return el; \ 00223 } \ 00224 el=pr##_List2Iterator_Next(it); \ 00225 } \ 00226 pr##_List2Iterator_free(it); \ 00227 return 0; \ 00228 } 00229 00230 /* 00231 * This macro should be used in libraries with the 00232 * __declspec(dllexport) declaration as the @c decl argument. 00233 */ 00234 #define GWEN_CONSTLIST2_FUNCTION_LIB_DEFS(t, pr, decl) \ 00235 typedef struct t##_CONSTLIST2 t##_CONSTLIST2; \ 00236 typedef struct t##_CONSTLIST2_ITERATOR t##_CONSTLIST2_ITERATOR; \ 00237 typedef const t* (t##_CONSTLIST2_FOREACH)(const t *element, void *user_data); \ 00238 \ 00239 decl t##_CONSTLIST2 *pr##_ConstList2_new(); \ 00240 decl void pr##_ConstList2_free(t##_CONSTLIST2 *l); \ 00241 decl void pr##_ConstList2_PushBack(t##_CONSTLIST2 *l, const t *p); \ 00242 decl void pr##_ConstList2_PushFront(t##_CONSTLIST2 *l, const t *p); \ 00243 decl const t *pr##_ConstList2_GetFront(const t##_CONSTLIST2 *l); \ 00244 decl const t *pr##_ConstList2_GetBack(const t##_CONSTLIST2 *l); \ 00245 decl unsigned int pr##_ConstList2_GetSize(const t##_CONSTLIST2 *l); \ 00246 decl int pr##_ConstList2_IsEmpty(const t##_CONSTLIST2 *l); \ 00247 decl void pr##_ConstList2_PopBack(t##_CONSTLIST2 *l); \ 00248 decl void pr##_ConstList2_PopFront(t##_CONSTLIST2 *l); \ 00249 decl void pr##_ConstList2_Clear(t##_CONSTLIST2 *l); \ 00250 decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2_First(const t##_CONSTLIST2 *l); \ 00251 decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2_Last(const t##_CONSTLIST2 *l); \ 00252 decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2Iterator_new(t##_CONSTLIST2 *l); \ 00253 decl void pr##_ConstList2Iterator_free(t##_CONSTLIST2_ITERATOR *li); \ 00254 decl const t *pr##_ConstList2Iterator_Previous(t##_CONSTLIST2_ITERATOR *li); \ 00255 decl const t *pr##_ConstList2Iterator_Next(t##_CONSTLIST2_ITERATOR *li); \ 00256 decl const t *pr##_ConstList2Iterator_Data(t##_CONSTLIST2_ITERATOR *li); \ 00257 decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2_FindIter(t##_CONSTLIST2 *l, const t *p); \ 00258 decl const t *pr##_ConstList2_Contains(t##_CONSTLIST2 *l, const t *p); \ 00259 decl void pr##_ConstList2_Remove(t##_CONSTLIST2 *l, const t *p); \ 00260 decl const t *pr##_ConstList2_ForEach(t##_CONSTLIST2 *l, t##_CONSTLIST2_FOREACH, void *user_data); 00261 00262 /* This macro should be used in applications, not in libraries. In 00263 * libraries please use the macro @ref 00264 * GWEN_CONSTLIST2_FUNCTION_LIB_DEFS. */ 00265 #define GWEN_CONSTLIST2_FUNCTION_DEFS(t, pr) \ 00266 GWEN_CONSTLIST2_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG) 00267 00268 00269 #define GWEN_CONSTLIST2_FUNCTIONS(t, pr) \ 00270 t##_CONSTLIST2 *pr##_ConstList2_new() { \ 00271 return (t##_CONSTLIST2*)GWEN_ConstList_new(); \ 00272 } \ 00273 \ 00274 void pr##_ConstList2_free(t##_CONSTLIST2 *l) { \ 00275 GWEN_ConstList_free((GWEN_CONSTLIST*)l); \ 00276 } \ 00277 \ 00278 void pr##_ConstList2_PushBack(t##_CONSTLIST2 *l, const t *p) { \ 00279 GWEN_ConstList_PushBack((GWEN_CONSTLIST*) l, p); \ 00280 } \ 00281 \ 00282 void pr##_ConstList2_PushFront(t##_CONSTLIST2 *l, const t *p) { \ 00283 GWEN_ConstList_PushFront((GWEN_CONSTLIST*) l, p); \ 00284 } \ 00285 \ 00286 const t *pr##_ConstList2_GetFront(const t##_CONSTLIST2 *l) { \ 00287 return (t*) GWEN_ConstList_GetFront((const GWEN_CONSTLIST*) l); \ 00288 }\ 00289 \ 00290 const t *pr##_ConstList2_GetBack(const t##_CONSTLIST2 *l) { \ 00291 return (t*) GWEN_ConstList_GetBack((const GWEN_CONSTLIST*) l); \ 00292 } \ 00293 \ 00294 \ 00295 unsigned int pr##_ConstList2_GetSize(const t##_CONSTLIST2 *l){ \ 00296 return GWEN_ConstList_GetSize((const GWEN_CONSTLIST*) l); \ 00297 }\ 00298 \ 00299 int pr##_ConstList2_IsEmpty(const t##_CONSTLIST2 *l){ \ 00300 return GWEN_ConstList_IsEmpty((const GWEN_CONSTLIST*) l); \ 00301 }\ 00302 \ 00303 void pr##_ConstList2_PopBack(t##_CONSTLIST2 *l){ \ 00304 GWEN_ConstList_PopBack((GWEN_CONSTLIST*) l); \ 00305 }\ 00306 \ 00307 void pr##_ConstList2_PopFront(t##_CONSTLIST2 *l){ \ 00308 GWEN_ConstList_PopFront((GWEN_CONSTLIST*) l); \ 00309 }\ 00310 \ 00311 void pr##_ConstList2_Clear(t##_CONSTLIST2 *l){ \ 00312 GWEN_ConstList_Clear((GWEN_CONSTLIST*) l); \ 00313 }\ 00314 \ 00315 \ 00316 t##_CONSTLIST2_ITERATOR *pr##_ConstList2_First(const t##_CONSTLIST2 *l) { \ 00317 return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstList_First((const GWEN_CONSTLIST*) l); \ 00318 }\ 00319 \ 00320 t##_CONSTLIST2_ITERATOR *pr##_ConstList2_Last(const t##_CONSTLIST2 *l) { \ 00321 return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstList_Last((const GWEN_CONSTLIST*) l); \ 00322 }\ 00323 \ 00324 t##_CONSTLIST2_ITERATOR *pr##_ConstList2Iterator_new(t##_CONSTLIST2 *l) { \ 00325 return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstListIterator_new((GWEN_CONSTLIST*) l); \ 00326 }\ 00327 \ 00328 void pr##_ConstList2Iterator_free(t##_CONSTLIST2_ITERATOR *li) {\ 00329 GWEN_ConstListIterator_free((GWEN_CONSTLIST_ITERATOR*)li); \ 00330 } \ 00331 \ 00332 const t *pr##_ConstList2Iterator_Previous(t##_CONSTLIST2_ITERATOR *li) { \ 00333 return (t*) GWEN_ConstListIterator_Previous((GWEN_CONSTLIST_ITERATOR*)li); \ 00334 }\ 00335 \ 00336 const t *pr##_ConstList2Iterator_Next(t##_CONSTLIST2_ITERATOR *li) { \ 00337 return (t*) GWEN_ConstListIterator_Next((GWEN_CONSTLIST_ITERATOR*)li); \ 00338 }\ 00339 \ 00340 const t *pr##_ConstList2Iterator_Data(t##_CONSTLIST2_ITERATOR *li) { \ 00341 return (t*) GWEN_ConstListIterator_Data((GWEN_CONSTLIST_ITERATOR*)li); \ 00342 } \ 00343 \ 00344 t##_CONSTLIST2_ITERATOR *pr##_ConstList2_FindIter(t##_CONSTLIST2 *l, const t *p){ \ 00345 return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstList_FindIter((GWEN_CONSTLIST *)l, p); \ 00346 } \ 00347 \ 00348 const t *pr##_ConstList2_Contains(t##_CONSTLIST2 *l, const t *p){ \ 00349 return (const t*) GWEN_ConstList_Contains((GWEN_CONSTLIST*)l, p); \ 00350 } \ 00351 \ 00352 void pr##_ConstList2_Remove(t##_CONSTLIST2 *l, const t *p){ \ 00353 GWEN_ConstList_Remove((GWEN_CONSTLIST*) l, p); \ 00354 } \ 00355 \ 00356 const t *pr##_ConstList2_ForEach(t##_CONSTLIST2 *l, t##_CONSTLIST2_FOREACH fn, void *user_data){ \ 00357 t##_CONSTLIST2_ITERATOR *it; \ 00358 const t *el; \ 00359 if (!l) return 0; \ 00360 \ 00361 it=pr##_ConstList2_First(l); \ 00362 if (!it) \ 00363 return 0; \ 00364 el=pr##_ConstList2Iterator_Data(it); \ 00365 while(el) { \ 00366 el=fn(el, user_data); \ 00367 if (el) { \ 00368 pr##_ConstList2Iterator_free(it); \ 00369 return el; \ 00370 } \ 00371 el=pr##_ConstList2Iterator_Next(it); \ 00372 } \ 00373 pr##_ConstList2Iterator_free(it); \ 00374 return 0; \ 00375 } 00376 00377 00378 #ifdef __cplusplus 00379 } 00380 #endif 00381 00382 00383 #endif /* GWENHYWFAR_LIST2_H */ 00384 00385 00386