From eb704d8c97c3ca14a1a5406ec90de4d200355cc2 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 6 Sep 2021 07:16:56 +0200 Subject: More refinements --- include/stc/ccommon.h | 9 +++------ include/stc/cvec.h | 2 +- include/stc/template.h | 43 ++++++++++++++++++------------------------- 3 files changed, 22 insertions(+), 32 deletions(-) (limited to 'include') diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index a8098e43..6899b1b5 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -39,7 +39,9 @@ #endif #define STC_INLINE static inline -#if defined(STC_HEADER) || defined(STC_IMPLEMENTATION) +#if !defined(STC_HEADER) && (defined(STC_IMPLEMENTATION) || defined(i_IMP)) +# error STC_HEADER should be defined when STC_IMPLEMENTATION or i_IMP is used +#elif defined(STC_HEADER) && (defined(STC_IMPLEMENTATION) || defined(i_IMP)) # define STC_API extern # define STC_DEF # define STC_LIBRARY_ONLY(...) __VA_ARGS__ @@ -110,11 +112,6 @@ #define c_default_del(ptr) ((void) (ptr)) -#define c_true(...) __VA_ARGS__ -#define c_false(...) -#define _c_deftypes_ c_false -#define _c_deftypes_i_FWD c_true - /* Generic algorithms */ #define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__) diff --git a/include/stc/cvec.h b/include/stc/cvec.h index daa95170..9491bacb 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -31,7 +31,7 @@ struct cvec_Rep_ { size_t size, cap; void* data[]; }; #define cvec_rep_(self) c_container_of((self)->data, struct cvec_Rep_, data) #endif // CVEC_H_INCLUDED -#define i_CNT cvec +#define i_MODULE cvec #include "template.h" #if !defined i_FWD diff --git a/include/stc/template.h b/include/stc/template.h index 46059bf9..eb770c9a 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -1,19 +1,10 @@ #ifndef STC_TEMPLATE_INCLUDED #define STC_TEMPLATE_INCLUDED -#if defined I_TAG - #define i_TAG I_TAG - #define i_IMP -#endif #if defined f_TAG #define i_TAG f_TAG #define i_FWD #endif -#if defined F_TAG - #define i_TAG F_TAG - #define i_FWD - #define i_IMP -#endif #if defined i_KEY_str #define i_KEY cstr @@ -36,27 +27,28 @@ #define i_VALRAW const char* #endif -#if !defined i_TAG && (defined i_KEY_str || defined i_VAL_str) +#if !defined i_TAG && defined i_KEY_str #define i_TAG str -#endif -#if !defined i_TAG && defined i_KEY +#elif !defined i_TAG && defined i_KEY #define i_TAG i_KEY +#elif !defined i_TAG && defined i_VAL_str + #define i_TAG str #elif !defined i_TAG && defined i_VAL #define i_TAG i_VAL #endif -#define Self c_PASTE3(i_CNT, _, i_TAG) +#define Self c_PASTE3(i_MODULE, _, i_TAG) #define cx_memb(name) c_PASTE(Self, name) #define cx_value_t cx_memb(_value_t) #define cx_rawvalue_t cx_memb(_rawvalue_t) #define cx_iter_t cx_memb(_iter_t) -#if defined i_VALTO ^ defined i_VALRAW - #error i_VALTO and i_VALRAW must both be defined +#if (defined i_VALTO ^ defined i_VALRAW) || (defined i_VALRAW && !defined i_VALFROM) + #error if i_VALRAW defined, both i_VALFROM and i_VALTO must be defined #endif -#if defined i_KEYTO ^ defined i_KEYRAW - #error i_KEYTO and i_KEYRAW must both be defined +#if (defined i_KEYTO ^ defined i_KEYRAW) || (defined i_KEYRAW && !defined i_KEYFROM) + #error if i_KEYRAW defined, both i_KEYFROM and i_KEYTO must be defined #endif #if defined i_KEY @@ -75,6 +67,14 @@ #define i_KEYRAW i_KEY #define i_KEYTO c_default_toraw #endif + #if !defined i_EQU && defined i_CMP + #define i_EQU !i_CMP + #elif !defined i_EQU + #define i_EQU c_default_equals + #endif + #ifndef i_HASH + #define i_HASH c_default_hash + #endif #endif #if !defined i_VALFROM && defined i_VALDEL @@ -86,19 +86,12 @@ #define i_VALRAW i_VAL #define i_VALTO c_default_toraw #endif - #ifndef i_KEYDEL #define i_KEYDEL c_default_del #endif #ifndef i_VALDEL #define i_VALDEL c_default_del #endif -#ifndef i_EQU - #define i_EQU c_default_equals -#endif -#ifndef i_HASH - #define i_HASH c_default_hash -#endif #ifndef i_CMP #define i_CMP c_default_compare #endif @@ -112,7 +105,7 @@ #else // ------------------------------------------------------- -#undef i_CNT +#undef i_MODULE #undef i_TAG #undef f_TAG #undef i_IMP -- cgit v1.2.3