Add new macros _DEF_AS so that
user can define its own name for the generated types.
This commit is contained in:
1 parent
63eee6bba3
commit
e04b120d41
4 files changed
+80
-6
No files matched your search
@@ -37,12 +37,23 @@
|
|||||||
M_END_PROTECTED_CODE
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Define a dynamic array of the given type and its associated functions
|
||||||
|
as the provided type name_t with the iterator named it_t
|
||||||
|
USAGE: ARRAY_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
|
||||||
|
#define ARRAY_DEF_AS(name, name_t, it_t, ...) \
|
||||||
|
M_BEGIN_PROTECTED_CODE \
|
||||||
|
ARRAYI_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 dynamic array given its name and its oplist.
|
/* 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
|
If no oplist is given it is assumed to be M_DEFAULT_OPLIST
|
||||||
USAGE: ARRAY_OPLIST(name[, oplist of the type]) */
|
USAGE: ARRAY_OPLIST(name[, oplist of the type]) */
|
||||||
#define ARRAY_OPLIST(...) \
|
#define ARRAY_OPLIST(...) \
|
||||||
ARRAYI_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
|
ARRAYI_OPLIST_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||||
((__VA_ARGS__, M_DEFAULT_OPLIST), \
|
((__VA_ARGS__, M_DEFAULT_OPLIST), \
|
||||||
(__VA_ARGS__ )))
|
(__VA_ARGS__ )))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,18 @@
|
|||||||
M_BEGIN_PROTECTED_CODE \
|
M_BEGIN_PROTECTED_CODE \
|
||||||
LISTI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
|
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_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) ))) \
|
(name, __VA_ARGS__, M_C(name,_t), M_C(name, _it_t) ))) \
|
||||||
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Define a singly linked list of a given type
|
||||||
|
as the provided type name_t with the iterator named it_t
|
||||||
|
USAGE: LIST_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
|
||||||
|
#define LIST_DEF_AS(name, name_t, it_t, ...) \
|
||||||
|
M_BEGIN_PROTECTED_CODE \
|
||||||
|
LISTI_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
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +58,17 @@
|
|||||||
M_END_PROTECTED_CODE
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Define a singly linked list of a given type allowing both push.
|
||||||
|
as the provided type name_t with the iterator named it_t
|
||||||
|
USAGE: LIST_DUAL_PUSH_DEF(name, type [, oplist_of_the_type]) */
|
||||||
|
#define LIST_DUAL_PUSH_DEF_AS(name, name_t, it_t, ...) \
|
||||||
|
M_BEGIN_PROTECTED_CODE \
|
||||||
|
LISTI_DUAL_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.
|
/* Define the oplist of a list of the given type.
|
||||||
USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */
|
USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */
|
||||||
#define LIST_OPLIST(...) \
|
#define LIST_OPLIST(...) \
|
||||||
@@ -659,7 +681,7 @@
|
|||||||
{ \
|
{ \
|
||||||
assert (str != NULL && list != NULL); \
|
assert (str != NULL && list != NULL); \
|
||||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||||
M_C(name, _it_t) it; \
|
it_t it; \
|
||||||
for (M_C(name, _it)(it, list) ; \
|
for (M_C(name, _it)(it, list) ; \
|
||||||
!M_C(name, _end_p)(it); \
|
!M_C(name, _end_p)(it); \
|
||||||
M_C(name, _next)(it)){ \
|
M_C(name, _next)(it)){ \
|
||||||
@@ -804,8 +826,8 @@
|
|||||||
M_C(name, _equal_p)(const list_t list1, const list_t list2) \
|
M_C(name, _equal_p)(const list_t list1, const list_t list2) \
|
||||||
{ \
|
{ \
|
||||||
assert (list1 != NULL && list2 != NULL); \
|
assert (list1 != NULL && list2 != NULL); \
|
||||||
M_C(name, _it_t) it1; \
|
it_t it1; \
|
||||||
M_C(name, _it_t) it2; \
|
it_t it2; \
|
||||||
if (list1 == list2) return true; \
|
if (list1 == list2) return true; \
|
||||||
M_C(name, _it)(it1, list1); \
|
M_C(name, _it)(it1, list1); \
|
||||||
M_C(name, _it)(it2, list2); \
|
M_C(name, _it)(it2, list2); \
|
||||||
@@ -829,7 +851,7 @@
|
|||||||
{ \
|
{ \
|
||||||
assert (list != NULL); \
|
assert (list != NULL); \
|
||||||
M_HASH_DECL(hash); \
|
M_HASH_DECL(hash); \
|
||||||
M_C(name, _it_t) it; \
|
it_t it; \
|
||||||
for(M_C(name, _it)(it, list) ; \
|
for(M_C(name, _it)(it, list) ; \
|
||||||
!M_C(name, _end_p)(it); \
|
!M_C(name, _end_p)(it); \
|
||||||
M_C(name, _next)(it)) { \
|
M_C(name, _next)(it)) { \
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ ARRAY_DEF(array_min3_z, testobj_t, (CLEAR(testobj_clear)))
|
|||||||
|
|
||||||
ARRAY_DEF(array_ulong, uint64_t)
|
ARRAY_DEF(array_ulong, uint64_t)
|
||||||
|
|
||||||
|
ARRAY_DEF_AS(array_double, ArrayDouble, ArrayDoubleIt, double)
|
||||||
|
#define M_OPL_ArrayDouble() ARRAY_OPLIST(array_double, M_DEFAULT_OPLIST)
|
||||||
|
|
||||||
static void test_uint(void)
|
static void test_uint(void)
|
||||||
{
|
{
|
||||||
array_uint_t v;
|
array_uint_t v;
|
||||||
@@ -350,10 +353,22 @@ static void test_d(void)
|
|||||||
array_uint_clear(a2);
|
array_uint_clear(a2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_double(void)
|
||||||
|
{
|
||||||
|
M_LET( (tab, 0.0, 1.0, 2.0, 3.0), ArrayDouble) {
|
||||||
|
double ref = 0.0;
|
||||||
|
for M_EACH(i, tab, ArrayDouble) {
|
||||||
|
assert (*i == ref);
|
||||||
|
ref += 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
test_uint();
|
test_uint();
|
||||||
test_mpz();
|
test_mpz();
|
||||||
test_d();
|
test_d();
|
||||||
|
test_double();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,12 @@ LIST_DEF(list_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), C
|
|||||||
LIST_DUAL_PUSH_DEF(list2_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
LIST_DUAL_PUSH_DEF(list2_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
||||||
|
|
||||||
|
|
||||||
|
LIST_DEF_AS(list_double, ListDouble, ListDoubleIt, double)
|
||||||
|
#define M_OPL_ListDouble() LIST_OPLIST(list_double, M_DEFAULT_OPLIST)
|
||||||
|
|
||||||
|
LIST_DUAL_PUSH_DEF_AS(list_doubleDP, ListDoubleDP, ListDoubleDPIt, double)
|
||||||
|
#define M_OPL_ListDoubleDP() LIST_OPLIST(list_doubleDP, M_DEFAULT_OPLIST)
|
||||||
|
|
||||||
static void test_uint(void)
|
static void test_uint(void)
|
||||||
{
|
{
|
||||||
list_uint_t v;
|
list_uint_t v;
|
||||||
@@ -635,6 +641,25 @@ static void test_out_default_oplist(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void test_double(void)
|
||||||
|
{
|
||||||
|
M_LET( (tab, 0.0, 1.0, 2.0, 3.0), ListDouble) {
|
||||||
|
double ref = 0.0;
|
||||||
|
for M_EACH(i, tab, ListDouble) {
|
||||||
|
assert (*i == ref);
|
||||||
|
ref += 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
M_LET( (tab, 0.0, 1.0, 2.0, 3.0), ListDoubleDP) {
|
||||||
|
double ref = 0.0;
|
||||||
|
for M_EACH(i, tab, ListDoubleDP) {
|
||||||
|
assert (*i == ref);
|
||||||
|
ref += 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
test_uint();
|
test_uint();
|
||||||
@@ -642,6 +667,7 @@ int main(void)
|
|||||||
test_dual_push1();
|
test_dual_push1();
|
||||||
test_dual_it1();
|
test_dual_it1();
|
||||||
test_out_default_oplist();
|
test_out_default_oplist();
|
||||||
|
test_double();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user