summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/mapmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/mapmap.c')
-rw-r--r--misc/examples/mapmap.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/misc/examples/mapmap.c b/misc/examples/mapmap.c
index cad5e462..668da5de 100644
--- a/misc/examples/mapmap.c
+++ b/misc/examples/mapmap.c
@@ -7,24 +7,13 @@
#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/csmap.h>
+#include <stc/cmap.h>
// Departments: std::map<std::string, People>
#define i_type Departments
#define i_key_str // dep. name
#define i_valclass People
-// i_key_str implies:
-// #define i_tag str
-// #define i_key cstr
-// #define i_keyclone cstr_clone
-// #define i_keydrop cstr_drop
-// #define i_cmp cstr_cmp
-// #define i_hash cstr_hash
-// i_valclass implies:
-// #define i_val People
-// #define i_valclone People_clone
-// #define i_valdrop People_drop
-#include <stc/csmap.h>
+#include <stc/cmap.h>
void add(Departments* deps, const char* name, const char* email, const char* dep)
@@ -44,31 +33,32 @@ int contains(Departments* map, const char* name)
int main(void)
{
- c_auto (Departments, map)
- {
- 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");
+ Departments map = {0};
- 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("");
+ 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");
- 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");
- }
+ 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);
}