diff --git a/m-list.h b/m-list.h index a0073968..6a6a158d 100644 --- a/m-list.h +++ b/m-list.h @@ -44,15 +44,15 @@ M_END_PROTECTED_CODE -/* Define a singly linked list of a given type allowing both push. - USAGE: LIST_DUAL_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ +/* Define a singly linked list of a given type allowing both push and one pop (back) + USAGE: LIST_DUAL_PUSH_DEF(name, type [, oplist_of_the_type]) */ #define M_LIST_DUAL_PUSH_DEF(name, ...) \ M_LIST_DUAL_PUSH_DEF_AS(name, M_F(name,_t), M_F(name, _it_t), __VA_ARGS__) -/* Define a singly linked list of a given type allowing both push. +/* Define a singly linked list of a given type allowing both push and one pop (back) as the provided type name_t with the iterator named it_t - USAGE: LIST_DUAL_PUSH_DEF(name, type [, oplist_of_the_type]) */ + USAGE: LIST_DUAL_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ #define M_LIST_DUAL_PUSH_DEF_AS(name, name_t, it_t, ...) \ M_BEGIN_PROTECTED_CODE \ M_L1ST_DUAL_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ @@ -61,6 +61,22 @@ M_END_PROTECTED_CODE +/* Define a singly linked list of a given type allowing both push and one pop (front) + USAGE: LIST_BI_PUSH_DEF(name, type [, oplist_of_the_type]) */ +#define M_LIST_BI_PUSH_DEF(name, ...) \ + M_LIST_BI_PUSH_DEF_AS(name, M_F(name,_t), M_F(name, _it_t), __VA_ARGS__) + + +/* Define a singly linked list of a given type allowing both push and one pop (front) + as the provided type name_t with the iterator named it_t + USAGE: LIST_BI_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ +#define M_LIST_BI_PUSH_DEF_AS(name, name_t, it_t, ...) \ + M_BEGIN_PROTECTED_CODE \ + M_L1ST_BI_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \ + (name, __VA_ARGS__, name_t, it_t ))) \ + M_END_PROTECTED_CODE + /* Define the oplist of a list of the given type. USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */ #define M_LIST_OPLIST(...) \ @@ -1529,11 +1545,40 @@ } \ +/* Deferred evaluation for the bi-push list definition, + so that all arguments are evaluated before further expansion */ +#define M_L1ST_BI_PUSH_DEF_P1(arg) M_ID( M_L1ST_BI_PUSH_DEF_P2 arg ) + +/* Validate the oplist before going further */ +#define M_L1ST_BI_PUSH_DEF_P2(name, type, oplist, list_t, it_t) \ + M_IF_OPLIST(oplist)(M_L1ST_BI_PUSH_DEF_P3, M_L1ST_BI_PUSH_DEF_FAILURE)(name, type, oplist, list_t, it_t) + +/* Stop processing with a compilation failure */ +#define M_L1ST_BI_PUSH_DEF_FAILURE(name, type, oplist, list_t, it_t) \ + M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(LIST_BI_PUSH_DEF): the given argument is not a valid oplist: " #oplist) + +/* Internal bi-push list definition (like dual-push but inverts front & back) + - 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_F(name, _t) [ type of the container ] + - it_t: alias for M_F(name, _it_t) [ iterator of the container ] + */ +#define M_L1ST_BI_PUSH_DEF_P3(name, type, oplist, list_t, it_t) \ + M_L1ST_DUAL_PUSH_DEF_TYPE(name, type, oplist, list_t, it_t) \ + M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + M_L1ST_DUAL_PUSH_DEF_P4(name, type, oplist, list_t, it_t, _front, _push_front_raw, _push_front, _push_front_move, _push_front_new, _pop_front, _back, _push_back_raw, _push_back, _push_back_move, _push_back_new) \ + M_EMPLACE_QUEUE_DEF(name, list_t, _emplace_front, oplist, M_L1ST_EMPLACE_STRONG_DEF) \ + M_EMPLACE_QUEUE_DEF(name, list_t, _emplace_back, oplist, M_L1ST_EMPLACE_WEAK_DEF) \ + M_L1ST_ITBASE_DEF(name, type, oplist, list_t, it_t) + #if M_USE_SMALL_NAME #define LIST_DEF M_LIST_DEF #define LIST_DEF_AS M_LIST_DEF_AS #define LIST_DUAL_PUSH_DEF M_LIST_DUAL_PUSH_DEF #define LIST_DUAL_PUSH_DEF_AS M_LIST_DUAL_PUSH_DEF_AS +#define LIST_BI_PUSH_DEF M_LIST_BI_PUSH_DEF +#define LIST_BI_PUSH_DEF_AS M_LIST_BI_PUSH_DEF_AS #define LIST_OPLIST M_LIST_OPLIST #define LIST_INIT_VALUE M_LIST_INIT_VALUE #define LIST_DUAL_PUSH_INIT_VALUE M_LIST_DUAL_PUSH_INIT_VALUE diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 0a2dbded..622711e4 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -47,6 +47,8 @@ LIST_DEF_AS(list_double, ListDouble, ListDoubleIt, double) LIST_DUAL_PUSH_DEF_AS(list_doubleDP, ListDoubleDP, ListDoubleDPIt, double) #define M_OPL_ListDoubleDP() LIST_OPLIST(list_doubleDP, M_BASIC_OPLIST) +LIST_BI_PUSH_DEF(list2f_double, double) + ListDouble g_array1 = LIST_INIT_VALUE(); ListDoubleDP g_array2 = LIST_DUAL_PUSH_INIT_VALUE();