summaryrefslogtreecommitdiffhomepage
path: root/docs/cmap_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-23 23:55:10 +0100
committerTyge Løvset <[email protected]>2022-12-23 23:55:10 +0100
commitd623c6c85071b9af5d607bb5d9aceceaea05220a (patch)
treef20fc3714f86e1553d1103bed6dc8efefcbd9d6b /docs/cmap_api.md
parent5f57d597cd27aef55adbcb3b452973b0c6e33667 (diff)
downloadSTC-modified-d623c6c85071b9af5d607bb5d9aceceaea05220a.tar.gz
STC-modified-d623c6c85071b9af5d607bb5d9aceceaea05220a.zip
Experimental uppercase macros.
Diffstat (limited to 'docs/cmap_api.md')
-rw-r--r--docs/cmap_api.md32
1 files changed, 16 insertions, 16 deletions
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 520d9046..3946196b 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -127,16 +127,16 @@ bool c_memcmp_eq(const i_keyraw* a, const i_keyraw* b); /
int main()
{
// Create an unordered_map of three strings (that map to strings)
- c_auto (cmap_str, u)
+ c_AUTO (cmap_str, u)
{
- c_forlist (i, cmap_str_raw, {
+ c_FORLIST (i, cmap_str_raw, {
{"RED", "#FF0000"},
{"GREEN", "#00FF00"},
{"BLUE", "#0000FF"}
}) cmap_str_emplace(&u, c_PAIR(i.ref));
// Iterate and print keys and values of unordered map
- c_foreach (n, cmap_str, u) {
+ c_FOREACH (n, cmap_str, u) {
printf("Key:[%s] Value:[%s]\n", cstr_str(&n.ref->first), cstr_str(&n.ref->second));
}
@@ -173,9 +173,9 @@ int main()
{
uint32_t col = 0xcc7744ff;
- c_auto (cmap_id, idnames)
+ c_AUTO (cmap_id, idnames)
{
- c_forlist (i, cmap_id_raw, { {100, "Red"}, {110, "Blue"} })
+ c_FORLIST (i, cmap_id_raw, { {100, "Red"}, {110, "Blue"} })
cmap_id_emplace(&idnames, c_PAIR(i.ref));
// replace existing mapped value:
@@ -187,7 +187,7 @@ int main()
// emplace/insert does nothing if key already exist:
cmap_id_emplace(&idnames, 100, "Green");
- c_foreach (i, cmap_id, idnames)
+ c_FOREACH (i, cmap_id, idnames)
printf("%d: %s\n", i.ref->first, cstr_str(&i.ref->second));
}
}
@@ -214,14 +214,14 @@ typedef struct { int x, y, z; } Vec3i;
int main()
{
// Define map with defered destruct
- c_with (cmap_vi vecs = cmap_vi_init(), cmap_vi_drop(&vecs))
+ c_WITH (cmap_vi vecs = cmap_vi_init(), cmap_vi_drop(&vecs))
{
cmap_vi_insert(&vecs, (Vec3i){100, 0, 0}, 1);
cmap_vi_insert(&vecs, (Vec3i){ 0, 100, 0}, 2);
cmap_vi_insert(&vecs, (Vec3i){ 0, 0, 100}, 3);
cmap_vi_insert(&vecs, (Vec3i){100, 100, 100}, 4);
- c_forpair (vec, num, cmap_vi, vecs)
+ c_FORPAIR (vec, num, cmap_vi, vecs)
printf("{ %3d, %3d, %3d }: %d\n", _.vec->x, _.vec->y, _.vec->z, *_.num);
}
}
@@ -247,14 +247,14 @@ typedef struct { int x, y, z; } Vec3i;
int main()
{
- c_auto (cmap_iv, vecs) // shorthand for c_with with _init(), _drop().
+ c_AUTO (cmap_iv, vecs) // shorthand for c_WITH with _init(), _drop().
{
cmap_iv_insert(&vecs, 1, (Vec3i){100, 0, 0});
cmap_iv_insert(&vecs, 2, (Vec3i){ 0, 100, 0});
cmap_iv_insert(&vecs, 3, (Vec3i){ 0, 0, 100});
cmap_iv_insert(&vecs, 4, (Vec3i){100, 100, 100});
- c_forpair (num, vec, cmap_iv, vecs)
+ c_FORPAIR (num, vec, cmap_iv, vecs)
printf("%d: { %3d, %3d, %3d }\n", *_.num, _.vec->x, _.vec->y, _.vec->z);
}
}
@@ -314,20 +314,20 @@ static inline void Viking_drop(Viking* vk) {
int main()
{
// Use a HashMap to store the vikings' health points.
- c_auto (Vikings, vikings) // uses Vikings_init(), Vikings_drop()
+ c_AUTO (Vikings, vikings) // uses Vikings_init(), Vikings_drop()
{
Vikings_insert(&vikings, (Viking){cstr_lit("Einar"), cstr_lit("Norway")}, 25);
Vikings_insert(&vikings, (Viking){cstr_lit("Olaf"), cstr_lit("Denmark")}, 24);
Vikings_insert(&vikings, (Viking){cstr_lit("Harald"), cstr_lit("Iceland")}, 12);
Vikings_insert(&vikings, (Viking){cstr_lit("Einar"), cstr_lit("Denmark")}, 21);
- c_auto (Viking, lookup) {
+ c_AUTO (Viking, lookup) {
lookup = (Viking){cstr_lit("Einar"), cstr_lit("Norway")};
printf("Lookup: Einar of Norway has %d hp\n\n", *Vikings_at(&vikings, lookup));
}
// Print the status of the vikings.
- c_forpair (vik, hp, Vikings, vikings) {
+ c_FORPAIR (vik, hp, Vikings, vikings) {
printf("%s of %s has %d hp\n", cstr_str(&_.vik->name), cstr_str(&_.vik->country), *_.hp);
}
}
@@ -354,7 +354,7 @@ typedef struct Viking {
} Viking;
static inline void Viking_drop(Viking* v) {
- c_drop(cstr, &v->name, &v->country);
+ c_DROP(cstr, &v->name, &v->country);
}
// Define Viking raw struct with cmp, hash, and convertion functions between Viking and RViking structs:
@@ -397,7 +397,7 @@ static inline RViking Viking_toraw(const Viking* vp) {
int main()
{
- c_auto (Vikings, vikings)
+ c_AUTO (Vikings, vikings)
{
Vikings_emplace(&vikings, (RViking){"Einar", "Norway"}, 20);
Vikings_emplace(&vikings, (RViking){"Olaf", "Denmark"}, 24);
@@ -407,7 +407,7 @@ int main()
Vikings_value *v = Vikings_get_mut(&vikings, (RViking){"Einar", "Norway"});
if (v) v->second += 3; // add 3 hp points to Einar
- c_forpair (vk, hp, Vikings, vikings) {
+ c_FORPAIR (vk, hp, Vikings, vikings) {
printf("%s of %s has %d hp\n", cstr_str(&_.vk->name), cstr_str(&_.vk->country), *_.hp);
}
}