gwenhywfar  4.13.1
list1.h
Go to the documentation of this file.
1 /***************************************************************************
2  $RCSfile$
3  -------------------
4  cvs : $Id$
5  begin : Sat Jun 28 2003
6  copyright : (C) 2003 by Martin Preuss
7  email : martin@libchipcard.de
8 
9  ***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
24  * MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 
30 #include <gwenhywfar/types.h>
31 #include <assert.h>
32 
33 
34 #ifndef GWEN_DUMMY_EMPTY_ARG
35 
37 # define GWEN_DUMMY_EMPTY_ARG
38 #endif
39 
40 
41 #ifndef GWEN_LIST1_H
42 #define GWEN_LIST1_H
43 
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 
149 
150 
158 typedef struct GWEN_LIST1 GWEN_LIST1;
160 
161 typedef int GWENHYWFAR_CB (*GWEN_LIST1_SORT_FN)(const void *a, const void *b, int ascending);
162 
163 
167 
172 void GWEN_List1_free(GWEN_LIST1 *l);
173 
178 int GWEN_List1_GetCount(const GWEN_LIST1 *l);
179 
184 
190 
197 
203 
206 void *GWEN_List1_GetFirst(const GWEN_LIST1 *l);
207 
210 void *GWEN_List1_GetLast(const GWEN_LIST1 *l);
211 
214 
216 void GWEN_List1_Sort(GWEN_LIST1 *l, int ascending);
217 
218 
219 
223 
227 
232 
238 
244 
245 
253 
258 #define GWEN_LIST_ELEMENT(t) \
259 GWEN_LIST1_ELEMENT *_list1_element;
260 
267 #define GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
268  typedef GWEN_LIST1 t##_LIST; \
269  typedef int GWENHYWFAR_CB (*t##_LIST_SORT_FN)(const t *a, const t *b, int ascending); \
270  \
271  \
272  decl t* pr##_List_First(const t##_LIST *l); \
273  decl t* pr##_List_Last(const t##_LIST *l); \
274  decl t* pr##_List_Next(const t *element); \
275  decl t* pr##_List_Previous(const t *element); \
276  decl uint32_t pr##_List_GetCount(const t##_LIST *l); \
277  decl int pr##_List_HasElement(const t##_LIST *l, const t *element); \
278  decl t##_LIST_SORT_FN pr##_List_SetSortFn(t##_LIST *l, t##_LIST_SORT_FN fn); \
279  decl void pr##_List_Sort(t##_LIST *l, int ascending);
280 
281 
282 #define GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) \
283  typedef GWEN_LIST1_ELEMENT t##_LIST_ELEMENT; \
284  \
285  decl void pr##_List_Clear(t##_LIST *l); \
286  decl t##_LIST* pr##_List_new(); \
287  decl void pr##_List_free(t##_LIST *l); \
288  decl int pr##_List_AddList(t##_LIST *dst, t##_LIST *l); \
289  decl int pr##_List_Add(t *element, t##_LIST *list); \
290  decl int pr##_List_Insert(t *element, t##_LIST *list); \
291  decl int pr##_List_Del(t *element); \
292 
293 
294 #define GWEN_LIST_FUNCTION_DEFS_CONST(t, pr) \
295  GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
296 
297 #define GWEN_LIST_FUNCTION_DEFS_NOCONST(t, pr) \
298  GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
299 
300 
349 #define GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl) \
350  GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
351  GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl)
352 
353 
358 #define GWEN_LIST_FUNCTION_DEFS(t, pr) \
359  GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
360 
361 
367 #define GWEN_LIST_FUNCTIONS(t, pr) \
368  \
369  int pr##_List_Add(t *element, t##_LIST *l) { \
370  return GWEN_List1_Add(l, element->_list1_element); \
371  } \
372  \
373  int pr##_List_AddList(t##_LIST *dst, t##_LIST *l) { \
374  return GWEN_List1_AddList(dst, l); \
375  } \
376  \
377  int pr##_List_Insert(t *element, t##_LIST *l) { \
378  return GWEN_List1_Insert(l, element->_list1_element); \
379  } \
380  \
381  int pr##_List_Del(t *element){ \
382  return GWEN_List1_Del(element->_list1_element); \
383  }\
384  \
385  t* pr##_List_First(const t##_LIST *l) { \
386  if (l) return (t*)GWEN_List1_GetFirst(l);\
387  else return 0; \
388  } \
389  \
390  t* pr##_List_Last(const t##_LIST *l) { \
391  if (l) return (t*) GWEN_List1_GetLast(l);\
392  else return 0; \
393  } \
394  \
395  void pr##_List_Clear(t##_LIST *l) { \
396  t* el; \
397  while( (el=GWEN_List1_GetFirst(l)) ) {\
398  pr##_List_Del(el);\
399  pr##_free(el);\
400  } /* while */ \
401  } \
402  \
403  int pr##_List_HasElement(const t##_LIST *l, const t *element) { \
404  const t* el; \
405  el=(t*)GWEN_List1_GetFirst(l); \
406  while(el) {\
407  if (el==element) \
408  return 1; \
409  el=(const t*)GWEN_List1Element_GetNext(el->_list1_element); \
410  } /* while */ \
411  return 0; \
412  } \
413  \
414  t##_LIST* pr##_List_new(){\
415  return (t##_LIST*)GWEN_List1_new(); \
416  }\
417  \
418  void pr##_List_free(t##_LIST *l) {\
419  if (l) { \
420  pr##_List_Clear(l);\
421  GWEN_List1_free(l); \
422  }\
423  } \
424  \
425  t* pr##_List_Next(const t *element) { \
426  return (t*)GWEN_List1Element_GetNext(element->_list1_element);\
427  } \
428  \
429  t* pr##_List_Previous(const t *element) { \
430  return (t*)GWEN_List1Element_GetPrevious(element->_list1_element);\
431  } \
432  \
433  uint32_t pr##_List_GetCount(const t##_LIST *l){\
434  return GWEN_List1_GetCount(l);\
435  } \
436  \
437  t##_LIST_SORT_FN pr##_List_SetSortFn(t##_LIST *l, t##_LIST_SORT_FN fn) { \
438  return (t##_LIST_SORT_FN) GWEN_List1_SetSortFn(l, (GWEN_LIST1_SORT_FN) fn); \
439  } \
440  \
441  void pr##_List_Sort(t##_LIST *l, int ascending){\
442  GWEN_List1_Sort(l, ascending);\
443  }
444 
450 #define GWEN_LIST_INIT(t, element) \
451  element->_list1_element=GWEN_List1Element_new(element);
452 
453 
459 #define GWEN_LIST_FINI(t, element) \
460  if (element && element->_list1_element) { \
461  GWEN_List1Element_free(element->_list1_element); \
462  element->_list1_element=0; \
463  }
464 
467  /* defgroup */
468 
469 
470 #ifdef __cplusplus
471 }
472 #endif
473 
474 
475 #endif
476 
477 
GWENHYWFAR_API int GWEN_List1_Add(GWEN_LIST1 *l, GWEN_LIST1_ELEMENT *el)
int GWENHYWFAR_CB(* GWEN_LIST1_SORT_FN)(const void *a, const void *b, int ascending)
Definition: list1.h:161
GWENHYWFAR_API void * GWEN_List1_GetLast(const GWEN_LIST1 *l)
GWENHYWFAR_API void * GWEN_List1_GetFirst(const GWEN_LIST1 *l)
GWENHYWFAR_API int GWEN_List1_Del(GWEN_LIST1_ELEMENT *el)
struct GWEN_LIST1 GWEN_LIST1
Definition: list1.h:158
GWENHYWFAR_API GWEN_LIST1 * GWEN_List1_new(void)
GWENHYWFAR_API void GWEN_List1Element_free(GWEN_LIST1_ELEMENT *el)
GWENHYWFAR_API GWEN_LIST1_ELEMENT * GWEN_List1Element_new(void *d)
GWENHYWFAR_API GWEN_LIST1_SORT_FN GWEN_List1_SetSortFn(GWEN_LIST1 *l, GWEN_LIST1_SORT_FN fn)
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
GWENHYWFAR_API int GWEN_List1_AddList(GWEN_LIST1 *dest, GWEN_LIST1 *l)
GWENHYWFAR_API void GWEN_List1_free(GWEN_LIST1 *l)
GWENHYWFAR_API void * GWEN_List1Element_GetPrevious(const GWEN_LIST1_ELEMENT *el)
struct GWEN_LIST1_ELEMENT GWEN_LIST1_ELEMENT
Definition: list1.h:159
#define GWENHYWFAR_API
Definition: gwenhywfarapi.h:67
GWENHYWFAR_API void GWEN_List1_Sort(GWEN_LIST1 *l, int ascending)
GWENHYWFAR_API int GWEN_List1_Insert(GWEN_LIST1 *l, GWEN_LIST1_ELEMENT *el)
GWENHYWFAR_API void * GWEN_List1Element_GetNext(const GWEN_LIST1_ELEMENT *el)
GWENHYWFAR_API void * GWEN_List1Element_GetData(const GWEN_LIST1_ELEMENT *el)
GWENHYWFAR_API int GWEN_List1_GetCount(const GWEN_LIST1 *l)