From c154cdf46c807563d93bbec333685355b9901629 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 25 Nov 2018 17:52:24 +0100 Subject: [PATCH] Add operator GET_SIZE --- README.md | 1 + m-core.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 8005b6b1..c323267e 100644 --- a/README.md +++ b/README.md @@ -440,6 +440,7 @@ Other documented operators are: * SET\_KEY (container, key, object): Associate in the container the key 'key' to the object 'object'. * GET\_SET\_KEY (container, key) --> &obj: return a pointer to the object within the container associated to the key 'key' or create a new object in the container, associate it to the key 'key' and return its pointer. The pointer to the object remains valid until any modification of the container. The returned pointer cannot be NULL. * ERASE\_KEY (container, key) --> bool: true to erase the object associated to the key 'key' within the container. Return true if successful, false if the key is not found. +* GET\_SIZE (container) --> size_t: return the number of elements in the container. * PUSH(container, obj) : push 'object' into 'container'. How it is pushed is container dependent. * POP(&obj, container) : pop an object from 'container' and save it in '*obj' if obj is not NULL (giving back the ownership to the caller). Which object is popped is container dependent. Undefined behavior is there is no object in the container. * PUSH_MOVE(container, &obj) : push and move the object '*obj' into 'container'. How it is pushed is container dependent but '*obj' is cleared afterward. diff --git a/m-core.h b/m-core.h index e26d6941..f2463c11 100644 --- a/m-core.h +++ b/m-core.h @@ -1793,6 +1793,7 @@ m_core_hash (const void *str, size_t length) #define M_SET_KEY_SET_KEY(a) ,a, #define M_GET_SET_KEY_GET_SET_KEY(a) ,a, #define M_ERASE_KEY_ERASE_KEY(a) ,a, +#define M_GET_SIZE_GET_SIZE(a) ,a, #define M_PUSH_PUSH(a) ,a, #define M_POP_POP(a) ,a, #define M_PUSH_MOVE_PUSH_MOVE(a) ,a, @@ -1869,6 +1870,7 @@ m_core_hash (const void *str, size_t length) #define M_GET_SET_KEY(...) M_GET_METHOD(SET_KEY, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_GET_SET_KEY(...) M_GET_METHOD(GET_SET_KEY, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_ERASE_KEY(...) M_GET_METHOD(ERASE_KEY, M_NO_DEFAULT, __VA_ARGS__) +#define M_GET_GET_SIZE(...) M_GET_METHOD(GET_SIZE, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_PUSH(...) M_GET_METHOD(PUSH, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_POP(...) M_GET_METHOD(POP, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_PUSH_MOVE(...) M_GET_METHOD(PUSH_MOVE, M_NO_DEFAULT, __VA_ARGS__) @@ -1934,6 +1936,7 @@ m_core_hash (const void *str, size_t length) #define M_CALL_SET_KEY(oplist, ...) M_APPLY_API(M_GET_SET_KEY oplist, oplist, __VA_ARGS__) #define M_CALL_GET_SET_KEY(oplist, ...) M_APPLY_API(M_GET_GET_SET_KEY oplist, oplist, __VA_ARGS__) #define M_CALL_ERASE_KEY(oplist, ...) M_APPLY_API(M_GET_ERASE_KEY oplist, oplist, __VA_ARGS__) +#define M_CALL_GET_SIZE(oplist, ...) M_APPLY_API(M_GET_GET_SIZE oplist, oplist, __VA_ARGS__) #define M_CALL_PUSH(oplist, ...) M_APPLY_API(M_GET_PUSH oplist, oplist, __VA_ARGS__) #define M_CALL_POP(oplist, ...) M_APPLY_API(M_GET_POP oplist, oplist, __VA_ARGS__) #define M_CALL_PUSH_MOVE(oplist, ...) M_APPLY_API(M_GET_PUSH_MOVE oplist, oplist, __VA_ARGS__)