39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/autoc/collection/set.rb', line 39
def write_impls(stream, define)
super
stream << %$
static #{element.type_ref} #{itGetRef}(#{it_ref});
static int #{containsAllOf}(#{type_ref} self, #{type_ref} other) {
#{it} it;
#{itCtor}(&it, self);
while(#{itMove}(&it)) {
if(!#{contains}(other, *#{itGetRef}(&it))) return 0;
}
return 1;
}
#{define} #{copy.definition} {
#{it} it;
#{assert}(src);
#{assert}(dst);
#{ctor}(dst);
#{itCtor}(&it, src);
while(#{itMove}(&it)) #{put}(dst, *#{itGetRef}(&it));
}
#{define} #{equal.definition} {
#{assert}(lt);
#{assert}(rt);
return #{size}(lt) == #{size}(rt) && #{containsAllOf}(lt, rt) && #{containsAllOf}(rt, lt);
}
#{define} #{identify.definition} {
#{it} it;
size_t result = 0;
#{assert}(self);
#{itCtor}(&it, self);
while(#{itMove}(&it)) {
#{element.type}* e = #{itGetRef}(&it);
result ^= #{element.identify("*e")};
result = AUTOC_RCYCLE(result);
}
return result;
}
#{define} size_t #{size}(#{type_ref} self) {
#{assert}(self);
return self->size;
}
#{define} void #{include}(#{type_ref} self, #{type_ref} other) {
#{it} it;
#{assert}(self);
#{assert}(other);
#{itCtor}(&it, other);
while(#{itMove}(&it)) #{put}(self, *#{itGetRef}(&it));
}
#{define} void #{retain}(#{type_ref} self, #{type_ref} other) {
#{it} it;
#{type} set;
#{assert}(self);
#{assert}(other);
#{ctor}(&set);
#{itCtor}(&it, self);
while(#{itMove}(&it)) {
#{element.type}* e = #{itGetRef}(&it);
#{assert}(e);
if(#{contains}(other, *e)) #{put}(&set, *e);
}
#{dtor}(self);
*self = set;
}
#{define} void #{invert}(#{type_ref} self, #{type_ref} other) {
#{it} it;
#{type} set;
#{assert}(self);
#{assert}(other);
#{ctor}(&set);
#{itCtor}(&it, self);
while(#{itMove}(&it)) {
#{element.type}* e = #{itGetRef}(&it);
if(!#{contains}(other, *e)) #{put}(&set, *e);
}
#{itCtor}(&it, other);
while(#{itMove}(&it)) {
#{element.type}* e = #{itGetRef}(&it);
if(!#{contains}(self, *e)) #{put}(&set, *e);
}
#{dtor}(self);
*self = set;
}
#{define} void #{exclude}(#{type_ref} self, #{type_ref} other) {
#{it} it;
#{assert}(self);
#{assert}(other);
#{itCtor}(&it, other);
while(#{itMove}(&it)) #{remove}(self, *#{itGetRef}(&it));
}
$
end
|