Add ALGO ALGO_INSERT that allows inserting a container into another one.
This commit is contained in:
1 parent
df8306c721
commit
ede57a20be
2 files changed
+40
-3
No files matched your search
@@ -75,13 +75,30 @@
|
|||||||
|
|
||||||
/* Define, initialize, set & clear a container with a variable array list.
|
/* Define, initialize, set & clear a container with a variable array list.
|
||||||
USAGE:
|
USAGE:
|
||||||
ALGO_LET_INIT_VA(container, containerOplist, param1[, param2[, ...]]) {
|
ALGO_LET_INIT_VA(container, containerOplist|type, param1[, param2[, ...]]) {
|
||||||
// Stuff with container
|
// Stuff with container
|
||||||
} */
|
} */
|
||||||
#define ALGO_LET_INIT_VA(dest, contOp, ...) \
|
#define ALGO_LET_INIT_VA(dest, contOp, ...) \
|
||||||
ALGO_LET_INIT_VAI(dest, M_GLOBAL_OPLIST(contOp), __VA_ARGS__)
|
ALGO_LET_INIT_VAI(dest, M_GLOBAL_OPLIST(contOp), __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
|
#define ALGO_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) \
|
||||||
|
ALGOI_INSERT_AT(contDst, M_GLOBAL_OPLIST(contDstOp), position, contSrc, M_GLOBAL_OPLIST(contSrcOp) )
|
||||||
|
|
||||||
|
#define ALGOI_INSERT_AT(contDst, contDstOp, position, contSrc, contSrcOp) do { \
|
||||||
|
M_GET_IT_TYPE contSrcOp itSrc; \
|
||||||
|
M_GET_IT_TYPE contDstOp itDst; \
|
||||||
|
M_GET_IT_SET contDstOp (itDst, position); \
|
||||||
|
for (M_GET_IT_FIRST contSrcOp (itSrc, contSrc) ; \
|
||||||
|
!M_GET_IT_END_P contSrcOp (itSrc) ; \
|
||||||
|
M_GET_IT_NEXT contSrcOp (itSrc) ) { \
|
||||||
|
M_GET_IT_INSERT contDstOp (contDst, itDst, \
|
||||||
|
*M_GET_IT_CREF contSrcOp (itSrc)); \
|
||||||
|
M_GET_IT_NEXT contDstOp (itDst); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/********************************** INTERNAL ************************************/
|
/********************************** INTERNAL ************************************/
|
||||||
|
|
||||||
#define ALGOI_DEF(name, cont_oplist) \
|
#define ALGOI_DEF(name, cont_oplist) \
|
||||||
@@ -668,7 +685,7 @@
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
while (!M_GET_IT_END_P cont_oplist (itSrc)) { \
|
while (!M_GET_IT_END_P cont_oplist (itSrc)) { \
|
||||||
type *objSrc = M_GET_REF cont_oplist (itSrc); \
|
type_t *objSrc = M_GET_IT_REF cont_oplist (itSrc); \
|
||||||
M_GET_PUSH cont_oplist (dst, *objSrc); \
|
M_GET_PUSH cont_oplist (dst, *objSrc); \
|
||||||
M_GET_IT_NEXT cont_oplist (itSrc); \
|
M_GET_IT_NEXT cont_oplist (itSrc); \
|
||||||
} \
|
} \
|
||||||
|
|||||||
@@ -386,11 +386,31 @@ static void test_extract(void)
|
|||||||
list_int_clear(l);
|
list_int_clear(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ARRAY_DEF(aint, int)
|
||||||
|
LIST_DEF(lint, int)
|
||||||
|
#define M_OPL_aint_t() ARRAY_OPLIST(aint)
|
||||||
|
#define M_OPL_lint_t() LIST_OPLIST(lint)
|
||||||
|
|
||||||
|
static void test_insert(void)
|
||||||
|
{
|
||||||
|
ALGO_LET_INIT_VA(a, lint_t, 1, 2, 3, 4)
|
||||||
|
ALGO_LET_INIT_VA(b, aint_t, -1, -2, -3) {
|
||||||
|
lint_it_t i;
|
||||||
|
lint_it(i, a);
|
||||||
|
ALGO_INSERT_AT(a, lint_t, i, b, aint_t);
|
||||||
|
// TBC: order ok for the list (the reverse is confusing...)?
|
||||||
|
ALGO_LET_INIT_VA(c, lint_t, 1, 2, 3, -3, -2, -1, 4) {
|
||||||
|
assert (lint_equal_p (c, a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
test_list();
|
test_list();
|
||||||
test_array();
|
test_array();
|
||||||
test_string();
|
test_string();
|
||||||
test_extract();
|
test_extract();
|
||||||
|
test_insert();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user