gwenhywfar
4.3.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 00028 00029 #include <gwenhywfar/gwenhywfarapi.h> 00030 #include <gwenhywfar/types.h> 00031 #include <assert.h> 00032 00033 00034 #ifndef GWEN_DUMMY_EMPTY_ARG 00035 00037 # define GWEN_DUMMY_EMPTY_ARG 00038 #endif 00039 00040 00041 #ifndef GWEN_LIST1_H 00042 #define GWEN_LIST1_H 00043 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif 00048 00049 00149 00150 00158 typedef struct GWEN_LIST1 GWEN_LIST1; 00159 typedef struct GWEN_LIST1_ELEMENT GWEN_LIST1_ELEMENT; 00160 00161 typedef int GWENHYWFAR_CB (*GWEN_LIST1_SORT_FN)(const void *a, const void *b, int ascending); 00162 00163 00165 GWENHYWFAR_API 00166 GWEN_LIST1 *GWEN_List1_new(void); 00167 00171 GWENHYWFAR_API 00172 void GWEN_List1_free(GWEN_LIST1 *l); 00173 00177 GWENHYWFAR_API 00178 int GWEN_List1_GetCount(const GWEN_LIST1 *l); 00179 00182 GWENHYWFAR_API 00183 int GWEN_List1_Add(GWEN_LIST1 *l, GWEN_LIST1_ELEMENT *el); 00184 00188 GWENHYWFAR_API 00189 int GWEN_List1_Insert(GWEN_LIST1 *l, GWEN_LIST1_ELEMENT *el); 00190 00195 GWENHYWFAR_API 00196 int GWEN_List1_Del(GWEN_LIST1_ELEMENT *el); 00197 00201 GWENHYWFAR_API 00202 int GWEN_List1_AddList(GWEN_LIST1 *dest, GWEN_LIST1 *l); 00203 00205 GWENHYWFAR_API 00206 void *GWEN_List1_GetFirst(const GWEN_LIST1 *l); 00207 00209 GWENHYWFAR_API 00210 void *GWEN_List1_GetLast(const GWEN_LIST1 *l); 00211 00212 GWENHYWFAR_API 00213 GWEN_LIST1_SORT_FN GWEN_List1_SetSortFn(GWEN_LIST1 *l, GWEN_LIST1_SORT_FN fn); 00214 00215 GWENHYWFAR_API 00216 void GWEN_List1_Sort(GWEN_LIST1 *l, int ascending); 00217 00218 00219 00221 GWENHYWFAR_API 00222 GWEN_LIST1_ELEMENT *GWEN_List1Element_new(void *d); 00223 00225 GWENHYWFAR_API 00226 void GWEN_List1Element_free(GWEN_LIST1_ELEMENT *el); 00227 00230 GWENHYWFAR_API 00231 void *GWEN_List1Element_GetData(const GWEN_LIST1_ELEMENT *el); 00232 00236 GWENHYWFAR_API 00237 void *GWEN_List1Element_GetPrevious(const GWEN_LIST1_ELEMENT *el); 00238 00242 GWENHYWFAR_API 00243 void *GWEN_List1Element_GetNext(const GWEN_LIST1_ELEMENT *el); 00244 00245 00253 00258 #define GWEN_LIST_ELEMENT(t) \ 00259 GWEN_LIST1_ELEMENT *_list1_element; 00260 00267 #define GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \ 00268 typedef GWEN_LIST1 t##_LIST; \ 00269 typedef int GWENHYWFAR_CB (*t##_LIST_SORT_FN)(const t *a, const t *b, int ascending); \ 00270 \ 00271 \ 00272 decl t* pr##_List_First(const t##_LIST *l); \ 00273 decl t* pr##_List_Last(const t##_LIST *l); \ 00274 decl t* pr##_List_Next(const t *element); \ 00275 decl t* pr##_List_Previous(const t *element); \ 00276 decl uint32_t pr##_List_GetCount(const t##_LIST *l); \ 00277 decl int pr##_List_HasElement(const t##_LIST *l, const t *element); \ 00278 decl t##_LIST_SORT_FN pr##_List_SetSortFn(t##_LIST *l, t##_LIST_SORT_FN fn); \ 00279 decl void pr##_List_Sort(t##_LIST *l, int ascending); 00280 00281 00282 #define GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) \ 00283 typedef GWEN_LIST1_ELEMENT t##_LIST_ELEMENT; \ 00284 \ 00285 decl void pr##_List_Clear(t##_LIST *l); \ 00286 decl t##_LIST* pr##_List_new(); \ 00287 decl void pr##_List_free(t##_LIST *l); \ 00288 decl int pr##_List_AddList(t##_LIST *dst, t##_LIST *l); \ 00289 decl int pr##_List_Add(t *element, t##_LIST *list); \ 00290 decl int pr##_List_Insert(t *element, t##_LIST *list); \ 00291 decl int pr##_List_Del(t *element); \ 00292 00293 00294 #define GWEN_LIST_FUNCTION_DEFS_CONST(t, pr) \ 00295 GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG) 00296 00297 #define GWEN_LIST_FUNCTION_DEFS_NOCONST(t, pr) \ 00298 GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG) 00299 00300 00349 #define GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl) \ 00350 GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \ 00351 GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) 00352 00353 00358 #define GWEN_LIST_FUNCTION_DEFS(t, pr) \ 00359 GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG) 00360 00361 00367 #define GWEN_LIST_FUNCTIONS(t, pr) \ 00368 \ 00369 int pr##_List_Add(t *element, t##_LIST *l) { \ 00370 return GWEN_List1_Add(l, element->_list1_element); \ 00371 } \ 00372 \ 00373 int pr##_List_AddList(t##_LIST *dst, t##_LIST *l) { \ 00374 return GWEN_List1_AddList(dst, l); \ 00375 } \ 00376 \ 00377 int pr##_List_Insert(t *element, t##_LIST *l) { \ 00378 return GWEN_List1_Insert(l, element->_list1_element); \ 00379 } \ 00380 \ 00381 int pr##_List_Del(t *element){ \ 00382 return GWEN_List1_Del(element->_list1_element); \ 00383 }\ 00384 \ 00385 t* pr##_List_First(const t##_LIST *l) { \ 00386 if (l) return (t*)GWEN_List1_GetFirst(l);\ 00387 else return 0; \ 00388 } \ 00389 \ 00390 t* pr##_List_Last(const t##_LIST *l) { \ 00391 if (l) return (t*) GWEN_List1_GetLast(l);\ 00392 else return 0; \ 00393 } \ 00394 \ 00395 void pr##_List_Clear(t##_LIST *l) { \ 00396 t* el; \ 00397 while( (el=GWEN_List1_GetFirst(l)) ) {\ 00398 pr##_List_Del(el);\ 00399 pr##_free(el);\ 00400 } /* while */ \ 00401 } \ 00402 \ 00403 int pr##_List_HasElement(const t##_LIST *l, const t *element) { \ 00404 const t* el; \ 00405 el=(t*)GWEN_List1_GetFirst(l); \ 00406 while(el) {\ 00407 if (el==element) \ 00408 return 1; \ 00409 el=(const t*)GWEN_List1Element_GetNext(el->_list1_element); \ 00410 } /* while */ \ 00411 return 0; \ 00412 } \ 00413 \ 00414 t##_LIST* pr##_List_new(){\ 00415 return (t##_LIST*)GWEN_List1_new(); \ 00416 }\ 00417 \ 00418 void pr##_List_free(t##_LIST *l) {\ 00419 if (l) { \ 00420 pr##_List_Clear(l);\ 00421 GWEN_List1_free(l); \ 00422 }\ 00423 } \ 00424 \ 00425 t* pr##_List_Next(const t *element) { \ 00426 return (t*)GWEN_List1Element_GetNext(element->_list1_element);\ 00427 } \ 00428 \ 00429 t* pr##_List_Previous(const t *element) { \ 00430 return (t*)GWEN_List1Element_GetPrevious(element->_list1_element);\ 00431 } \ 00432 \ 00433 uint32_t pr##_List_GetCount(const t##_LIST *l){\ 00434 return GWEN_List1_GetCount(l);\ 00435 } \ 00436 \ 00437 t##_LIST_SORT_FN pr##_List_SetSortFn(t##_LIST *l, t##_LIST_SORT_FN fn) { \ 00438 return (t##_LIST_SORT_FN) GWEN_List1_SetSortFn(l, (GWEN_LIST1_SORT_FN) fn); \ 00439 } \ 00440 \ 00441 void pr##_List_Sort(t##_LIST *l, int ascending){\ 00442 GWEN_List1_Sort(l, ascending);\ 00443 } 00444 00450 #define GWEN_LIST_INIT(t, element) \ 00451 element->_list1_element=GWEN_List1Element_new(element); 00452 00453 00459 #define GWEN_LIST_FINI(t, element) \ 00460 if (element && element->_list1_element) { \ 00461 GWEN_List1Element_free(element->_list1_element); \ 00462 element->_list1_element=0; \ 00463 } 00464 00467 /* defgroup */ 00468 00469 00470 #ifdef __cplusplus 00471 } 00472 #endif 00473 00474 00475 #endif 00476 00477