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