From dbb34b75fd21ff07f2e7452e33227441e9dc5ef5 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Tue, 21 Aug 2018 19:26:18 +0200 Subject: [PATCH] Add method for the operator OUT_STR for the default type. --- m-core.h | 9 +++++++-- m-string.h | 4 ++++ tests/test-mlist.c | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/m-core.h b/m-core.h index 648fb2d3..42331ba5 100644 --- a/m-core.h +++ b/m-core.h @@ -1279,6 +1279,9 @@ #define M_GET_STRING_ARG(string, x, append) \ (append ? string_cat_printf : string_printf) (str, M_PRINTF_FORMAT(x), x) +/* No use of GET_STR if no inclusion of m-string */ +#define M_GET_STR_METHOD_FOR_DEFAULT_TYPE /* */ + #define M_SEPARATE_PER_SEMICOLON(a,b) a ; b /* Generic PRINT macro: print all its inputs regardless of the type @@ -1780,13 +1783,15 @@ m_core_hash (const void *str, size_t length) (INIT(M_INIT_DEFAULT), INIT_SET(M_SET_DEFAULT), SET(M_SET_DEFAULT), \ CLEAR(M_NOTHING_DEFAULT), EQUAL(M_EQUAL_DEFAULT), CMP(M_CMP_DEFAULT), \ INIT_MOVE(M_MOVE_DEFAULT), MOVE(M_MOVE_DEFAULT) , \ - HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) , OUT_STR(M_FPRINT_ARG) ) + HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) , OUT_STR(M_FPRINT_ARG), \ + M_GET_STR_METHOD_FOR_DEFAULT_TYPE) #else #define M_DEFAULT_OPLIST \ (INIT(M_INIT_DEFAULT), INIT_SET(M_SET_DEFAULT), SET(M_SET_DEFAULT), \ CLEAR(M_NOTHING_DEFAULT), EQUAL(M_EQUAL_DEFAULT), CMP(M_CMP_DEFAULT), \ INIT_MOVE(M_MOVE_DEFAULT), MOVE(M_MOVE_DEFAULT) , \ - HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) ) + HASH(M_HASH_DEFAULT), SWAP(M_SWAP_DEFAULT) , \ + M_GET_STR_METHOD_FOR_DEFAULT_TYPE) #endif #define M_CLASSIC_OPLIST(name) ( \ diff --git a/m-string.h b/m-string.h index e961ae94..1210b61d 100644 --- a/m-string.h +++ b/m-string.h @@ -1343,6 +1343,10 @@ namespace m_string { M_APPLY(STRINGI_SELECT3, string_search, string_search_str, \ v, M_IF_DEFAULT1(0, __VA_ARGS__)) +/* Provide GET_STR method to default type */ +#undef M_GET_STR_METHOD_FOR_DEFAULT_TYPE +#define M_GET_STR_METHOD_FOR_DEFAULT_TYPE GET_STR(M_GET_STRING_ARG) + #endif diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 8d24fe3f..2756d217 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -596,6 +596,7 @@ LIST_DEF(list_int, int) static void test_out_default_oplist(void) { + M_LET(str, string_t) M_LET(list, list_int_t) { FILE *f = fopen ("a-mlist.dat", "wt"); if (!f) abort(); @@ -609,6 +610,8 @@ static void test_out_default_oplist(void) assert (fgets(buffer, 1024, f) == buffer); assert (strcmp(buffer, "[3,2]") == 0); fclose(f); + list_int_get_str(str, list, false); + assert (string_equal_str_p(str, "[3,2]")); } } #else