diff options
| author | Tyge Løvset <[email protected]> | 2022-05-12 15:29:15 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-12 15:29:15 +0200 |
| commit | 7b6fb49407abdd41c2bc1fdb8c84aaabcc3295de (patch) | |
| tree | 01165be591bb08f362bfefd49bccec9548ff2302 | |
| parent | e2fad76fa778dc6bc041e2163615f230ae069f6b (diff) | |
| download | STC-modified-7b6fb49407abdd41c2bc1fdb8c84aaabcc3295de.tar.gz STC-modified-7b6fb49407abdd41c2bc1fdb8c84aaabcc3295de.zip | |
i_keyfrom/i_valfrom no longer used with i_key_bind/i_val_bind. Is considered optional for enabling emplace.
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | docs/cmap_api.md | 4 | ||||
| -rw-r--r-- | examples/vikings.c | 4 | ||||
| -rw-r--r-- | include/stc/template.h | 24 |
4 files changed, 11 insertions, 23 deletions
@@ -315,7 +315,7 @@ Specials: - `i_key_str` - Define key type *cstr* and container i_tag = *str*. It binds type convertion from/to *const char*\*, and the ***cmp***, ***eq***, ***hash***, and ***keydrop*** functions. - `i_key_ssv` - Define key type *cstr* and container i_tag = *ssv*. It binds type convertion from/to *csview*, and its ***cmp***, ***eq***, ***hash***, and ***keydrop*** functions. - `i_key_arcbox TYPE` - Define container key type where TYPE is a smart pointer **carc** or **cbox**. NB: not to be used when defining carc/cbox types themselves. -- `i_key_bind TYPE` - General version of the two above - will auto-bind to standard named functions: *TYPE_clone*, *TYPE_drop*, *TYPE_cmp*, *TYPE_eq*, *TYPE_hash*. Only functions required by the particular container need to be defined (*TYPE_drop* is always used). E.g., only **cmap** and **cset** and smart pointers uses *TYPE_hash* and *TYPE_eq*. **cstack** does not use *TYPE_cmp*. *TYPE_clone* is not used if *#define i_opt c_no_clone* is specified. Likewise, *TYPE_cmp* is not used if *#define i_opt c_no_cmp* is specified. +- `i_key_bind TYPE` - General version of the two above - will auto-bind to standard named functions: *TYPE_clone*, *TYPE_drop*, *TYPE_cmp*, *TYPE_eq*, *TYPE_hash*. If `i_keyraw` is defined, *TYPE_toraw* func. is bound to `i_keyto`. Only functions required by the particular container need to be defined. E.g., only **cmap** and **cset** and smart pointers uses *TYPE_hash* and *TYPE_eq*. **cstack** does not use *TYPE_cmp*. *TYPE_clone* is not used if *#define i_opt c_no_clone* is specified. Likewise, *TYPE_cmp* is not used if *#define i_opt c_no_cmp* is specified. - `i_val_str`, `i_val_bind`, `i_val_arcbox` - Similar rules as for ***key***. **Notes**: diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 67210b6e..02052847 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -378,16 +378,16 @@ static inline RViking Viking_toraw(const Viking* vp) { // With this in place, we define the Viking => int hash map type: #define i_type Vikings +#define i_key_bind Viking #define i_keyraw RViking +#define i_keyfrom Viking_from // optional to enable emplace funcs. #define i_hash(rp) (c_strhash(rp->name) ^ c_strhash(rp->country)) -#define i_key_bind Viking #define i_val int /* i_key_bind macro auto-binds these functions: #define i_hash RViking_hash #define i_cmp RViking_cmp #define i_keyclone Viking_clone - #define i_keyfrom Viking_from // because i_keyraw type is defined #define i_keyto Viking_toraw // because i_keyraw type is defined #define i_keydrop Viking_drop */ diff --git a/examples/vikings.c b/examples/vikings.c index bd4d379f..41f5eb5b 100644 --- a/examples/vikings.c +++ b/examples/vikings.c @@ -37,14 +37,14 @@ static inline RViking Viking_toraw(const Viking* vp) { // With this in place, we define the Viking => int hash map type: #define i_type Vikings #define i_key_bind Viking // key type -#define i_val int // mapped type #define i_keyraw RViking // lookup type +#define i_keyfrom Viking_from // convert from lookup type (enables emplace) #define i_hash(rp) c_strhash(rp->name) ^ c_strhash(rp->country) +#define i_val int // mapped type // i_key_bind auto-binds these functions (unless they are defined by i_...): // i_cmp => RViking_cmp // i_hash => RViking_hash // i_keyclone => Viking_clone -// i_keyfrom => Viking_from // because i_keyraw is defined // i_keyto => Viking_toraw // because i_keyraw is defined // i_keydrop => Viking_drop #include <stc/cmap.h> diff --git a/include/stc/template.h b/include/stc/template.h index 2d01c68f..f5e77238 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -98,6 +98,7 @@ #if defined i_key_str
#define i_key_bind cstr
#define i_keyraw crawstr
+ #define i_keyfrom cstr_from
#ifndef i_tag
#define i_tag str
#endif
@@ -113,10 +114,8 @@ #elif defined i_key_arcbox
#define i_key_bind i_key_arcbox
#define i_keyraw c_paste(i_key_arcbox, _value)
- #define i_keyfrom c_paste(i_key_arcbox, _make)
#define i_keyto c_paste(i_key_arcbox, _get)
#define i_eq c_paste(i_key_arcbox, _value_eq)
- #define _i_no_emplace
#endif
#ifdef i_key_bind
@@ -124,13 +123,8 @@ #ifndef i_keyclone
#define i_keyclone c_paste(i_key, _clone)
#endif
- #ifdef i_keyraw
- #ifndef i_keyfrom
- #define i_keyfrom c_paste(i_key, _from)
- #endif
- #ifndef i_keyto
- #define i_keyto c_paste(i_key, _toraw)
- #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)
@@ -194,6 +188,7 @@ #ifdef i_val_str
#define i_val_bind cstr
#define i_valraw crawstr
+ #define i_valfrom cstr_from
#elif defined i_val_ssv
#define i_val_bind cstr
#define i_valraw csview
@@ -202,9 +197,7 @@ #elif defined i_val_arcbox
#define i_val_bind i_val_arcbox
#define i_valraw c_paste(i_val_arcbox, _value)
- #define i_valfrom c_paste(i_val_arcbox, _make)
#define i_valto c_paste(i_val_arcbox, _get)
- #define _i_no_emplace
#endif
#ifdef i_val_bind
@@ -212,13 +205,8 @@ #ifndef i_valclone
#define i_valclone c_paste(i_val, _clone)
#endif
- #ifdef i_valraw
- #ifndef i_valfrom
- #define i_valfrom c_paste(i_val, _from)
- #endif
- #ifndef i_valto
- #define i_valto c_paste(i_val, _toraw)
- #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)
|
