list2.h

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

Generated on Tue May 1 12:56:30 2007 for gwenhywfar by  doxygen 1.5.1