Make INIT operator optionnal for ARRAY & LIST.

This commit is contained in:
Patrick Pelissier committed 2018-09-08 08:21:13 +02:00
1 parent 7a55667a5d
commit 2174c28aa2
4 files changed
+32 -8

No files matched your search

+14 -4
View File
@@ -260,6 +260,7 @@
M_GET_INIT_SET oplist(*data, x); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline type * \
M_C(name, _push_new)(array_t v) \
{ \
@@ -269,6 +270,7 @@
M_GET_INIT oplist(*data); \
return data; \
} \
, /* No INIT */ ) \
\
static inline void \
M_C(name, _push_move)(array_t v, type *x) \
@@ -308,6 +310,7 @@
ARRAYI_CONTRACT(v); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline void \
M_C(name, _resize)(array_t v, size_t size) \
{ \
@@ -335,6 +338,7 @@
} \
ARRAYI_CONTRACT(v); \
} \
, /* No INIT */ ) \
\
static inline void \
M_C(name, _reserve)(array_t v, size_t alloc) \
@@ -360,6 +364,7 @@
ARRAYI_CONTRACT(v); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline type * \
M_C(name, _get_at)(array_t v, size_t idx) \
{ \
@@ -391,6 +396,7 @@
ARRAYI_CONTRACT(v); \
return &v->ptr[idx]; \
} \
, /* No INIT */) \
\
static inline void \
M_C(name, _pop_back)(type *dest, array_t v) \
@@ -417,6 +423,7 @@
ARRAYI_CONTRACT(v); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline void \
M_C(name, _pop_until)(array_t v, array_it_t pos) \
{ \
@@ -425,6 +432,7 @@
M_ASSUME (pos->index <= v->size); \
M_C(name, _resize)(v, pos->index); \
} \
, /* No INIT */ ) \
\
static inline bool \
M_C(name, _empty_p)(const array_t v) \
@@ -461,6 +469,7 @@
ARRAYI_CONTRACT(v); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline void \
M_C(name, _insert_v)(array_t v, size_t i, size_t num) \
{ \
@@ -488,6 +497,7 @@
v->size = size; \
ARRAYI_CONTRACT(v); \
} \
, /* No INIT */) \
\
static inline void \
M_C(name, _remove_v)(array_t v, size_t i, size_t j) \
@@ -809,7 +819,7 @@
} \
, /* no OUT_STR */ ) \
\
M_IF_METHOD(PARSE_STR, oplist)( \
M_IF_METHOD2(PARSE_STR, INIT, oplist)( \
static inline bool \
M_C(name, _parse_str)(array_t array, const char str[], const char**endp) \
{ \
@@ -838,9 +848,9 @@
if (endp) *endp = str; \
return success; \
} \
, /* no PARSE_STR */ ) \
, /* no PARSE_STR & INIT */ ) \
\
M_IF_METHOD(IN_STR, oplist)( \
M_IF_METHOD2(IN_STR, INIT, oplist)( \
static inline bool \
M_C(name, _in_str)(array_t array, FILE *file) \
{ \
@@ -865,7 +875,7 @@
ARRAYI_CONTRACT(array); \
return c == ']'; \
} \
, /* no IN_STR */ ) \
, /* no IN_STR & INIT */ ) \
\
M_IF_METHOD(EQUAL, oplist)( \
static inline bool \
+10 -4
View File
@@ -209,6 +209,7 @@
M_GET_INIT_SET oplist(*data, x); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline type * \
M_C(name, _push_new)(list_t v) \
{ \
@@ -218,6 +219,7 @@
M_GET_INIT oplist(*data); \
return data; \
} \
, /* No INIT */) \
\
static inline void \
M_C(name, _pop_back)(type *data, list_t v) \
@@ -618,7 +620,7 @@
} \
, /* no out_str */ ) \
\
M_IF_METHOD(PARSE_STR, oplist)( \
M_IF_METHOD2(PARSE_STR, INIT, oplist)( \
static inline bool \
M_C(name, _parse_str)(list_t list, const char str[], const char **endp) \
{ \
@@ -646,9 +648,9 @@
if (endp) *endp = str; \
return success; \
} \
, /* no parse_str */ ) \
, /* no PARSE_STR & INIT */ ) \
\
M_IF_METHOD(IN_STR, oplist)( \
M_IF_METHOD2(IN_STR, INIT, oplist)( \
static inline bool \
M_C(name, _in_str)(list_t list, FILE *file) \
{ \
@@ -672,7 +674,7 @@
M_C(name, _reverse)(list); \
return c == ']'; \
} \
, /* no in_str */ ) \
, /* no IN_STR & INIT */ ) \
\
M_IF_METHOD(EQUAL, oplist)( \
static inline bool \
@@ -825,6 +827,7 @@
M_GET_INIT_SET oplist(*data, x); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline type * \
M_C(name, _push_back_new)(list_t v) \
{ \
@@ -834,6 +837,7 @@
M_GET_INIT oplist(*data); \
return data; \
} \
, /* No INIT */ ) \
\
static inline void \
M_C(name, _push_back_move)(list_t v, type *x) \
@@ -938,6 +942,7 @@
M_DO_INIT_MOVE (oplist, *data, *x); \
} \
\
M_IF_METHOD(INIT, oplist)( \
static inline type * \
M_C(name, _push_front_new)(list_t v) \
{ \
@@ -947,6 +952,7 @@
M_GET_INIT oplist(*data); \
return data; \
} \
, /* No INIT */) \
\
static inline bool \
M_C(name, _empty_p)(const list_t v) \
+3
View File
@@ -31,6 +31,9 @@ ARRAY_DEF(array_mpz, testobj_t, TESTOBJ_OPLIST)
END_COVERAGE
#define ARRAY_UINT_OPLIST ARRAY_OPLIST(array_uint)
// Array with the minimum number of methods.
ARRAY_DEF(array_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
static void test_uint(void)
{
array_uint_t v;
+5
View File
@@ -35,6 +35,11 @@ LIST_DUAL_PUSH_DEF(list2_mpz, testobj_t, TESTOBJ_OPLIST)
#define LIST_UINT_OPLIST LIST_OPLIST(list_uint)
#define LIST2_DOUBLE_OPLIST LIST_OPLIST(list2_double)
// Array with the minimum number of methods.
LIST_DEF(list_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)))
static void test_uint(void)
{
list_uint_t v;