Add macro DEQUE_DEF_AS
This commit is contained in:
1 parent
3d3a473716
commit
a4fa70a478
2 files changed
+26
-1
No files matched your search
@@ -37,6 +37,17 @@
|
|||||||
M_END_PROTECTED_CODE
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
|
|
||||||
|
/* Define a deque of a given type and its associated functions.
|
||||||
|
as the provided type name_t with the iterator named it_t.
|
||||||
|
USAGE: DEQUE_DEF(name, name_t, it_t, type [, oplist_of_the_type]) */
|
||||||
|
#define DEQUE_DEF_AS(name, name_t, it_t, ...) \
|
||||||
|
M_BEGIN_PROTECTED_CODE \
|
||||||
|
DEQUEI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||||
|
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _node_ct) ), \
|
||||||
|
(name, __VA_ARGS__, name_t, it_t, M_C(name, _node_ct)))) \
|
||||||
|
M_END_PROTECTED_CODE
|
||||||
|
|
||||||
|
|
||||||
/* Define the oplist of a deque of a type.
|
/* Define the oplist of a deque of a type.
|
||||||
USAGE: DEQUE_OPLIST(name[, oplist of the type]) */
|
USAGE: DEQUE_OPLIST(name[, oplist of the type]) */
|
||||||
#define DEQUE_OPLIST(...) \
|
#define DEQUE_OPLIST(...) \
|
||||||
|
|||||||
+15
-1
@@ -36,14 +36,17 @@ DEQUE_DEF(deque_mpz, testobj_t, TESTOBJ_OPLIST)
|
|||||||
// Deque with the minimum number of methods.
|
// Deque with the minimum number of methods.
|
||||||
DEQUE_DEF(deque_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
DEQUE_DEF(deque_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
||||||
|
|
||||||
|
// Dequeue of an enumerate
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SUCCESS = 0, NULL_PARAM, INVALID_PARAM
|
SUCCESS = 0, NULL_PARAM, INVALID_PARAM
|
||||||
} ReturnCode_t;
|
} ReturnCode_t;
|
||||||
|
|
||||||
DEQUE_DEF(deque_retcode, ReturnCode_t, M_ENUM_OPLIST(ReturnCode_t, SUCCESS))
|
DEQUE_DEF(deque_retcode, ReturnCode_t, M_ENUM_OPLIST(ReturnCode_t, SUCCESS))
|
||||||
|
|
||||||
#define OPL DEQUE_OPLIST(deque)
|
#define OPL DEQUE_OPLIST(deque)
|
||||||
|
|
||||||
|
DEQUE_DEF_AS(DequeDouble, DequeDouble, DequeDoubleIt, double)
|
||||||
|
#define M_OPL_DequeDouble() DEQUE_OPLIST(DequeDouble, M_DEFAULT_OPLIST)
|
||||||
|
|
||||||
static void test_ti1(int n)
|
static void test_ti1(int n)
|
||||||
{
|
{
|
||||||
deque_t d;
|
deque_t d;
|
||||||
@@ -383,6 +386,16 @@ static void test_io_enum(void)
|
|||||||
deque_retcode_clear(d2);
|
deque_retcode_clear(d2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_double(void)
|
||||||
|
{
|
||||||
|
M_LET( (tab, 0.0, 1.0, 2.0, 3.0), DequeDouble) {
|
||||||
|
double ref = 0.0;
|
||||||
|
for M_EACH(i, tab, DequeDouble) {
|
||||||
|
assert (*i == ref);
|
||||||
|
ref += 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -397,5 +410,6 @@ int main(void)
|
|||||||
test_io_enum();
|
test_io_enum();
|
||||||
test_z();
|
test_z();
|
||||||
test_advance();
|
test_advance();
|
||||||
|
test_double();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user