From 6b8938cf7669ec2a3474e3c060f91e35ba65c1b9 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 9 Jun 2019 10:01:50 +0200 Subject: [PATCH] Update comments. Rename / Uniformize internal macros. --- m-array.h | 71 +++++++++++++--------- m-deque.h | 37 +++++++---- m-list.h | 179 +++++++++++++++++++++++++++++++++++------------------- 3 files changed, 186 insertions(+), 101 deletions(-) diff --git a/m-array.h b/m-array.h index bb9ad6f4..8381f258 100644 --- a/m-array.h +++ b/m-array.h @@ -30,27 +30,32 @@ /* Define a dynamic array of the given type and its associated functions. USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */ #define ARRAY_DEF(name, ...) \ - ARRAYI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ARRAYI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name,_it_t) ), \ (name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t)))) /* Define the oplist of a dynamic array given its name and its oplist. + If no oplist is given it is assumed to be M_DEFAULT_OPLIST USAGE: ARRAY_OPLIST(name[, oplist of the type]) */ #define ARRAY_OPLIST(...) \ - ARRAYI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((__VA_ARGS__, M_DEFAULT_OPLIST), \ - (__VA_ARGS__ ))) + ARRAYI_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_DEFAULT_OPLIST), \ + (__VA_ARGS__ ))) + +/********************************************************************************/ /********************************** INTERNAL ************************************/ +/********************************************************************************/ -// Deferred evaluation for the oplist definition. -#define ARRAYI_OPLIST(arg) ARRAYI_OPLIST2 arg +/* Deferred evaluation for the oplist definition, + so that all arguments are evaluated before further expansion */ +#define ARRAYI_OPLIST_P1(arg) ARRAYI_OPLIST_P2 arg /* OPLIST definition of a dynamic array */ /* FIXME: Do we want to export some methods as they are slow and are not fit to be used for building other methods (like _it_remove)? */ -#define ARRAYI_OPLIST2(name, oplist) \ +#define ARRAYI_OPLIST_P2(name, oplist) \ (INIT(M_C(name, _init)) \ ,INIT_SET(M_C(name, _init_set)) \ ,INIT_WITH(API_1(M_INIT_VAI)) \ @@ -112,15 +117,22 @@ assert (a->size == 0 || a->ptr != NULL); \ } while (0) -// Deferred evaluation for the array definition. -#define ARRAYI_DEF(arg) ARRAYI_DEF2 arg +/* Deferred evaluation for the array definition, + so that all arguments are evaluated before further expansion */ +#define ARRAYI_DEF_P1(arg) ARRAYI_DEF_P2 arg -// Internal definition. -#define ARRAYI_DEF2(name, type, oplist, array_t, array_it_t) \ +/* Internal definition: + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the array + - array_t: alias for M_C(name, _t) [ type of the array ] + - it_t: alias for M_C(name, _it_t) [ iterator of the array ] +*/ +#define ARRAYI_DEF_P2(name, type, oplist, array_t, it_t) \ \ typedef struct M_C(name, _s) { \ size_t size; /* Number of elements in the array */ \ - size_t alloc; /* Allocated size for the array */ \ + size_t alloc; /* Allocated size for the array base */ \ type *ptr; /* Pointer to the array base */ \ } array_t[1]; \ typedef struct M_C(name, _s) *M_C(name, _ptr); \ @@ -131,7 +143,7 @@ typedef struct M_C(name, _it_s) { \ size_t index; /* Index of the element */ \ const struct M_C(name, _s) *array; /* Reference of the array */ \ - } array_it_t[1]; \ + } it_t[1]; \ \ static inline void \ M_C(name, _init)(array_t v) \ @@ -437,7 +449,7 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _pop_until)(array_t v, array_it_t pos) \ + M_C(name, _pop_until)(array_t v, it_t pos) \ { \ ARRAYI_CONTRACT(v); \ assert (v == pos->array); \ @@ -602,7 +614,7 @@ } \ \ static inline void \ - M_C(name, _it)(array_it_t it, const array_t v) \ + M_C(name, _it)(it_t it, const array_t v) \ { \ ARRAYI_CONTRACT(v); \ assert (it != NULL); \ @@ -611,7 +623,7 @@ } \ \ static inline void \ - M_C(name, _it_last)(array_it_t it, const array_t v) \ + M_C(name, _it_last)(it_t it, const array_t v) \ { \ ARRAYI_CONTRACT(v); \ assert (it != NULL); \ @@ -620,7 +632,7 @@ } \ \ static inline void \ - M_C(name, _it_end)(array_it_t it, const array_t v) \ + M_C(name, _it_end)(it_t it, const array_t v) \ { \ ARRAYI_CONTRACT(v); \ assert (it != NULL); \ @@ -629,7 +641,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(array_it_t it, const array_it_t org) \ + M_C(name, _it_set)(it_t it, const it_t org) \ { \ assert (it != NULL && org != NULL); \ it->index = org->index; \ @@ -638,14 +650,14 @@ } \ \ static inline bool \ - M_C(name, _end_p)(const array_it_t it) \ + M_C(name, _end_p)(const it_t it) \ { \ assert(it != NULL && it->array != NULL); \ return it->index >= it->array->size; \ } \ \ static inline bool \ - M_C(name, _last_p)(const array_it_t it) \ + M_C(name, _last_p)(const it_t it) \ { \ assert(it != NULL && it->array != NULL); \ /* NOTE: Can not compute 'size-1' due to potential overflow \ @@ -654,22 +666,22 @@ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const array_it_t it1, \ - const array_it_t it2) \ + M_C(name, _it_equal_p)(const it_t it1, \ + const it_t it2) \ { \ assert(it1 != NULL && it2 != NULL); \ return it1->array == it2->array && it1->index == it2->index; \ } \ \ static inline void \ - M_C(name, _next)(array_it_t it) \ + M_C(name, _next)(it_t it) \ { \ assert(it != NULL && it->array != NULL); \ it->index ++; \ } \ \ static inline void \ - M_C(name, _previous)(array_it_t it) \ + M_C(name, _previous)(it_t it) \ { \ assert(it != NULL && it->array != NULL); \ /* NOTE: In the case index=0, it will be set to (unsigned) -1 \ @@ -678,28 +690,28 @@ } \ \ static inline type * \ - M_C(name, _ref)(const array_it_t it) \ + M_C(name, _ref)(const it_t it) \ { \ assert(it != NULL); \ return M_C(name, _get)(it->array, it->index); \ } \ \ static inline type const * \ - M_C(name, _cref)(const array_it_t it) \ + M_C(name, _cref)(const it_t it) \ { \ assert(it != NULL); \ return M_C(name, _cget)(it->array, it->index); \ } \ \ static inline void \ - M_C(name, _insert)(array_t a, array_it_t it, type const x) \ + M_C(name, _insert)(array_t a, it_t it, type const x) \ { \ assert (it != NULL && a == it->array); \ M_C(name, _push_at)(a, it->index + 1, x); \ } \ \ static inline void \ - M_C(name, _remove)(array_t a, array_it_t it) \ + M_C(name, _remove)(array_t a, it_t it) \ { \ assert (it != NULL && a == it->array); \ M_C(name, _pop_at)(NULL, a, it->index); \ @@ -809,6 +821,7 @@ \ ,) /* IF CMP oplist */ \ \ + \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ M_C(name, _get_str)(string_t str, array_t const array, \ @@ -817,7 +830,7 @@ STRINGI_CONTRACT(str); \ ARRAYI_CONTRACT(array); \ (append ? string_cat_str : string_set_str) (str, "["); \ - array_it_t it; \ + it_t it; \ for (M_C(name, _it)(it, array) ; \ !M_C(name, _end_p)(it); \ M_C(name, _next)(it)){ \ diff --git a/m-deque.h b/m-deque.h index edfcafa7..b06ea20f 100644 --- a/m-deque.h +++ b/m-deque.h @@ -30,22 +30,25 @@ /* Define a deque of a given type and its associated functions. USAGE: DEQUE_DEF(name, type [, oplist_of_the_type]) */ #define DEQUE_DEF(name, ...) \ - DEQUEI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t) ), \ - (name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t)))) + DEQUEI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t) ), \ + (name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t)))) /* Define the oplist of a deque of a type. USAGE: DEQUE_OPLIST(name[, oplist of the type]) */ #define DEQUE_OPLIST(...) \ - DEQUEI_OPLIST (M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((__VA_ARGS__, M_DEFAULT_OPLIST), \ - (__VA_ARGS__ ))) + DEQUEI_OPLIST_P1 (M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_DEFAULT_OPLIST), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ +#ifndef DEQUEUI_DEFAULT_SIZE #define DEQUEUI_DEFAULT_SIZE 8 +#endif +/* Define the internal contract of an deque */ #define DEQUEI_CONTRACT(d) do { \ assert ((d) != NULL); \ assert ((d)->default_size >= DEQUEUI_DEFAULT_SIZE); \ @@ -59,9 +62,19 @@ (d)->back->index - (d)->front->index == (d)->count); \ } while (0) -#define DEQUEI_DEF(arg) DEQUEI_DEF2 arg +/* Deferred evaluation for the deque definition, + so that all arguments are evaluated before further expansion */ +#define DEQUEI_DEF_P1(arg) DEQUEI_DEF_P2 arg -#define DEQUEI_DEF2(name, type, oplist, deque_t, it_t, node_t) \ +/* Internal deque definition + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the container + - deque_t: alias for M_C(name, _t) [ type of the container ] + - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - node_t: alias for M_C(name, _node_t) [ node ] + */ +#define DEQUEI_DEF_P2(name, type, oplist, deque_t, it_t, node_t) \ \ typedef struct M_C(name, _node_s) { \ ILIST_INTERFACE(M_C(name, _node_list), struct M_C(name, _node_s)); \ @@ -902,10 +915,12 @@ , /* no IN_SERIAL & INIT */ ) \ \ +/* Deferred evaluation for the oplist definition, + so that all arguments are evaluated before further expansion */ +#define DEQUEI_OPLIST_P1(arg) DEQUEI_OPLIST_P2 arg -#define DEQUEI_OPLIST(arg) DEQUEI_OPLIST2 arg - -#define DEQUEI_OPLIST2(name, oplist) \ +/* OPLIST definition of a deque */ +#define DEQUEI_OPLIST_P2(name, oplist) \ (INIT(M_C(name, _init)) \ ,INIT_SET(M_C(name, _init_set)) \ ,INIT_WITH(API_1(M_INIT_VAI)) \ diff --git a/m-list.h b/m-list.h index b905581b..205d2606 100644 --- a/m-list.h +++ b/m-list.h @@ -30,30 +30,33 @@ /* Define a singly linked list of a given type. USAGE: LIST_DEF(name, type [, oplist_of_the_type]) */ #define LIST_DEF(name, ...) \ - LISTI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name, _it_t) ), \ - (name, __VA_ARGS__, M_C(name,_t), M_C(name, _it_t) ))) + LISTI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name, _it_t) ), \ + (name, __VA_ARGS__, M_C(name,_t), M_C(name, _it_t) ))) /* Define a dual-push singly linked list of a given type. USAGE: LIST_DEF(name, type [, oplist_of_the_type]) */ #define LIST_DUAL_PUSH_DEF(name, ...) \ - LISTI_DUAL_PUSH_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name, _it_t) ), \ - (name, __VA_ARGS__, M_C(name,_t), M_C(name, _it_t) ))) + LISTI_DUAL_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), M_C(name,_t), M_C(name, _it_t) ), \ + (name, __VA_ARGS__, M_C(name,_t), M_C(name, _it_t) ))) /* Define the oplist of a list of type. USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */ #define LIST_OPLIST(...) \ - LISTI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((__VA_ARGS__, M_DEFAULT_OPLIST ), \ - (__VA_ARGS__ ))) + LISTI_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_DEFAULT_OPLIST ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ -#define LISTI_OPLIST(arg) LISTI_OPLIST2 arg +/* Deferred evaluation for the oplist definition, + so that all arguments are evaluated before further expansion */ +#define LISTI_OPLIST_P1(arg) LISTI_OPLIST_P2 arg -#define LISTI_OPLIST2(name, oplist) \ +/* OPLIST definition of a list and list_dual_push */ +#define LISTI_OPLIST_P2(name, oplist) \ (INIT(M_C(name, _init)), \ INIT_SET(M_C(name, _init_set)), \ INIT_WITH(API_1(M_INIT_VAI)), \ @@ -99,7 +102,9 @@ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) -#define LISTI_DEF(arg) LISTI_DEF2 arg +/* Deferred evaluation for the list definition, + so that all arguments are evaluated before further expansion */ +#define LISTI_DEF_P1(arg) LISTI_DEF_P2 arg /* Define allocation functions. If MEMPOOL, we need to define it */ #define LISTI_MEMPOOL_DEF(name, type, oplist, list_t, list_it_t) \ @@ -124,7 +129,16 @@ } \ ) \ -#define LISTI_DEF2(name, type, oplist, list_t, list_it_t) \ + +/* Internal list definition + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the container + - list_t: alias for M_C(name, _t) [ type of the container ] + - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - node_t: alias for M_C(name, _node_t) [ node ] + */ +#define LISTI_DEF_P2(name, type, oplist, list_t, it_t) \ \ typedef struct M_C(name, _s) { \ struct M_C(name, _s) *next; \ @@ -138,17 +152,29 @@ typedef struct M_C(name, _it_s) { \ struct M_C(name, _s) *previous; \ struct M_C(name, _s) *current; \ - } list_it_t[1]; \ + } it_t[1]; \ \ - LISTI_MEMPOOL_DEF(name, type, oplist, list_t, list_it_t) \ - LISTI_DEF3(name, type, oplist, list_t, list_it_t) \ - LISTI_ITBASE_DEF(name, type, oplist, list_t, list_it_t) + LISTI_MEMPOOL_DEF(name, type, oplist, list_t, it_t) \ + LISTI_DEF_P3(name, type, oplist, list_t, it_t) \ + LISTI_ITBASE_DEF(name, type, oplist, list_t, it_t) + +/* Define the internal contract of a list + (there is nothing worthy to be checked) */ #define LISTI_CONTRACT(v) do { \ assert (v != NULL); \ } while (0) -#define LISTI_DEF3(name, type, oplist, list_t, list_it_t) \ + +/* Internal list function definition + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the container + - list_t: alias for M_C(name, _t) [ type of the container ] + - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - node_t: alias for M_C(name, _node_t) [ node ] + */ +#define LISTI_DEF_P3(name, type, oplist, list_t, it_t) \ \ static inline void \ M_C(name, _init)(list_t v) \ @@ -282,7 +308,7 @@ } \ \ static inline void \ - M_C(name, _it)(list_it_t it, const list_t v) \ + M_C(name, _it)(it_t it, const list_t v) \ { \ LISTI_CONTRACT(v); \ assert (it != NULL); \ @@ -291,7 +317,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(list_it_t it1, const list_it_t it2) \ + M_C(name, _it_set)(it_t it1, const it_t it2) \ { \ assert (it1 != NULL && it2 != NULL); \ it1->current = it2->current; \ @@ -299,7 +325,7 @@ } \ \ static inline void \ - M_C(name, _it_end)(list_it_t it1, const list_t v) \ + M_C(name, _it_end)(it_t it1, const list_t v) \ { \ LISTI_CONTRACT(v); \ assert (it1 != NULL); \ @@ -309,21 +335,21 @@ } \ \ static inline bool \ - M_C(name, _end_p)(const list_it_t it) \ + M_C(name, _end_p)(const it_t it) \ { \ assert (it != NULL); \ return it->current == NULL; \ } \ \ static inline bool \ - M_C(name, _last_p)(const list_it_t it) \ + M_C(name, _last_p)(const it_t it) \ { \ assert (it != NULL); \ return it->current == NULL || it->current->next == NULL; \ } \ \ static inline void \ - M_C(name, _next)(list_it_t it) \ + M_C(name, _next)(it_t it) \ { \ assert(it != NULL && it->current != NULL); \ it->previous = it->current; \ @@ -331,21 +357,21 @@ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const list_it_t it1, const list_it_t it2) \ + M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \ { \ assert(it1 != NULL && it2 != NULL); \ return it1->current == it2->current; \ } \ \ static inline type * \ - M_C(name, _ref)(const list_it_t it) \ + M_C(name, _ref)(const it_t it) \ { \ assert(it != NULL && it->current != NULL); \ return &(it->current->data); \ } \ \ static inline type const * \ - M_C(name, _cref)(const list_it_t it) \ + M_C(name, _cref)(const it_t it) \ { \ assert(it != NULL && it->current != NULL); \ return M_CONST_CAST(type, &(it->current->data)); \ @@ -365,7 +391,7 @@ } \ \ static inline bool \ - M_C(name, _sublist_p)(const list_t list, const list_it_t itsub) \ + M_C(name, _sublist_p)(const list_t list, const it_t itsub) \ { \ LISTI_CONTRACT(list); \ assert (itsub != NULL); \ @@ -401,7 +427,7 @@ } \ \ static inline void \ - M_C(name, _insert)(list_t list, list_it_t insertion_point, \ + M_C(name, _insert)(list_t list, it_t insertion_point, \ type const x) \ { \ LISTI_CONTRACT(list); \ @@ -425,7 +451,7 @@ } \ \ static inline void \ - M_C(name, _remove)(list_t list, list_it_t removing_point) \ + M_C(name, _remove)(list_t list, it_t removing_point) \ { \ LISTI_CONTRACT(list); \ assert (removing_point != NULL); \ @@ -493,7 +519,7 @@ } \ \ static inline void \ - M_C(name, _splice_back)(list_t nv, list_t ov, list_it_t it) \ + M_C(name, _splice_back)(list_t nv, list_t ov, it_t it) \ { \ LISTI_CONTRACT(nv); \ LISTI_CONTRACT(ov); \ @@ -517,8 +543,8 @@ } \ \ static inline void \ - M_C(name, _splice_at)(list_t nlist, list_it_t npos, \ - list_t olist, list_it_t opos) \ + M_C(name, _splice_at)(list_t nlist, it_t npos, \ + list_t olist, it_t opos) \ { \ LISTI_CONTRACT(nlist); \ LISTI_CONTRACT(olist); \ @@ -582,7 +608,18 @@ *list = previous; \ } \ -#define LISTI_ITBASE_DEF(name, type, oplist, list_t, list_it_t) \ + +/* Internal list function definition based on iterator functions + (common for all kind of lists) + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the container + - list_t: alias for M_C(name, _t) [ type of the container ] + - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - node_t: alias for M_C(name, _node_t) [ node ] + */ +#define LISTI_ITBASE_DEF(name, type, oplist, list_t, it_t) \ + \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ M_C(name, _get_str)(string_t str, const list_t list, \ @@ -687,7 +724,7 @@ m_serial_return_code_t ret; \ m_serial_local_t local; \ bool first_done = false; \ - ret = f->interface->write_array_start(local, f, 0); /* TBC: 0? */ \ + ret = f->interface->write_array_start(local, f, 0); \ M_C(name, _it_t) it; \ for (M_C(name, _it)(it, list) ; \ !M_C(name, _end_p)(it); \ @@ -770,20 +807,31 @@ } \ , /* no hash */ ) \ -/* Dual Push singly linked list. - Support Push Back / Push Front / Pop back in O(1). - Doesn't support Pop front. - This is done by keeping a pointer to both back & front - */ -#define LISTI_DUAL_PUSH_DEF(arg) LISTI_DUAL_PUSH_DEF2 arg -#define LISTI_DUAL_PUSH_DEF2(name, type, oplist, list_t, list_it_t) \ +/* Deferred evaluation for the dual-push list definition, + so that all arguments are evaluated before further expansion */ +#define LISTI_DUAL_PUSH_DEF_P1(arg) LISTI_DUAL_PUSH_DEF_P2 arg + +/* Internal dual-push list definition + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the container + - list_t: alias for M_C(name, _t) [ type of the container ] + - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - node_t: alias for M_C(name, _node_t) [ node ] + */ +#define LISTI_DUAL_PUSH_DEF_P2(name, type, oplist, list_t, it_t) \ \ struct M_C(name, _s) { \ struct M_C(name, _s) *next; \ type data; \ }; \ \ + /* Dual Push singly linked list. \ + Support Push Back / Push Front / Pop back in O(1). \ + Doesn't support Pop front. \ + This is done by keeping a pointer to both back & front \ + */ \ typedef struct M_C(name, _head_s) { \ struct M_C(name, _s) *front; \ struct M_C(name, _s) *back; \ @@ -796,19 +844,28 @@ typedef struct M_C(name, _it_s) { \ struct M_C(name, _s) *previous; \ struct M_C(name, _s) *current; \ - } list_it_t[1]; \ + } it_t[1]; \ \ - LISTI_MEMPOOL_DEF(name, type, oplist, list_t, list_it_t) \ - LISTI_DUAL_PUSH_DEF3(name, type, oplist, list_t, list_it_t) \ - LISTI_ITBASE_DEF(name, type, oplist, list_t, list_it_t) + LISTI_MEMPOOL_DEF(name, type, oplist, list_t, it_t) \ + LISTI_DUAL_PUSH_DEF_P3(name, type, oplist, list_t, it_t) \ + LISTI_ITBASE_DEF(name, type, oplist, list_t, it_t) +/* Define the internal contract of an dual-push list */ #define LISTI_DUAL_PUSH_CONTRACT(l) do { \ assert (l != NULL); \ assert ( (l->back == NULL && l->front == NULL) \ || (l->back != NULL && l->front != NULL)); \ } while (0) -#define LISTI_DUAL_PUSH_DEF3(name, type, oplist, list_t, list_it_t) \ +/* Internal dual-push list definition + - name: prefix to be used + - type: type of the elements of the array + - oplist: oplist of the type of the elements of the container + - list_t: alias for M_C(name, _t) [ type of the container ] + - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - node_t: alias for M_C(name, _node_t) [ node ] + */ +#define LISTI_DUAL_PUSH_DEF_P3(name, type, oplist, list_t, it_t) \ \ static inline void \ M_C(name, _init)(list_t v) \ @@ -1024,7 +1081,7 @@ } \ \ static inline void \ - M_C(name, _it)(list_it_t it, const list_t v) \ + M_C(name, _it)(it_t it, const list_t v) \ { \ LISTI_DUAL_PUSH_CONTRACT(v); \ assert (it != NULL); \ @@ -1033,7 +1090,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(list_it_t it1, const list_it_t it2) \ + M_C(name, _it_set)(it_t it1, const it_t it2) \ { \ assert (it1 != NULL && it2 != NULL); \ it1->current = it2->current; \ @@ -1041,7 +1098,7 @@ } \ \ static inline void \ - M_C(name, _it_end)(list_it_t it1, const list_t v) \ + M_C(name, _it_end)(it_t it1, const list_t v) \ { \ assert (it1 != NULL); \ LISTI_DUAL_PUSH_CONTRACT(v); \ @@ -1051,21 +1108,21 @@ } \ \ static inline bool \ - M_C(name, _end_p)(const list_it_t it) \ + M_C(name, _end_p)(const it_t it) \ { \ assert (it != NULL); \ return it->current == NULL; \ } \ \ static inline bool \ - M_C(name, _last_p)(const list_it_t it) \ + M_C(name, _last_p)(const it_t it) \ { \ assert (it != NULL); \ return it->current == NULL || it->current->next == NULL; \ } \ \ static inline void \ - M_C(name, _next)(list_it_t it) \ + M_C(name, _next)(it_t it) \ { \ assert(it != NULL && it->current != NULL); \ it->previous = it->current; \ @@ -1073,21 +1130,21 @@ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const list_it_t it1, const list_it_t it2) \ + M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \ { \ assert(it1 != NULL && it2 != NULL); \ return it1->current == it2->current; \ } \ \ static inline type * \ - M_C(name, _ref)(const list_it_t it) \ + M_C(name, _ref)(const it_t it) \ { \ assert(it != NULL && it->current != NULL); \ return &(it->current->data); \ } \ \ static inline type const * \ - M_C(name, _cref)(const list_it_t it) \ + M_C(name, _cref)(const it_t it) \ { \ assert(it != NULL && it->current != NULL); \ return M_CONST_CAST(type, &(it->current->data)); \ @@ -1107,7 +1164,7 @@ } \ \ static inline void \ - M_C(name, _insert)(list_t list, list_it_t insertion_point, \ + M_C(name, _insert)(list_t list, it_t insertion_point, \ type const x) \ { \ LISTI_DUAL_PUSH_CONTRACT(list); \ @@ -1136,7 +1193,7 @@ } \ \ static inline void \ - M_C(name, _remove)(list_t list, list_it_t removing_point) \ + M_C(name, _remove)(list_t list, it_t removing_point) \ { \ LISTI_DUAL_PUSH_CONTRACT(list); \ assert (removing_point != NULL); \ @@ -1211,7 +1268,7 @@ } \ \ static inline void \ - M_C(name, _splice_back)(list_t list1, list_t list2, list_it_t it) \ + M_C(name, _splice_back)(list_t list1, list_t list2, it_t it) \ { \ LISTI_DUAL_PUSH_CONTRACT(list1); \ LISTI_DUAL_PUSH_CONTRACT(list2); \ @@ -1243,8 +1300,8 @@ } \ \ static inline void \ - M_C(name, _splice_at)(list_t nlist, list_it_t npos, \ - list_t olist, list_it_t opos) \ + M_C(name, _splice_at)(list_t nlist, it_t npos, \ + list_t olist, it_t opos) \ { \ LISTI_DUAL_PUSH_CONTRACT(nlist); \ LISTI_DUAL_PUSH_CONTRACT(olist); \