26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#include <stdio.h>
#include "object.h"
#include "string.h"
#include "array.h"
#include "map.h"
void
print_map(CFWMap *map)
{
cfw_map_iter_t iter;
cfw_map_iter(map, &iter);
cfw_map_iter_next(&iter);
fputs("{\n", stdout);
while (iter.key != NULL) {
if (iter.obj != NULL)
printf("\t%s = %s\n", cfw_string_c(iter.key),
cfw_string_c(iter.obj));
else
printf("\t%s = NULL\n", cfw_string_c(iter.key));
cfw_map_iter_next(&iter);
}
fputs("}\n", stdout);
}
int
main()
{
CFWString *s[3];
CFWArray *a;
CFWMap *m;
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
-
-
+
-
+
-
+
|
cfw_unref(s[0]);
s[0] = cfw_new(cfw_string, "Hallo");
s[1] = cfw_new(cfw_string, "Welt!");
m = cfw_new(cfw_map, s[0], s[1], NULL);
cfw_unref(s[1]);
puts(cfw_string_c(cfw_map_get(m, s[0])));
print_map(m);
s[1] = cfw_new(cfw_string, "Test");
cfw_map_set(m, s[0], s[1]);
cfw_unref(s[1]);
puts(cfw_string_c(cfw_map_get(m, s[0])));
print_map(m);
cfw_map_set(m, s[0], NULL);
printf("%p\n", cfw_map_get(m, s[0]));
print_map(m);
cfw_unref(s[0]);
cfw_unref(m);
return 0;
}
|