From 1930bdeac12614cd9ac6955cbe2bb7d0bbb44eaa Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 16 Sep 2017 08:31:22 +0200 Subject: [PATCH] _DEF macros checks if a global oplist is register if there is no one given in the macro call. If it founds one, it will be it instead of M_DEFAULT_OPLIST. --- example/ex-list01.c | 22 ++++++++++++---------- m-array.h | 23 ++++++++++++++--------- m-buffer.h | 15 +++++++++------ m-core.h | 3 ++- m-deque.h | 18 +++++++++++------- m-i-list.h | 20 ++++++++++++-------- m-i-shared.h | 20 ++++++++++++-------- m-list.h | 18 +++++++++++------- m-rbtree.h | 24 +++++++++++++++--------- m-shared.h | 40 +++++++++++++++++++++++----------------- m-snapshot.h | 22 ++++++++++++++-------- 11 files changed, 135 insertions(+), 90 deletions(-) diff --git a/example/ex-list01.c b/example/ex-list01.c index d4f2f2b7..25376c94 100644 --- a/example/ex-list01.c +++ b/example/ex-list01.c @@ -9,22 +9,24 @@ #include "m-algo.h" // Let's create a list of string. -LIST_DEF(list_string, string_t, STRING_OPLIST) +LIST_DEF(list_string, string_t) -// Let's define its oplist with a shorter name -#define ASTR_OPLIST LIST_OPLIST(list_string, STRING_OPLIST) +// Let's register the oplist globally so that other m*lib macros +// can get the oplist without us giving it explictly to them. +#define M_OPL_list_string_t() LIST_OPLIST(list_string, STRING_OPLIST) // Let's define some basic algorithms over this list of string. -ALGO_DEF(astring, ASTR_OPLIST) +ALGO_DEF(astring, M_OPL_list_string_t()) int main(void) { // Let's create a variable named 'grow' which is a list of string_t // This variable is only defined within the associated '{' '}' block. - // You can also define the variable (list_string_t) and use explicitely + // The constructor/destructor of the variable will be called within this block + // You can also define the variable (list_string_t) and use explicitly // its constructor (list_string_init) / destructor (list_string_clear). - M_LET (grow, ASTR_OPLIST) - M_LET (tmpstr, STRING_OPLIST) { // And let's create also a string_t + M_LET (grow, list_string_t) + M_LET (tmpstr, string_t) { // And let's create also a string_t // add string elements to the list list_string_push_back (grow, STRING_CTE("AB")); @@ -42,7 +44,7 @@ int main(void) // Let's iterate over each element of the list // using the macro for iteration over a container. printf ("Using macro EACH :\n"); - for M_EACH (item, grow, ASTR_OPLIST) { + for M_EACH (item, grow, list_string_t) { printf ("Item = "); string_fputs (stdout, *item); printf ("\n"); @@ -66,14 +68,14 @@ int main(void) // We can even sort the list. astring_sort(grow); - for M_EACH (item, grow, ASTR_OPLIST) { + for M_EACH (item, grow, list_string_t) { printf ("Sort Item = %s\n", string_get_cstr(*item) ); } // Split a string into a list. string_set_str(tmpstr, "HELLO;JOHN;HOW;ARE;YOU"); astring_split(grow, tmpstr, ';'); - for M_EACH (item, grow, ASTR_OPLIST) { + for M_EACH (item, grow, list_string_t) { printf ("Split Item = %s\n", string_get_cstr(*item) ); } diff --git a/m-array.h b/m-array.h index 8ebf153d..bfe548cc 100644 --- a/m-array.h +++ b/m-array.h @@ -35,21 +35,23 @@ /* Define an array of a given type. USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */ #define ARRAY_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (ARRAYI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name,_t), M_C(name,_it_t) ), \ - ARRAYI_DEF2(name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t))) + ARRAYI_DEF(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_C(name,_t), M_C(name,_it_t)))) /* Define the oplist of an array of type. USAGE: ARRAY_OPLIST(name[, oplist of the type]) */ -#define ARRAY_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (ARRAYI_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - ARRAYI_OPLIST(__VA_ARGS__ )) +#define ARRAY_OPLIST(...) \ + ARRAYI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ -#define ARRAYI_OPLIST(name, oplist) \ +#define ARRAYI_OPLIST(arg) ARRAYI_OPLIST2 arg + +#define ARRAYI_OPLIST2(name, oplist) \ (INIT(M_C(name, _init)) \ ,INIT_SET(M_C(name, _init_set)) \ ,SET(M_C(name, _set)) \ @@ -95,10 +97,13 @@ // Compute alloc from the requested size. // NOTE: EXPECTED_SIZE can be overloaded by the given oplist. -// TODO: Factor 2 shall be configurable. +// TODO: Factor 2 should be configurable. Maybe this macro shall be the operator itself! #define ARRAYI_INC_ALLOC_SIZE(oplist, n) \ (M_MAX(M_GET_EXPECTED_SIZE oplist, (n))*2) +// Deferred evaluation. +#define ARRAYI_DEF(arg) ARRAYI_DEF2 arg + // Internal definition. #define ARRAYI_DEF2(name, type, oplist, array_t, array_it_t) \ \ diff --git a/m-buffer.h b/m-buffer.h index 2f86d6bf..89903714 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -46,18 +46,18 @@ typedef enum { /* Define a buffer. USAGE: BUFFER_DEF(name, type, size_of_buffer_or_0, policy[, oplist]) */ #define BUFFER_DEF(name, type, m_size, ... ) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (BUFFERI_DEF2(name, type, m_size,__VA_ARGS__, (), M_C(name,_t)), \ - BUFFERI_DEF2(name, type, m_size,__VA_ARGS__, M_C(name,_t))) + BUFFERI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, type, m_size,__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__), M_C(name,_t)), \ + (name, type, m_size,__VA_ARGS__, M_C(name,_t)))) /* Define a queue for Many Producer Many Consummer Much faster than queue of BUFFER_DEF in heavy communication scenario Size of created queue can only a power of 2. */ #define QUEUE_MPMC_DEF(name, type, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (QUEUEI_MPMC_DEF2(name, type, __VA_ARGS__, (), M_C(name,_t)), \ - QUEUEI_MPMC_DEF2(name, type, __VA_ARGS__, M_C(name,_t))) + QUEUEI_MPMC_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, type, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__), M_C(name,_t)), \ + (name, type, __VA_ARGS__, M_C(name,_t)))) @@ -86,6 +86,8 @@ typedef enum { assert (buffer->idx_cons <= BUFFERI_SIZE(size)); \ }while (0) +#define BUFFERI_DEF(arg) BUFFERI_DEF2 arg + #define BUFFERI_DEF2(name, type, m_size, policy, oplist, buffer_t) \ \ typedef struct M_C(name, _s) { \ @@ -319,6 +321,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ * size of queue is always a power of 2 * no overwriting. */ +#define QUEUEI_MPMC_DEF(arg) QUEUEI_MPMC_DEF2 arg #define QUEUEI_MPMC_DEF2(name, type, policy, oplist, buffer_t) \ \ diff --git a/m-core.h b/m-core.h index 65708adf..0101eb74 100644 --- a/m-core.h +++ b/m-core.h @@ -30,6 +30,7 @@ #include #include #include +#include /***************************************************************/ @@ -1075,7 +1076,7 @@ m_core_hash (const void *str, size_t length) #define M_GLOBAL_OPLIST_OR_DEF(a) \ M_IF( M_PARENTHESIS_P(a))(M_DEFAULT_OPLIST, M_GLOBAL_OPLIST_OR_DEF_ELSE(a)) #define M_GLOBAL_OPLIST_OR_DEF_ELSE(a) M_GLOBAL_OPLIST_OR_DEF_ELSE2(M_C(M_OPL_, a)()) -#define M_GLOBAL_OPLIST_OR_DEF_ELSE2(op) M_IF( M_OPLIST_P(op))(op, M_DEFAULT_OPLIST)) +#define M_GLOBAL_OPLIST_OR_DEF_ELSE2(op) M_IF( M_OPLIST_P(op))(op, M_DEFAULT_OPLIST) /************************************************************/ diff --git a/m-deque.h b/m-deque.h index a944a204..cd1bcb1b 100644 --- a/m-deque.h +++ b/m-deque.h @@ -36,17 +36,17 @@ /* Define a deque of a given type. USAGE: DEQUE_DEF(name, type [, oplist_of_the_type]) */ #define DEQUE_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (DEQUEI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t) ), \ - DEQUEI_DEF2(name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t) )) + DEQUEI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t) ), \ + (name, __VA_ARGS__, M_C(name,_t), M_C(name,_it_t), M_C(name, _node_t) ))) /* Define the oplist of a deque of type. USAGE: DEQUE_OPLIST(name[, oplist of the type]) */ #define DEQUE_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (DEQUEI_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - DEQUEI_OPLIST(__VA_ARGS__ )) + DEQUEI_OPLIST (M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_DEFAULT_OPLIST ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ @@ -65,6 +65,8 @@ (d)->back->index - (d)->front->index == (d)->count); \ } while (0) +#define DEQUEI_DEF(arg) DEQUEI_DEF2 arg + #define DEQUEI_DEF2(name, type, oplist, deque_t, it_t, node_t) \ \ typedef struct M_C(name, _node_s) { \ @@ -710,7 +712,9 @@ , /* no IN_STR */ ) \ -#define DEQUEI_OPLIST(name, oplist) \ +#define DEQUEI_OPLIST(arg) DEQUEI_OPLIST2 arg + +#define DEQUEI_OPLIST2(name, oplist) \ (INIT(M_C(name, _init)) \ ,INIT_SET(M_C(name, _init_set)) \ ,SET(M_C(name, _set)) \ diff --git a/m-i-list.h b/m-i-list.h index a65a3e63..d61e5406 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -43,16 +43,16 @@ /* Define a list of a given type. LIST_DEF(name, type [, oplist_of_the_type]) */ #define ILIST_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (ILISTI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name, _t), M_C(name, _it_t) ), \ - ILISTI_DEF2(name, __VA_ARGS__, M_C(name, _t), M_C(name, _it_t) )) + ILISTI_DEF(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_C(name, _t), M_C(name, _it_t) ))) /* Define the oplist of a ilist of type. USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */ -#define ILIST_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (ILISTI_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - ILISTI_OPLIST(__VA_ARGS__ )) +#define ILIST_OPLIST(...) \ + ILISTI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ @@ -63,8 +63,10 @@ typedef struct ilist_head_s { struct ilist_head_s *prev; } ilist_head_t; +#define ILISTI_OPLIST(arg) ILISTI_OPLIST2 arg + /* Define the oplist of an ilist of type */ -#define ILISTI_OPLIST(name,oplist) \ +#define ILISTI_OPLIST2(name,oplist) \ (INIT(M_C(name, _init)), \ CLEAR(M_C(name, _clear)), \ TYPE(M_C(name,_t)), \ @@ -96,6 +98,8 @@ typedef struct ilist_head_s { assert(list->name.prev->next == &list->name); \ } while (0) +#define ILISTI_DEF(arg) ILISTI_DEF2 arg + #define ILISTI_DEF2(name, type, oplist, list_t, list_it_t) \ \ typedef struct M_C(name, _s) { \ diff --git a/m-i-shared.h b/m-i-shared.h index bd0c64da..d2e0ffce 100644 --- a/m-i-shared.h +++ b/m-i-shared.h @@ -35,9 +35,9 @@ /* Define the oplist of a intrusive shared pointer. USAGE: ISHARED_OPLIST(name [, oplist_of_the_type]) */ #define ISHARED_PTR_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (ISHAREDI_PTR_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - ISHAREDI_PTR_OPLIST(__VA_ARGS__ )) + ISHAREDI_PTR_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (__VA_ARGS__ ))) /* Interface to add to a structure to allow intrusive support. name: name of the intrusive shared pointer. @@ -48,15 +48,17 @@ /* Define the intrusive shared pointer type and its static inline functions. USAGE: ISHARED_PTR_DEF(name[, oplist]) */ -#define ISHARED_PTR_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (ISHAREDI_PTR_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST ), \ - ISHAREDI_PTR_DEF2(name, __VA_ARGS__ )) +#define ISHARED_PTR_DEF(name, ...) \ + ISHAREDI_PTR_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (name, __VA_ARGS__ ))) /********************************** INTERNAL ************************************/ -#define ISHAREDI_PTR_OPLIST(name, oplist) ( \ +#define ISHAREDI_PTR_OPLIST(arg) ISHAREDI_PTR_OPLIST2 arg + +#define ISHAREDI_PTR_OPLIST2(name, oplist) ( \ INIT(M_INIT_DEFAULT), \ INIT_SET(M_C(name, _init_set2) M_IPTR), \ SET(M_C(name, _set) M_IPTR), \ @@ -70,6 +72,8 @@ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) +#define ISHAREDI_PTR_DEF(arg) ISHAREDI_PTR_DEF2 arg + #define ISHAREDI_PTR_DEF2(name, type, oplist) \ \ typedef type *M_C(name,_t); \ diff --git a/m-list.h b/m-list.h index 860b8fd2..3599f53f 100644 --- a/m-list.h +++ b/m-list.h @@ -35,21 +35,23 @@ /* Define a list of a given type. USAGE: LIST_DEF(name, type [, oplist_of_the_type]) */ #define LIST_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (LISTI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name,_t), M_C(name, _it_t) ), \ - LISTI_DEF2(name, __VA_ARGS__, M_C(name,_t), M_C(name, _it_t) )) + LISTI_DEF(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_C(name,_t), M_C(name, _it_t) ))) /* Define the oplist of a list of type. USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */ #define LIST_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (LISTI_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - LISTI_OPLIST(__VA_ARGS__ )) + LISTI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ -#define LISTI_OPLIST(name, oplist) \ +#define LISTI_OPLIST(arg) LISTI_OPLIST2 arg + +#define LISTI_OPLIST2(name, oplist) \ (INIT(M_C(name, _init)), \ INIT_SET(M_C(name, _init_set)), \ SET(M_C(name, _set)), \ @@ -85,6 +87,8 @@ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) +#define LISTI_DEF(arg) LISTI_DEF2 arg + #define LISTI_DEF2(name, type, oplist, list_t, list_it_t) \ \ typedef struct M_C(name, _s) { \ diff --git a/m-rbtree.h b/m-rbtree.h index f67dcc11..b6727dda 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -36,23 +36,26 @@ /* Define a Red/Black binary tree of a given type. USAGE: RBTREE_DEF(name, type [, oplist_of_the_type]) */ #define RBTREE_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (RBTREEI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, \ + RBTREEI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__), \ M_C(name, _t), struct M_C(name, _node_s), M_C(name, _it_t)), \ - RBTREEI_DEF2(name, __VA_ARGS__ , \ - M_C(name, _t), struct M_C(name, _node_s), M_C(name, _it_t))) + (name, __VA_ARGS__ , \ + M_C(name, _t), struct M_C(name, _node_s), M_C(name, _it_t)))) /* Define the oplist of a rbtree of type. USAGE: RBTREE_OPLIST(name [, oplist_of_the_type]) */ -#define RBTREE_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (RBTREEI_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - RBTREEI_OPLIST(__VA_ARGS__ )) +#define RBTREE_OPLIST(...) \ + RBTREEI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ -#define RBTREEI_OPLIST(name, oplist) \ +// deferred evaluation +#define RBTREEI_OPLIST(arg) RBTREEI_OPLIST2 arg + +#define RBTREEI_OPLIST2(name, oplist) \ (INIT(M_C(name, _init)), \ INIT_SET(M_C(name, _init_set)), \ SET(M_C(name, _set)), \ @@ -122,6 +125,9 @@ typedef enum { && ((node)->child[1] == NULL || RBTREEI_IS_BLACK(node->child[1])))); \ } while (0) +// deferred evaluation +#define RBTREEI_DEF(arg) RBTREEI_DEF2 arg + #define RBTREEI_DEF2(name, type, oplist, tree_t, node_t, tree_it_t) \ \ node_t { \ diff --git a/m-shared.h b/m-shared.h index 435344da..55ad12b7 100644 --- a/m-shared.h +++ b/m-shared.h @@ -35,34 +35,40 @@ /* Define the oplist of a shared pointer. USAGE: SHARED_OPLIST(name [, oplist_of_the_type]) */ -#define SHARED_PTR_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (SHAREDI_PTR_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - SHAREDI_PTR_OPLIST(__VA_ARGS__ )) +#define SHARED_PTR_OPLIST(...) \ + SHAREDI_PTR_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + _OPLIST(__VA_ARGS__ ))) /* Define shared pointer and its function. USAGE: SHARED_PTR_DEF(name[, oplist]) */ -#define SHARED_PTR_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (SHAREDI_PTR_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST ), \ - SHAREDI_PTR_DEF2(name, __VA_ARGS__ )) +#define SHARED_PTR_DEF(name, ...) \ + SHAREDI_PTR_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (name, __VA_ARGS__ ))) /********************************** INTERNAL ************************************/ -#define SHAREDI_PTR_OPLIST(name, oplist) ( \ - INIT(M_C(name, _init)), \ - CLEAR(M_C(name, _clear)), \ - INIT_SET(M_C(name, _init_set)), \ - SET(M_C(name, _set)) \ - INIT_MOVE(M_C(name, _init_move)), \ - CLEAN(M_C(name, _clean)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)) \ +// deferred +#define SHAREDI_PTR_OPLIST(arg) SHAREDI_PTR_OPLIST2 arg + +#define SHAREDI_PTR_OPLIST2(name, oplist) ( \ + INIT(M_C(name, _init)), \ + CLEAR(M_C(name, _clear)), \ + INIT_SET(M_C(name, _init_set)), \ + SET(M_C(name, _set)) \ + INIT_MOVE(M_C(name, _init_move)), \ + CLEAN(M_C(name, _clean)), \ + MOVE(M_C(name, _move)), \ + SWAP(M_C(name, _swap)) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) +// deferred +#define SHAREDI_PTR_DEF(arg) SHAREDI_PTR_DEF2 arg + #define SHAREDI_PTR_DEF2(name, type, oplist) \ \ typedef struct M_C(name, _s){ \ diff --git a/m-snapshot.h b/m-snapshot.h index ac4feb44..f3231c1e 100644 --- a/m-snapshot.h +++ b/m-snapshot.h @@ -32,23 +32,26 @@ /* Define a snapshot and it function USAGE: SNAPSHOT_DEF(name, type[, oplist]) */ -#define SNAPSHOT_DEF(name, ...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (SNAPSHOTI_DEF2(name, __VA_ARGS__, () ), \ - SNAPSHOTI_DEF2(name, __VA_ARGS__ )) +#define SNAPSHOT_DEF(name, ...) \ + SNAPSHOTI_DEF(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (name, __VA_ARGS__ ))) /* Define the oplist of a snapshot. USAGE: SNAPSHOT_OPLIST(name[, oplist]) */ #define SNAPSHOT_OPLIST(...) \ - M_IF_NARGS_EQ1(__VA_ARGS__) \ - (SNAPSHOTI_OPLIST(__VA_ARGS__, M_DEFAULT_OPLIST ), \ - SNAPSHOTI_OPLIST(__VA_ARGS__ )) + SNAPSHOTI_OPLIST(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((__VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__) ), \ + (__VA_ARGS__ ))) /********************************** INTERNAL ************************************/ +// deferred +#define SNAPSHOTI_OPLIST(arg) SNAPSHOTI_OPLIST arg + /* Define the oplist of a snapshot */ -#define SNAPSHOTI_OPLIST(name, oplist) \ +#define SNAPSHOTI_OPLIST2(name, oplist) \ (INIT(M_C(name, _init)), \ INIT_SET(M_C(name, _init_set)), \ SET(M_C(name, _set)), \ @@ -89,6 +92,9 @@ SNAPSHOTI_FLAGS_CONTRACT(f); \ } while (0) +//defered +#define SNAPSHOTI_DEF(arg) SNAPSHOTI_DEF2 arg + #define SNAPSHOTI_DEF2(name, type, oplist) \ \ typedef struct M_C(name, _s) { \