WIP on BI-F list. Still an issue to fix
This commit is contained in:
1 parent
089b8b3c61
commit
522f37f66d
2 files changed
+81
-19
No files matched your search
@@ -62,17 +62,17 @@
|
||||
|
||||
|
||||
/* 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__)
|
||||
USAGE: LIST_BIF_DEF(name, type [, oplist_of_the_type]) */
|
||||
#define M_LIST_BIF_DEF(name, ...) \
|
||||
M_LIST_BIF_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, ...) \
|
||||
USAGE: LIST_BIF_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
|
||||
#define M_LIST_BIF_DEF_AS(name, name_t, it_t, ...) \
|
||||
M_BEGIN_PROTECTED_CODE \
|
||||
M_L1ST_BI_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||
M_L1ST_BIF_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
|
||||
@@ -144,8 +144,8 @@
|
||||
IT_INSERT(M_F(name, _insert)), \
|
||||
IT_REMOVE(M_F(name,_remove)), \
|
||||
RESET(M_F(name,_reset)), \
|
||||
PUSH(M_F(name,_push_back)), \
|
||||
POP(M_F(name,_pop_back)), \
|
||||
PUSH(M_F(name,_push)), \
|
||||
POP(M_F(name,_pop)), \
|
||||
PUSH_MOVE(M_F(name,_push_move)), \
|
||||
POP_MOVE(M_F(name,_pop_move)) \
|
||||
,SPLICE_BACK(M_F(name,_splice_back)) \
|
||||
@@ -188,8 +188,8 @@
|
||||
IT_INSERT(API_0P(M_F(name, _insert))), \
|
||||
IT_REMOVE(API_0P(M_F(name,_remove))), \
|
||||
RESET(API_0P(M_F(name,_reset))), \
|
||||
PUSH(API_0P(M_F(name,_push_back))), \
|
||||
POP(API_0P(M_F(name,_pop_back))), \
|
||||
PUSH(API_0P(M_F(name,_push))), \
|
||||
POP(API_0P(M_F(name,_pop))), \
|
||||
PUSH_MOVE(API_0P(M_F(name,_push_move))), \
|
||||
POP_MOVE(API_0P(M_F(name,_pop_move))) \
|
||||
,SPLICE_BACK(M_F(name,_splice_back)) \
|
||||
@@ -334,6 +334,11 @@
|
||||
} \
|
||||
} \
|
||||
\
|
||||
M_P(void, name, _push, list_t v, type const x) \
|
||||
{ \
|
||||
M_F(name, _push_back)M_R(v, x); \
|
||||
} \
|
||||
\
|
||||
M_IF_METHOD(INIT, oplist)( \
|
||||
M_P(type *, name, _push_new, list_t v) \
|
||||
{ \
|
||||
@@ -363,6 +368,11 @@
|
||||
M_L1ST_CONTRACT(v); \
|
||||
} \
|
||||
\
|
||||
M_P(void, name, _pop, type *data, list_t v) \
|
||||
{ \
|
||||
M_F(name, _pop_back)M_R(data, v); \
|
||||
} \
|
||||
\
|
||||
M_P(void, name, _push_move, list_t v, type *x) \
|
||||
{ \
|
||||
M_ASSERT (x != NULL); \
|
||||
@@ -1094,6 +1104,11 @@
|
||||
} \
|
||||
} \
|
||||
\
|
||||
M_P(void, name, _push, list_t v, type const x) \
|
||||
{ \
|
||||
M_F(name, push_strong)M_R(v, x); \
|
||||
} \
|
||||
\
|
||||
M_IF_METHOD(INIT, oplist)( \
|
||||
M_P(type *, name, push_strong_new, list_t v) \
|
||||
{ \
|
||||
@@ -1142,6 +1157,11 @@
|
||||
M_L1ST_DUAL_PUSH_CONTRACT(v); \
|
||||
} \
|
||||
\
|
||||
M_P(void, name, _pop, type *data, list_t v) \
|
||||
{ \
|
||||
M_F(name, pop_strong)M_R(data, v); \
|
||||
} \
|
||||
\
|
||||
M_P(void, name, _pop_move, type *data, list_t v) \
|
||||
{ \
|
||||
M_L1ST_DUAL_PUSH_CONTRACT(v); \
|
||||
@@ -1431,6 +1451,7 @@
|
||||
M_INLINE void \
|
||||
M_F(name, _splice_back)(list_t list1, list_t list2, it_t it) \
|
||||
{ \
|
||||
/* FIXME back ==> strong */ \
|
||||
M_L1ST_DUAL_PUSH_CONTRACT(list1); \
|
||||
M_L1ST_DUAL_PUSH_CONTRACT(list2); \
|
||||
M_ASSERT (it->current != NULL); \
|
||||
@@ -1547,15 +1568,15 @@
|
||||
|
||||
/* 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 )
|
||||
#define M_L1ST_BIF_DEF_P1(arg) M_ID( M_L1ST_BIF_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)
|
||||
#define M_L1ST_BIF_DEF_P2(name, type, oplist, list_t, it_t) \
|
||||
M_IF_OPLIST(oplist)(M_L1ST_BIF_DEF_P3, M_L1ST_BIF_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)
|
||||
#define M_L1ST_BIF_DEF_FAILURE(name, type, oplist, list_t, it_t) \
|
||||
M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(LIST_BIF_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
|
||||
@@ -1564,7 +1585,7 @@
|
||||
- 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) \
|
||||
#define M_L1ST_BIF_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) \
|
||||
@@ -1577,8 +1598,8 @@
|
||||
#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_BIF_DEF M_LIST_BIF_DEF
|
||||
#define LIST_BIF_DEF_AS M_LIST_BIF_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
|
||||
|
||||
+42
-1
@@ -47,7 +47,7 @@ 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)
|
||||
LIST_BIF_DEF(list2f_double, double)
|
||||
|
||||
ListDouble g_array1 = LIST_INIT_VALUE();
|
||||
ListDoubleDP g_array2 = LIST_DUAL_PUSH_INIT_VALUE();
|
||||
@@ -576,6 +576,46 @@ static void test_dual_push1(void)
|
||||
list2_double_clear(list);
|
||||
}
|
||||
|
||||
static void test_bif(void)
|
||||
{
|
||||
list2f_double_t x;
|
||||
|
||||
list2f_double_init(x);
|
||||
assert(list2f_double_empty_p(x));
|
||||
list2f_double_push_front(x, 2.0);
|
||||
list2f_double_push_front(x, 1.0);
|
||||
list2f_double_push_back(x, 3.0);
|
||||
assert(list2f_double_size(x) == 3);
|
||||
assert(*list2f_double_front(x) == 1.0);
|
||||
assert(*list2f_double_back(x) == 3.0);
|
||||
list2f_double_it_t it;
|
||||
double d = 1.0;
|
||||
for(list2f_double_it(it, x); !list2f_double_end_p(it); list2f_double_next(it)){
|
||||
assert(d == *list2f_double_cref(it));
|
||||
d += 1.0;
|
||||
}
|
||||
list2f_double_pop_front(&d, x);
|
||||
assert(d == 1.0);
|
||||
list2f_double_reverse(x);
|
||||
list2f_double_pop_front(&d, x);
|
||||
assert(d == 3.0);
|
||||
list2f_double_pop_front(&d, x);
|
||||
assert(d == 2.0);
|
||||
assert(list2f_double_empty_p(x));
|
||||
list2f_double_clear(x);
|
||||
// BUG: M_INIT_WITH_VAI23_FUNC uses _back instead of _strong...
|
||||
// How to fix? Create common functions also for array...
|
||||
M_LET( (y, (1.0, 2.0, 3.0, 4.0)), LIST_OPLIST(list2f_double, M_BASIC_OPLIST)) {
|
||||
assert(list2f_double_size(y) == 4);
|
||||
for(list2f_double_it(it, y); !list2f_double_end_p(it); list2f_double_next(it)){
|
||||
printf("%f ", *list2f_double_cref(it) );
|
||||
} printf("\n");
|
||||
printf("Front=%f\n", *list2f_double_front(y) );
|
||||
assert(*list2f_double_front(y) == 1.0);
|
||||
assert(*list2f_double_back(y) == 4.0);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_dual_it1(void)
|
||||
{
|
||||
list2_double_t list;
|
||||
@@ -901,6 +941,7 @@ int main(void)
|
||||
test_mpz();
|
||||
test_dual_push1();
|
||||
test_dual_it1();
|
||||
test_bif();
|
||||
test_out_default_oplist();
|
||||
test_double();
|
||||
test_let_string();
|
||||
|
||||
Reference in new issue
Block a user