summaryrefslogtreecommitdiffhomepage
path: root/examples/mapmap.c
blob: 38e88712615207744ea94c04ecddd59a8d49e833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

#include <stdio.h>
#include <stc/cmap.h>
#include <stc/cstr.h>

using_cmap_str();
using_cmap_strkey(cfg, cmap_str, cmap_str_del);

int main(void) {
    cmap_cfg config = cmap_INIT;
    cmap_str init = cmap_INIT;
    cmap_str_put(&cmap_cfg_emplace(&config, "user", init).first->second, "name", "Joe");
    cmap_str_put(&cmap_cfg_emplace(&config, "user", init).first->second, "groups", "proj1,proj3");
    cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj1", "Energy");
    cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj2", "Windy");
    cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj3", "Oil");
    cmap_str_put(&cmap_cfg_emplace(&config, "admin", init).first->second, "employees", "2302");

    cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj2", "Wind"); // Update

    c_foreach (i, cmap_cfg, config)
        c_foreach (j, cmap_str, i.get->second)
            printf("%s: %s - %s (%u)\n", i.get->first.str, j.get->first.str, j.get->second.str, i.get->second.bucket_count);

    cmap_cfg_del(&config);
}