list1.h

Go to the documentation of this file.
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 
00163 GWENHYWFAR_API
00164 GWEN_LIST1 *GWEN_List1_new();
00165 
00169 GWENHYWFAR_API
00170 void GWEN_List1_free(GWEN_LIST1 *l);
00171 
00175 GWENHYWFAR_API
00176 int GWEN_List1_GetCount(const GWEN_LIST1 *l);
00177 
00180 GWENHYWFAR_API
00181 int GWEN_List1_Add(GWEN_LIST1 *l, GWEN_LIST1_ELEMENT *el);
00182 
00186 GWENHYWFAR_API
00187 int GWEN_List1_Insert(GWEN_LIST1 *l, GWEN_LIST1_ELEMENT *el);
00188 
00193 GWENHYWFAR_API
00194 int GWEN_List1_Del(GWEN_LIST1_ELEMENT *el);
00195 
00199 GWENHYWFAR_API
00200 int GWEN_List1_AddList(GWEN_LIST1 *dest, GWEN_LIST1 *l);
00201 
00203 GWENHYWFAR_API
00204 void *GWEN_List1_GetFirst(const GWEN_LIST1 *l);
00205 
00207 GWENHYWFAR_API
00208 void *GWEN_List1_GetLast(const GWEN_LIST1 *l);
00209 
00210 
00211 
00213 GWENHYWFAR_API
00214 GWEN_LIST1_ELEMENT *GWEN_List1Element_new(void *d);
00215 
00217 GWENHYWFAR_API
00218 void GWEN_List1Element_free(GWEN_LIST1_ELEMENT *el);
00219 
00222 GWENHYWFAR_API
00223 void *GWEN_List1Element_GetData(const GWEN_LIST1_ELEMENT *el);
00224 
00228 GWENHYWFAR_API
00229 void *GWEN_List1Element_GetPrevious(const GWEN_LIST1_ELEMENT *el);
00230 
00234 GWENHYWFAR_API
00235 void *GWEN_List1Element_GetNext(const GWEN_LIST1_ELEMENT *el);
00236 
00244 
00249 #define GWEN_LIST_ELEMENT(t) \
00250 GWEN_LIST1_ELEMENT *_list1_element;
00251 
00258 #define GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
00259   typedef GWEN_LIST1 t##_LIST; \
00260   \
00261   decl t* pr##_List_First(const t##_LIST *l); \
00262   decl t* pr##_List_Last(const t##_LIST *l); \
00263   decl t* pr##_List_Next(const t *element); \
00264   decl t* pr##_List_Previous(const t *element); \
00265   decl uint32_t pr##_List_GetCount(const t##_LIST *l); \
00266   decl int pr##_List_HasElement(const t##_LIST *l, const t *element);
00267 
00268 
00269 #define GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) \
00270   typedef GWEN_LIST1_ELEMENT t##_LIST_ELEMENT; \
00271   \
00272   decl void pr##_List_Clear(t##_LIST *l); \
00273   decl t##_LIST* pr##_List_new(); \
00274   decl void pr##_List_free(t##_LIST *l); \
00275   decl int pr##_List_AddList(t##_LIST *dst, t##_LIST *l); \
00276   decl int pr##_List_Add(t *element, t##_LIST *list); \
00277   decl int pr##_List_Insert(t *element, t##_LIST *list); \
00278   decl int pr##_List_Del(t *element); \
00279 
00280 
00281 #define GWEN_LIST_FUNCTION_DEFS_CONST(t, pr) \
00282   GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
00283 
00284 #define GWEN_LIST_FUNCTION_DEFS_NOCONST(t, pr) \
00285   GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
00286 
00287 
00335 #define GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl) \
00336   GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
00337   GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl)
00338 
00339 
00344 #define GWEN_LIST_FUNCTION_DEFS(t, pr) \
00345   GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
00346 
00347 
00353 #define GWEN_LIST_FUNCTIONS(t, pr) \
00354   \
00355   int pr##_List_Add(t *element, t##_LIST *l) { \
00356     assert(element); \
00357     assert(element->_list1_element);\
00358     return GWEN_List1_Add(l, element->_list1_element); \
00359   } \
00360   \
00361   int pr##_List_AddList(t##_LIST *dst, t##_LIST *l) { \
00362     return GWEN_List1_AddList(dst, l); \
00363   } \
00364   \
00365   int pr##_List_Insert(t *element, t##_LIST *l) { \
00366     assert(element); \
00367     assert(element->_list1_element);\
00368     return GWEN_List1_Insert(l, element->_list1_element); \
00369   } \
00370   \
00371   int pr##_List_Del(t *element){ \
00372     assert(element); \
00373     assert(element->_list1_element);\
00374     return GWEN_List1_Del(element->_list1_element); \
00375   }\
00376   \
00377   t* pr##_List_First(const t##_LIST *l) { \
00378     if (l) return (t*)GWEN_List1_GetFirst(l);\
00379     else return 0; \
00380   } \
00381   \
00382   t* pr##_List_Last(const t##_LIST *l) { \
00383     if (l) return (t*) GWEN_List1_GetLast(l);\
00384     else return 0; \
00385   } \
00386   \
00387   void pr##_List_Clear(t##_LIST *l) { \
00388     t* el; \
00389     while( (el=GWEN_List1_GetFirst(l)) ) {\
00390       pr##_List_Del(el);\
00391       pr##_free(el);\
00392     } /* while */ \
00393   } \
00394   \
00395   int pr##_List_HasElement(const t##_LIST *l, const t *element) { \
00396     const t* el; \
00397     el=(t*)GWEN_List1_GetFirst(l); \
00398     while(el) {\
00399       if (el==element) \
00400         return 1; \
00401       el=(const t*)GWEN_List1Element_GetNext(element->_list1_element); \
00402     } /* while */ \
00403     return 0; \
00404   } \
00405   \
00406   t##_LIST* pr##_List_new(){\
00407     return (t##_LIST*)GWEN_List1_new(); \
00408   }\
00409   \
00410   void pr##_List_free(t##_LIST *l) {\
00411     if (l) { \
00412       pr##_List_Clear(l);\
00413       GWEN_List1_free(l); \
00414     }\
00415   } \
00416   \
00417   t* pr##_List_Next(const t *element) { \
00418     assert(element); \
00419     assert(element->_list1_element);\
00420     return (t*)GWEN_List1Element_GetNext(element->_list1_element);\
00421   } \
00422   \
00423   t* pr##_List_Previous(const t *element) { \
00424     assert(element); \
00425     assert(element->_list1_element);\
00426     return (t*)GWEN_List1Element_GetPrevious(element->_list1_element);\
00427   } \
00428   \
00429   uint32_t pr##_List_GetCount(const t##_LIST *l){\
00430     return GWEN_List1_GetCount(l);\
00431   }
00432 
00433 
00434 
00440 #define GWEN_LIST_INIT(t, element) \
00441   element->_list1_element=GWEN_List1Element_new(element);
00442 
00443 
00449 #define GWEN_LIST_FINI(t, element) \
00450   if (element && element->_list1_element) { \
00451     GWEN_List1Element_free(element->_list1_element); \
00452     element->_list1_element=0; \
00453   }
00454 
00457  /* defgroup */
00458 
00459 
00460 #ifdef __cplusplus
00461 }
00462 #endif
00463 
00464 
00465 #endif
00466 
00467 

Generated on Wed Jul 9 13:12:28 2008 for gwenhywfar by  doxygen 1.5.6