list1.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  $RCSfile$
00003  -------------------
00004  cvs         : $Id: list1.h 1020 2006-03-26 17:16:05Z aquamaniac $
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 GWEN_TYPE_UINT32 pr##_List_GetCount(const t##_LIST *l);
00266 
00267 
00268 #define GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl) \
00269   typedef GWEN_LIST1_ELEMENT t##_LIST_ELEMENT; \
00270   \
00271   decl void pr##_List_Clear(t##_LIST *l); \
00272   decl t##_LIST* pr##_List_new(); \
00273   decl void pr##_List_free(t##_LIST *l); \
00274   decl int pr##_List_AddList(t##_LIST *dst, t##_LIST *l); \
00275   decl int pr##_List_Add(t *element, t##_LIST *list); \
00276   decl int pr##_List_Insert(t *element, t##_LIST *list); \
00277   decl int pr##_List_Del(t *element); \
00278 
00279 
00280 #define GWEN_LIST_FUNCTION_DEFS_CONST(t, pr) \
00281   GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
00282 
00283 #define GWEN_LIST_FUNCTION_DEFS_NOCONST(t, pr) \
00284   GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, GWEN_DUMMY_EMPTY_ARG)
00285 
00286 
00334 #define GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, decl) \
00335   GWEN_LIST_FUNCTION_LIB_DEFS_CONST(t, pr, decl) \
00336   GWEN_LIST_FUNCTION_LIB_DEFS_NOCONST(t, pr, decl)
00337 
00338 
00343 #define GWEN_LIST_FUNCTION_DEFS(t, pr) \
00344   GWEN_LIST_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
00345 
00346 
00352 #define GWEN_LIST_FUNCTIONS(t, pr) \
00353   \
00354   int pr##_List_Add(t *element, t##_LIST *l) { \
00355     assert(element); \
00356     assert(element->_list1_element);\
00357     return GWEN_List1_Add(l, element->_list1_element); \
00358   } \
00359   \
00360   int pr##_List_AddList(t##_LIST *dst, t##_LIST *l) { \
00361     return GWEN_List1_AddList(dst, l); \
00362   } \
00363   \
00364   int pr##_List_Insert(t *element, t##_LIST *l) { \
00365     assert(element); \
00366     assert(element->_list1_element);\
00367     return GWEN_List1_Insert(l, element->_list1_element); \
00368   } \
00369   \
00370   int pr##_List_Del(t *element){ \
00371     assert(element); \
00372     assert(element->_list1_element);\
00373     return GWEN_List1_Del(element->_list1_element); \
00374   }\
00375   \
00376   t* pr##_List_First(const t##_LIST *l) { \
00377     if (l) return (t*)GWEN_List1_GetFirst(l);\
00378     else return 0; \
00379   } \
00380   \
00381   t* pr##_List_Last(const t##_LIST *l) { \
00382     if (l) return (t*) GWEN_List1_GetLast(l);\
00383     else return 0; \
00384   } \
00385   \
00386   void pr##_List_Clear(t##_LIST *l) { \
00387     t* el; \
00388     while( (el=GWEN_List1_GetFirst(l)) ) {\
00389       pr##_List_Del(el);\
00390       pr##_free(el);\
00391     } /* while */ \
00392   } \
00393   \
00394   t##_LIST* pr##_List_new(){\
00395     return (t##_LIST*)GWEN_List1_new(); \
00396   }\
00397   \
00398   void pr##_List_free(t##_LIST *l) {\
00399     if (l) { \
00400       pr##_List_Clear(l);\
00401       GWEN_List1_free(l); \
00402     }\
00403   } \
00404   \
00405   t* pr##_List_Next(const t *element) { \
00406     assert(element); \
00407     assert(element->_list1_element);\
00408     return (t*)GWEN_List1Element_GetNext(element->_list1_element);\
00409   } \
00410   \
00411   t* pr##_List_Previous(const t *element) { \
00412     assert(element); \
00413     assert(element->_list1_element);\
00414     return (t*)GWEN_List1Element_GetPrevious(element->_list1_element);\
00415   } \
00416   \
00417   GWEN_TYPE_UINT32 pr##_List_GetCount(const t##_LIST *l){\
00418     return GWEN_List1_GetCount(l);\
00419   }
00420 
00421 
00422 
00428 #define GWEN_LIST_INIT(t, element) \
00429   element->_list1_element=GWEN_List1Element_new(element);
00430 
00431 
00437 #define GWEN_LIST_FINI(t, element) \
00438   if (element && element->_list1_element) { \
00439     GWEN_List1Element_free(element->_list1_element); \
00440     element->_list1_element=0; \
00441   }
00442 
00445  /* defgroup */
00446 
00447 
00448 #ifdef __cplusplus
00449 }
00450 #endif
00451 
00452 
00453 #endif
00454 
00455 

Generated on Wed Jun 21 00:59:52 2006 for gwenhywfar by  doxygen 1.4.6