list2.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 
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 t##_LIST2_ITERATOR *pr##_List2_FindIter(t##_LIST2 *l, const t *p); \
00086   decl const t *pr##_List2_Contains(t##_LIST2 *l, const t *p); \
00087   decl t *pr##_List2_ForEach(t##_LIST2 *l, t##_LIST2_FOREACH, void *user_data);
00088 
00091 #define GWEN_LIST2_FUNCTION_DEFS(t, pr) \
00092   GWEN_LIST2_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
00093 
00094 
00098 #define GWEN_LIST2_FUNCTIONS(t, pr) \
00099   t##_LIST2 *pr##_List2_new() { \
00100     return (t##_LIST2*)GWEN_List_new(); \
00101   } \
00102   \
00103   void pr##_List2_free(t##_LIST2 *l) { \
00104     GWEN_List_free((GWEN_LIST*)l); \
00105   } \
00106   \
00107   t##_LIST2 *pr##_List2_dup(const t##_LIST2 *l) {\
00108     return (t##_LIST2*)GWEN_List_dup((GWEN_LIST*)l); \
00109   }\
00110   \
00111   void pr##_List2_Unshare(t##_LIST2 *l) { \
00112     GWEN_List_Unshare((GWEN_LIST*)l); \
00113   } \
00114   \
00115   void pr##_List2_Dump(t##_LIST2 *l, FILE *f, unsigned int indent) { \
00116     GWEN_List_Dump((GWEN_LIST*) l, f, indent); \
00117   } \
00118   \
00119   void pr##_List2_PushBack(t##_LIST2 *l, t *p) { \
00120     GWEN_List_PushBack((GWEN_LIST*) l, p); \
00121   } \
00122   \
00123   void pr##_List2_PushFront(t##_LIST2 *l, t *p) { \
00124     GWEN_List_PushFront((GWEN_LIST*) l, p); \
00125   } \
00126   \
00127   t *pr##_List2_GetFront(const t##_LIST2 *l) { \
00128   return (t*) GWEN_List_GetFront((GWEN_LIST*) l); \
00129   }\
00130   \
00131   t *pr##_List2_GetBack(const t##_LIST2 *l) { \
00132   return (t*) GWEN_List_GetBack((GWEN_LIST*) l); \
00133   } \
00134   \
00135   void pr##_List2_Erase(t##_LIST2 *l, t##_LIST2_ITERATOR *it) { \
00136     GWEN_List_Erase((GWEN_LIST*) l, (GWEN_LIST_ITERATOR*) it); \
00137   } \
00138   \
00139   void pr##_List2_Remove(t##_LIST2 *l, const t *p){ \
00140     GWEN_List_Remove((GWEN_LIST*) l, p); \
00141   } \
00142   \
00143   unsigned int pr##_List2_GetSize(const t##_LIST2 *l){ \
00144     return GWEN_List_GetSize((GWEN_LIST*) l); \
00145   }\
00146   int pr##_List2_IsEmpty(const t##_LIST2 *l){ \
00147     return GWEN_List_IsEmpty((GWEN_LIST*) l); \
00148   }\
00149   \
00150   void pr##_List2_PopBack(t##_LIST2 *l){ \
00151     GWEN_List_PopBack((GWEN_LIST*) l); \
00152   }\
00153   \
00154   void pr##_List2_PopFront(t##_LIST2 *l){ \
00155     GWEN_List_PopFront((GWEN_LIST*) l); \
00156   }\
00157   \
00158   void pr##_List2_Clear(t##_LIST2 *l){ \
00159     GWEN_List_Clear((GWEN_LIST*) l); \
00160   }\
00161   \
00162   \
00163   t##_LIST2_ITERATOR *pr##_List2_First(const t##_LIST2 *l) { \
00164     return (t##_LIST2_ITERATOR*) GWEN_List_First((GWEN_LIST*) l); \
00165   }\
00166   \
00167   t##_LIST2_ITERATOR *pr##_List2_Last(const t##_LIST2 *l) { \
00168     return (t##_LIST2_ITERATOR*) GWEN_List_Last((GWEN_LIST*) l); \
00169   }\
00170   \
00171   t##_LIST2_ITERATOR *pr##_List2Iterator_new(t##_LIST2 *l) { \
00172     return (t##_LIST2_ITERATOR*) GWEN_ListIterator_new((GWEN_LIST*) l); \
00173   }\
00174   \
00175   void pr##_List2Iterator_free(t##_LIST2_ITERATOR *li) {\
00176     GWEN_ListIterator_free((GWEN_LIST_ITERATOR*)li); \
00177   } \
00178   \
00179   t *pr##_List2Iterator_Previous(t##_LIST2_ITERATOR *li) { \
00180     return (t*) GWEN_ListIterator_Previous((GWEN_LIST_ITERATOR*)li); \
00181   }\
00182   \
00183   t *pr##_List2Iterator_Next(t##_LIST2_ITERATOR *li) { \
00184     return (t*) GWEN_ListIterator_Next((GWEN_LIST_ITERATOR*)li); \
00185   }\
00186   \
00187   t *pr##_List2Iterator_Data(t##_LIST2_ITERATOR *li) { \
00188     return (t*) GWEN_ListIterator_Data((GWEN_LIST_ITERATOR*)li); \
00189   } \
00190   \
00191   void pr##_List2Iterator_IncLinkCount(t##_LIST2_ITERATOR *li) { \
00192     GWEN_ListIterator_IncLinkCount((GWEN_LIST_ITERATOR*)li); \
00193   } \
00194   \
00195   unsigned int pr##_List2Iterator_GetLinkCount(const t##_LIST2_ITERATOR *li){\
00196     return GWEN_ListIterator_GetLinkCount((const GWEN_LIST_ITERATOR*)li); \
00197   } \
00198   \
00199   t##_LIST2_ITERATOR *pr##_List2_FindIter(t##_LIST2 *l, const t *p){ \
00200     return (t##_LIST2_ITERATOR*) GWEN_List_FindIter((GWEN_LIST *)l, p); \
00201   } \
00202   \
00203   const t *pr##_List2_Contains(t##_LIST2 *l, const t *p){ \
00204     return (const t*) GWEN_List_Contains((GWEN_LIST*)l, p); \
00205   } \
00206   \
00207   t *pr##_List2_ForEach(t##_LIST2 *l, t##_LIST2_FOREACH fn, void *user_data){ \
00208     t##_LIST2_ITERATOR *it; \
00209     t *el; \
00210     if (!l) return 0; \
00211     \
00212     it=pr##_List2_First(l); \
00213     if (!it) \
00214       return 0; \
00215     el=pr##_List2Iterator_Data(it); \
00216     while(el) { \
00217       el=fn(el, user_data); \
00218       if (el) { \
00219         pr##_List2Iterator_free(it); \
00220         return el; \
00221       } \
00222       el=pr##_List2Iterator_Next(it); \
00223       } \
00224     pr##_List2Iterator_free(it); \
00225     return 0; \
00226   }
00227 
00228   /*
00229    * This macro should be used in libraries with the
00230    * __declspec(dllexport) declaration as the @c decl argument.
00231    */
00232 #define GWEN_CONSTLIST2_FUNCTION_LIB_DEFS(t, pr, decl) \
00233   typedef struct t##_CONSTLIST2 t##_CONSTLIST2; \
00234   typedef struct t##_CONSTLIST2_ITERATOR t##_CONSTLIST2_ITERATOR; \
00235   typedef const t* (t##_CONSTLIST2_FOREACH)(const t *element, void *user_data); \
00236   \
00237   decl t##_CONSTLIST2 *pr##_ConstList2_new(); \
00238   decl void pr##_ConstList2_free(t##_CONSTLIST2 *l); \
00239   decl void pr##_ConstList2_PushBack(t##_CONSTLIST2 *l, const t *p); \
00240   decl void pr##_ConstList2_PushFront(t##_CONSTLIST2 *l, const t *p); \
00241   decl const t *pr##_ConstList2_GetFront(const t##_CONSTLIST2 *l); \
00242   decl const t *pr##_ConstList2_GetBack(const t##_CONSTLIST2 *l); \
00243   decl unsigned int pr##_ConstList2_GetSize(const t##_CONSTLIST2 *l); \
00244   decl int pr##_ConstList2_IsEmpty(const t##_CONSTLIST2 *l); \
00245   decl void pr##_ConstList2_PopBack(t##_CONSTLIST2 *l); \
00246   decl void pr##_ConstList2_PopFront(t##_CONSTLIST2 *l); \
00247   decl void pr##_ConstList2_Clear(t##_CONSTLIST2 *l); \
00248   decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2_First(const t##_CONSTLIST2 *l); \
00249   decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2_Last(const t##_CONSTLIST2 *l); \
00250   decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2Iterator_new(t##_CONSTLIST2 *l); \
00251   decl void pr##_ConstList2Iterator_free(t##_CONSTLIST2_ITERATOR *li); \
00252   decl const t *pr##_ConstList2Iterator_Previous(t##_CONSTLIST2_ITERATOR *li); \
00253   decl const t *pr##_ConstList2Iterator_Next(t##_CONSTLIST2_ITERATOR *li); \
00254   decl const t *pr##_ConstList2Iterator_Data(t##_CONSTLIST2_ITERATOR *li); \
00255   decl t##_CONSTLIST2_ITERATOR *pr##_ConstList2_FindIter(t##_CONSTLIST2 *l, const t *p); \
00256   decl const t *pr##_ConstList2_Contains(t##_CONSTLIST2 *l, const t *p); \
00257   decl void pr##_ConstList2_Remove(t##_CONSTLIST2 *l, const t *p); \
00258   decl const t *pr##_ConstList2_ForEach(t##_CONSTLIST2 *l, t##_CONSTLIST2_FOREACH, void *user_data);
00259 
00260   /* This macro should be used in applications, not in libraries. In
00261    * libraries please use the macro @ref
00262    * GWEN_CONSTLIST2_FUNCTION_LIB_DEFS. */
00263 #define GWEN_CONSTLIST2_FUNCTION_DEFS(t, pr) \
00264   GWEN_CONSTLIST2_FUNCTION_LIB_DEFS(t, pr, GWEN_DUMMY_EMPTY_ARG)
00265 
00266 
00267 #define GWEN_CONSTLIST2_FUNCTIONS(t, pr) \
00268   t##_CONSTLIST2 *pr##_ConstList2_new() { \
00269     return (t##_CONSTLIST2*)GWEN_ConstList_new(); \
00270   } \
00271   \
00272   void pr##_ConstList2_free(t##_CONSTLIST2 *l) { \
00273     GWEN_ConstList_free((GWEN_CONSTLIST*)l); \
00274   } \
00275   \
00276   void pr##_ConstList2_PushBack(t##_CONSTLIST2 *l, const t *p) { \
00277     GWEN_ConstList_PushBack((GWEN_CONSTLIST*) l, p); \
00278   } \
00279   \
00280   void pr##_ConstList2_PushFront(t##_CONSTLIST2 *l, const t *p) { \
00281     GWEN_ConstList_PushFront((GWEN_CONSTLIST*) l, p); \
00282   } \
00283   \
00284   const t *pr##_ConstList2_GetFront(const t##_CONSTLIST2 *l) { \
00285   return (t*) GWEN_ConstList_GetFront((GWEN_CONSTLIST*) l); \
00286   }\
00287   \
00288   const t *pr##_ConstList2_GetBack(const t##_CONSTLIST2 *l) { \
00289   return (t*) GWEN_ConstList_GetBack((GWEN_CONSTLIST*) l); \
00290   } \
00291   \
00292   \
00293   unsigned int pr##_ConstList2_GetSize(const t##_CONSTLIST2 *l){ \
00294     return GWEN_ConstList_GetSize((GWEN_CONSTLIST*) l); \
00295   }\
00296   \
00297   int pr##_ConstList2_IsEmpty(const t##_CONSTLIST2 *l){ \
00298     return GWEN_ConstList_IsEmpty((GWEN_CONSTLIST*) l); \
00299   }\
00300   \
00301   void pr##_ConstList2_PopBack(t##_CONSTLIST2 *l){ \
00302     GWEN_ConstList_PopBack((GWEN_CONSTLIST*) l); \
00303   }\
00304   \
00305   void pr##_ConstList2_PopFront(t##_CONSTLIST2 *l){ \
00306     GWEN_ConstList_PopFront((GWEN_CONSTLIST*) l); \
00307   }\
00308   \
00309   void pr##_ConstList2_Clear(t##_CONSTLIST2 *l){ \
00310     GWEN_ConstList_Clear((GWEN_CONSTLIST*) l); \
00311   }\
00312   \
00313   \
00314   t##_CONSTLIST2_ITERATOR *pr##_ConstList2_First(const t##_CONSTLIST2 *l) { \
00315     return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstList_First((GWEN_CONSTLIST*) l); \
00316   }\
00317   \
00318   t##_CONSTLIST2_ITERATOR *pr##_ConstList2_Last(const t##_CONSTLIST2 *l) { \
00319     return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstList_Last((GWEN_CONSTLIST*) l); \
00320   }\
00321   \
00322   t##_CONSTLIST2_ITERATOR *pr##_ConstList2Iterator_new(t##_CONSTLIST2 *l) { \
00323     return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstListIterator_new((GWEN_CONSTLIST*) l); \
00324   }\
00325   \
00326   void pr##_ConstList2Iterator_free(t##_CONSTLIST2_ITERATOR *li) {\
00327     GWEN_ConstListIterator_free((GWEN_CONSTLIST_ITERATOR*)li); \
00328   } \
00329   \
00330   const t *pr##_ConstList2Iterator_Previous(t##_CONSTLIST2_ITERATOR *li) { \
00331     return (t*) GWEN_ConstListIterator_Previous((GWEN_CONSTLIST_ITERATOR*)li); \
00332   }\
00333   \
00334   const t *pr##_ConstList2Iterator_Next(t##_CONSTLIST2_ITERATOR *li) { \
00335     return (t*) GWEN_ConstListIterator_Next((GWEN_CONSTLIST_ITERATOR*)li); \
00336   }\
00337   \
00338   const t *pr##_ConstList2Iterator_Data(t##_CONSTLIST2_ITERATOR *li) { \
00339     return (t*) GWEN_ConstListIterator_Data((GWEN_CONSTLIST_ITERATOR*)li); \
00340   } \
00341   \
00342   t##_CONSTLIST2_ITERATOR *pr##_ConstList2_FindIter(t##_CONSTLIST2 *l, const t *p){ \
00343     return (t##_CONSTLIST2_ITERATOR*) GWEN_ConstList_FindIter((GWEN_CONSTLIST *)l, p); \
00344   } \
00345   \
00346   const t *pr##_ConstList2_Contains(t##_CONSTLIST2 *l, const t *p){ \
00347     return (const t*) GWEN_ConstList_Contains((GWEN_CONSTLIST*)l, p); \
00348   } \
00349   \
00350   void pr##_ConstList2_Remove(t##_CONSTLIST2 *l, const t *p){ \
00351     GWEN_ConstList_Remove((GWEN_CONSTLIST*) l, p); \
00352   } \
00353   \
00354   const t *pr##_ConstList2_ForEach(t##_CONSTLIST2 *l, t##_CONSTLIST2_FOREACH fn, void *user_data){ \
00355     t##_CONSTLIST2_ITERATOR *it; \
00356     const t *el; \
00357     if (!l) return 0; \
00358     \
00359     it=pr##_ConstList2_First(l); \
00360     if (!it) \
00361       return 0; \
00362     el=pr##_ConstList2Iterator_Data(it); \
00363     while(el) { \
00364       el=fn(el, user_data); \
00365       if (el) { \
00366         pr##_ConstList2Iterator_free(it); \
00367         return el; \
00368       } \
00369       el=pr##_ConstList2Iterator_Next(it); \
00370       } \
00371     pr##_ConstList2Iterator_free(it); \
00372     return 0; \
00373   }
00374 
00375 
00376 #ifdef __cplusplus
00377 }
00378 #endif
00379 
00380 
00381 #endif /* GWENHYWFAR_LIST2_H */
00382 
00383 
00384 

Generated on Wed Sep 3 15:21:58 2008 for gwenhywfar by  doxygen 1.5.6