list1.h
Go to the documentation of this file.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
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 return GWEN_List1_Add(l, element->_list1_element); \
00357 } \
00358 \
00359 int pr##_List_AddList(t##_LIST *dst, t##_LIST *l) { \
00360 return GWEN_List1_AddList(dst, l); \
00361 } \
00362 \
00363 int pr##_List_Insert(t *element, t##_LIST *l) { \
00364 return GWEN_List1_Insert(l, element->_list1_element); \
00365 } \
00366 \
00367 int pr##_List_Del(t *element){ \
00368 return GWEN_List1_Del(element->_list1_element); \
00369 }\
00370 \
00371 t* pr##_List_First(const t##_LIST *l) { \
00372 if (l) return (t*)GWEN_List1_GetFirst(l);\
00373 else return 0; \
00374 } \
00375 \
00376 t* pr##_List_Last(const t##_LIST *l) { \
00377 if (l) return (t*) GWEN_List1_GetLast(l);\
00378 else return 0; \
00379 } \
00380 \
00381 void pr##_List_Clear(t##_LIST *l) { \
00382 t* el; \
00383 while( (el=GWEN_List1_GetFirst(l)) ) {\
00384 pr##_List_Del(el);\
00385 pr##_free(el);\
00386 } \
00387 } \
00388 \
00389 int pr##_List_HasElement(const t##_LIST *l, const t *element) { \
00390 const t* el; \
00391 el=(t*)GWEN_List1_GetFirst(l); \
00392 while(el) {\
00393 if (el==element) \
00394 return 1; \
00395 el=(const t*)GWEN_List1Element_GetNext(el->_list1_element); \
00396 } \
00397 return 0; \
00398 } \
00399 \
00400 t##_LIST* pr##_List_new(){\
00401 return (t##_LIST*)GWEN_List1_new(); \
00402 }\
00403 \
00404 void pr##_List_free(t##_LIST *l) {\
00405 if (l) { \
00406 pr##_List_Clear(l);\
00407 GWEN_List1_free(l); \
00408 }\
00409 } \
00410 \
00411 t* pr##_List_Next(const t *element) { \
00412 return (t*)GWEN_List1Element_GetNext(element->_list1_element);\
00413 } \
00414 \
00415 t* pr##_List_Previous(const t *element) { \
00416 return (t*)GWEN_List1Element_GetPrevious(element->_list1_element);\
00417 } \
00418 \
00419 uint32_t pr##_List_GetCount(const t##_LIST *l){\
00420 return GWEN_List1_GetCount(l);\
00421 }
00422
00423
00424
00430 #define GWEN_LIST_INIT(t, element) \
00431 element->_list1_element=GWEN_List1Element_new(element);
00432
00433
00439 #define GWEN_LIST_FINI(t, element) \
00440 if (element && element->_list1_element) { \
00441 GWEN_List1Element_free(element->_list1_element); \
00442 element->_list1_element=0; \
00443 }
00444
00447
00448
00449
00450 #ifdef __cplusplus
00451 }
00452 #endif
00453
00454
00455 #endif
00456
00457