diff options
| author | Tyge Lovset <[email protected]> | 2022-12-20 23:31:51 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-12-20 23:31:51 +0100 |
| commit | 5f57d597cd27aef55adbcb3b452973b0c6e33667 (patch) | |
| tree | dfd59c2fd0e36a6ef37912a9d0cc5a65970f1524 /include/stc/priv | |
| parent | 1763be8c8cbbc0896477fcf924edd4180d1345a9 (diff) | |
| download | STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.tar.gz STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.zip | |
Restructured folders: examples, benchmarks, tests into misc folder.
Diffstat (limited to 'include/stc/priv')
| -rw-r--r-- | include/stc/priv/template.h | 331 |
1 files changed, 331 insertions, 0 deletions
diff --git a/include/stc/priv/template.h b/include/stc/priv/template.h new file mode 100644 index 00000000..b7583e82 --- /dev/null +++ b/include/stc/priv/template.h @@ -0,0 +1,331 @@ +/* MIT License + * + * Copyright (c) 2022 Tyge Løvset, NORCE, www.norceresearch.no + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef _i_template +#define _i_template + +#ifndef STC_TEMPLATE_H_INCLUDED +#define STC_TEMPLATE_H_INCLUDED + #define _cx_self c_PASTE(_i_prefix, i_tag) + #define _cx_memb(name) c_PASTE(_cx_self, name) + #define _cx_deftypes(macro, SELF, ...) c_EXPAND(macro(SELF, __VA_ARGS__)) + #define _cx_value _cx_memb(_value) + #define _cx_key _cx_memb(_key) + #define _cx_mapped _cx_memb(_mapped) + #define _cx_raw _cx_memb(_raw) + #define _cx_rawkey _cx_memb(_rawkey) + #define _cx_iter _cx_memb(_iter) + #define _cx_result _cx_memb(_result) + #define _cx_node _cx_memb(_node) +#endif + +#ifdef i_type + #define i_tag i_type + #undef _i_prefix + #define _i_prefix +#endif + +#ifdef i_size + #define _i_expandby 2 +#else + #define i_size uint32_t + #define _i_expandby 1 +#endif + +#if !(defined i_key || defined i_key_str || defined i_key_ssv || \ + defined i_keyclass || defined i_keyboxed) + #if defined _i_ismap + #error "i_key* must be defined for maps." + #endif + + #if defined i_val_str + #define i_key_str i_val_str + #endif + #if defined i_val_ssv + #define i_key_ssv i_val_ssv + #endif + #if defined i_valboxed + #define i_keyboxed i_valboxed + #endif + #if defined i_valclass + #define i_keyclass i_valclass + #endif + #if defined i_val + #define i_key i_val + #endif + #if defined i_valraw + #define i_keyraw i_valraw + #endif + #if defined i_valclone + #define i_keyclone i_valclone + #endif + #if defined i_valfrom + #define i_keyfrom i_valfrom + #endif + #if defined i_valto + #define i_keyto i_valto + #endif + #if defined i_valdrop + #define i_keydrop i_valdrop + #endif +#endif + +#if c_option(c_no_cmp) + #define i_no_cmp +#endif +#if c_option(c_no_eq) + #define i_no_eq +#endif +#if c_option(c_no_hash) + #define i_no_hash +#endif +#if c_option(c_no_emplace) + #define i_no_emplace +#endif + +#if defined i_key_str + #define i_keyclass cstr + #define i_rawclass crawstr + #define i_keyfrom cstr_from + #ifndef i_tag + #define i_tag str + #endif +#elif defined i_key_ssv + #define i_keyclass cstr + #define i_rawclass csview + #define i_keyfrom cstr_from_sv + #define i_keyto cstr_sv + #define i_eq csview_eq + #ifndef i_tag + #define i_tag ssv + #endif +#elif defined i_keyboxed + #define i_keyclass i_keyboxed + #define i_rawclass c_PASTE(i_keyboxed, _raw) + #define i_keyfrom c_PASTE(i_keyboxed, _from) + #ifndef i_no_eq + #define i_eq c_PASTE(i_keyboxed, _raw_eq) + #endif +#endif + +#if defined i_rawclass + #define i_keyraw i_rawclass +#elif defined i_keyclass && !defined i_keyraw + #define i_rawclass i_key +#endif + +#ifdef i_keyclass + #define i_key i_keyclass + #ifndef i_keyclone + #define i_keyclone c_PASTE(i_key, _clone) + #endif + #if !defined i_keyto && defined i_keyraw + #define i_keyto c_PASTE(i_key, _toraw) + #endif + #ifndef i_keydrop + #define i_keydrop c_PASTE(i_key, _drop) + #endif +#endif + +#ifdef i_rawclass + #if !defined i_cmp && !defined i_no_cmp + #define i_cmp c_PASTE(i_keyraw, _cmp) + #endif + #if !defined i_hash && !defined i_no_hash + #define i_hash c_PASTE(i_keyraw, _hash) + #endif +#endif + +#if !defined i_key + #error "no i_key or i_val defined" +#elif defined i_keyraw ^ defined i_keyto + #error "both i_***raw and i_***to must be defined, if any" +#elif defined i_keyfrom && !defined i_keyraw + #error "i_***from defined without i_***raw" +#elif defined i_from || defined i_drop + #error "i_from / i_drop not supported. Define i_keyfrom/i_valfrom and/or i_keydrop/i_valdrop instead" +#endif + +#ifndef i_tag + #define i_tag i_key +#endif +#if c_option(c_no_clone) || (!defined i_keyclone && (defined i_keydrop || defined i_keyraw)) + #define i_no_clone +#endif +#ifndef i_keyraw + #define i_keyraw i_key +#endif +#ifndef i_keyfrom + #define i_keyfrom c_default_clone +#else + #define _i_has_from +#endif +#ifndef i_keyto + #define i_keyto c_default_toraw +#endif +#ifndef i_keyclone + #define i_keyclone c_default_clone +#endif +#ifndef i_keydrop + #define i_keydrop c_default_drop +#endif + +// i_eq, i_less, i_cmp +#if !defined i_eq && (defined i_cmp || defined i_less) + #define i_eq(x, y) !(i_cmp(x, y)) +#elif !defined i_eq + #define i_eq c_default_eq +#endif +#if defined i_less && defined i_cmp + #error "Only one of i_less and i_cmp may be defined" +#elif !defined i_less && !defined i_cmp + #define i_less c_default_less +#elif !defined i_less + #define i_less(x, y) (i_cmp(x, y)) < 0 +#endif +#ifndef i_cmp + #define i_cmp(x, y) (i_less(y, x)) - (i_less(x, y)) +#endif + +#ifndef i_hash + #define i_hash c_default_hash +#endif + +#if defined _i_ismap // ---- process cmap/csmap value i_val, ... ---- + +#ifdef i_val_str + #define i_valclass cstr + #define i_valraw crawstr + #define i_valfrom cstr_from +#elif defined i_val_ssv + #define i_valclass cstr + #define i_valraw csview + #define i_valfrom cstr_from_sv + #define i_valto cstr_sv +#elif defined i_valboxed + #define i_valclass i_valboxed + #define i_valraw c_PASTE(i_valboxed, _raw) + #define i_valfrom c_PASTE(i_valboxed, _from) +#endif + +#ifdef i_valclass + #define i_val i_valclass + #ifndef i_valclone + #define i_valclone c_PASTE(i_val, _clone) + #endif + #if !defined i_valto && defined i_valraw + #define i_valto c_PASTE(i_val, _toraw) + #endif + #ifndef i_valdrop + #define i_valdrop c_PASTE(i_val, _drop) + #endif +#endif + +#ifndef i_val + #error "i_val* must be defined for maps" +#endif + +#if !defined i_valclone && (defined i_valdrop || defined i_valraw) + #define i_no_clone +#endif +#ifndef i_valraw + #define i_valraw i_val +#endif +#ifndef i_valfrom + #define i_valfrom c_default_clone +#else + #define _i_has_from +#endif +#ifndef i_valto + #define i_valto c_default_toraw +#endif +#ifndef i_valclone + #define i_valclone c_default_clone +#endif +#ifndef i_valdrop + #define i_valdrop c_default_drop +#endif + +#endif // !_i_ismap + +#ifndef i_val + #define i_val i_key +#endif +#ifndef i_valraw + #define i_valraw i_keyraw +#endif +#ifndef _i_has_from + #define i_no_emplace +#endif + +#else // ============================================================ + +#undef i_type +#undef i_tag +#undef i_imp +#undef i_opt +#undef i_less +#undef i_cmp +#undef i_eq +#undef i_hash +#undef i_rawclass +#undef i_capacity +#undef i_size + +#undef i_val +#undef i_val_str +#undef i_val_ssv +#undef i_valboxed +#undef i_valclass +#undef i_valraw +#undef i_valclone +#undef i_valfrom +#undef i_valto +#undef i_valdrop + +#undef i_key +#undef i_key_str +#undef i_key_ssv +#undef i_keyboxed +#undef i_keyclass +#undef i_keyraw +#undef i_keyclone +#undef i_keyfrom +#undef i_keyto +#undef i_keydrop + +#undef i_header +#undef i_implement +#undef i_static +#undef i_extern + +#undef i_no_cmp +#undef i_no_eq +#undef i_no_hash +#undef i_no_clone +#undef i_no_emplace + +#undef _i_prefix +#undef _i_expandby +#undef _i_has_from +#undef _i_template +#endif |
