diff options
| author | _Tradam <[email protected]> | 2023-09-08 01:29:47 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-08 01:29:47 +0000 |
| commit | 3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch) | |
| tree | afbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/mapmap.c | |
| parent | 0841165881871ee01b782129be681209aeed2423 (diff) | |
| parent | 1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff) | |
| download | STC-modified-modified.tar.gz STC-modified-modified.zip | |
Diffstat (limited to 'misc/examples/mapmap.c')
| -rw-r--r-- | misc/examples/mapmap.c | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/misc/examples/mapmap.c b/misc/examples/mapmap.c deleted file mode 100644 index 668da5de..00000000 --- a/misc/examples/mapmap.c +++ /dev/null @@ -1,64 +0,0 @@ -// create a structure like: std::map<std::string, std::map<std::string, std::string>>: - -#include <stc/cstr.h> - -// People: std::map<std::string, std::string> -#define i_type People -#define i_key_str // name -#define i_val_str // email -#define i_keydrop(p) (printf("kdrop: %s\n", cstr_str(p)), cstr_drop(p)) // override -#include <stc/cmap.h> - -// Departments: std::map<std::string, People> -#define i_type Departments -#define i_key_str // dep. name -#define i_valclass People -#include <stc/cmap.h> - - -void add(Departments* deps, const char* name, const char* email, const char* dep) -{ - People *people = &Departments_emplace(deps, dep, People_init()).ref->second; - People_emplace_or_assign(people, name, email); -} - -int contains(Departments* map, const char* name) -{ - int count = 0; - c_foreach (i, Departments, *map) - if (People_contains(&i.ref->second, name)) - ++count; - return count; -} - -int main(void) -{ - Departments map = {0}; - - add(&map, "Anna Kendro", "[email protected]", "Support"); - add(&map, "Terry Dane", "[email protected]", "Development"); - add(&map, "Kik Winston", "[email protected]", "Finance"); - add(&map, "Nancy Drew", "[email protected]", "Development"); - add(&map, "Nick Denton", "[email protected]", "Finance"); - add(&map, "Stan Whiteword", "[email protected]", "Marketing"); - add(&map, "Serena Bath", "[email protected]", "Support"); - add(&map, "Patrick Dust", "[email protected]", "Finance"); - add(&map, "Red Winger", "[email protected]", "Marketing"); - add(&map, "Nick Denton", "[email protected]", "Support"); - add(&map, "Colin Turth", "[email protected]", "Support"); - add(&map, "Dennis Kay", "[email protected]", "Marketing"); - add(&map, "Anne Dickens", "[email protected]", "Development"); - - c_foreach (i, Departments, map) - c_forpair (name, email, People, i.ref->second) - printf("%s: %s - %s\n", cstr_str(&i.ref->first), cstr_str(_.name), cstr_str(_.email)); - puts(""); - - printf("found Nick Denton: %d\n", contains(&map, "Nick Denton")); - printf("found Patrick Dust: %d\n", contains(&map, "Patrick Dust")); - printf("found Dennis Kay: %d\n", contains(&map, "Dennis Kay")); - printf("found Serena Bath: %d\n", contains(&map, "Serena Bath")); - puts("Done"); - - Departments_drop(&map); -} |
