autoc 1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +3 -0
  3. data/README.md +149 -0
  4. data/cmake/AutoC.cmake +39 -0
  5. data/lib/autoc/allocators.rb +51 -0
  6. data/lib/autoc/association.rb +126 -0
  7. data/lib/autoc/box.rb +311 -0
  8. data/lib/autoc/cmake.rb +54 -0
  9. data/lib/autoc/collection.rb +83 -110
  10. data/lib/autoc/composite.rb +333 -0
  11. data/lib/autoc/cstring.rb +263 -0
  12. data/lib/autoc/function.rb +247 -0
  13. data/lib/autoc/hash_map.rb +328 -0
  14. data/lib/autoc/hash_set.rb +339 -0
  15. data/lib/autoc/hashers.rb +102 -0
  16. data/lib/autoc/list.rb +444 -0
  17. data/lib/autoc/module.rb +434 -0
  18. data/lib/autoc/openmp.rb +15 -0
  19. data/lib/autoc/primitive.rb +27 -0
  20. data/lib/autoc/ranges.rb +707 -0
  21. data/lib/autoc/record.rb +247 -0
  22. data/lib/autoc/scaffold/docs.rb +117 -0
  23. data/lib/autoc/scaffold/generic_value.rb +86 -0
  24. data/lib/autoc/scaffold/project.rb +75 -0
  25. data/lib/autoc/scaffold/test_cstring.rb +113 -0
  26. data/lib/autoc/scaffold/test_cstring_hash_set.rb +35 -0
  27. data/lib/autoc/scaffold/test_int_box.rb +22 -0
  28. data/lib/autoc/scaffold/test_int_hash_set.rb +448 -0
  29. data/lib/autoc/scaffold/test_int_list.rb +106 -0
  30. data/lib/autoc/scaffold/test_int_vector.rb +83 -0
  31. data/lib/autoc/scaffold/test_v2v_hash_map.rb +83 -0
  32. data/lib/autoc/scaffold/test_value_hash_set.rb +60 -0
  33. data/lib/autoc/scaffold/test_value_vector.rb +146 -0
  34. data/{test/test.rb → lib/autoc/scaffold/tests.rb} +179 -158
  35. data/lib/autoc/scaffold.rb +12 -0
  36. data/lib/autoc/sequential.rb +99 -0
  37. data/lib/autoc/set.rb +331 -0
  38. data/lib/autoc/std.rb +149 -0
  39. data/lib/autoc/type.rb +93 -531
  40. data/lib/autoc/vector.rb +290 -0
  41. data/lib/autoc.rb +4 -35
  42. metadata +55 -85
  43. data/.yardopts +0 -4
  44. data/CHANGES +0 -23
  45. data/README +0 -28
  46. data/doc/AutoC/Code.html +0 -523
  47. data/doc/AutoC/Collection.html +0 -1214
  48. data/doc/AutoC/HashMap.html +0 -1441
  49. data/doc/AutoC/HashSet.html +0 -916
  50. data/doc/AutoC/Iterators/Bidirectional.html +0 -204
  51. data/doc/AutoC/Iterators/Unidirectional.html +0 -200
  52. data/doc/AutoC/Iterators.html +0 -126
  53. data/doc/AutoC/List.html +0 -1039
  54. data/doc/AutoC/Maps.html +0 -290
  55. data/doc/AutoC/Module/File.html +0 -415
  56. data/doc/AutoC/Module/Header.html +0 -437
  57. data/doc/AutoC/Module/Source.html +0 -707
  58. data/doc/AutoC/Module.html +0 -948
  59. data/doc/AutoC/Priority.html +0 -138
  60. data/doc/AutoC/Queue.html +0 -1172
  61. data/doc/AutoC/Reference.html +0 -735
  62. data/doc/AutoC/Sets.html +0 -520
  63. data/doc/AutoC/String.html +0 -1394
  64. data/doc/AutoC/TreeMap.html +0 -1565
  65. data/doc/AutoC/TreeSet.html +0 -1447
  66. data/doc/AutoC/Type.html +0 -2148
  67. data/doc/AutoC/UserDefinedType.html +0 -1047
  68. data/doc/AutoC/Vector.html +0 -987
  69. data/doc/AutoC.html +0 -331
  70. data/doc/_index.html +0 -388
  71. data/doc/class_list.html +0 -51
  72. data/doc/css/common.css +0 -1
  73. data/doc/css/full_list.css +0 -58
  74. data/doc/css/style.css +0 -481
  75. data/doc/file.CHANGES.html +0 -117
  76. data/doc/file.README.html +0 -116
  77. data/doc/file_list.html +0 -61
  78. data/doc/frames.html +0 -17
  79. data/doc/index.html +0 -116
  80. data/doc/js/app.js +0 -243
  81. data/doc/js/full_list.js +0 -216
  82. data/doc/js/jquery.js +0 -4
  83. data/doc/method_list.html +0 -1307
  84. data/doc/top-level-namespace.html +0 -112
  85. data/lib/autoc/code.rb +0 -237
  86. data/lib/autoc/collection/hash_map.rb +0 -385
  87. data/lib/autoc/collection/hash_set.rb +0 -337
  88. data/lib/autoc/collection/iterator.rb +0 -39
  89. data/lib/autoc/collection/list.rb +0 -429
  90. data/lib/autoc/collection/map.rb +0 -41
  91. data/lib/autoc/collection/queue.rb +0 -517
  92. data/lib/autoc/collection/set.rb +0 -134
  93. data/lib/autoc/collection/tree_map.rb +0 -464
  94. data/lib/autoc/collection/tree_set.rb +0 -611
  95. data/lib/autoc/collection/vector.rb +0 -336
  96. data/lib/autoc/string.rb +0 -492
  97. data/test/test_auto.c +0 -7141
  98. data/test/test_auto.h +0 -753
  99. data/test/test_char_string.rb +0 -270
  100. data/test/test_int_list.rb +0 -35
  101. data/test/test_int_tree_set.rb +0 -111
  102. data/test/test_int_vector.rb +0 -34
  103. data/test/test_value_hash_map.rb +0 -162
  104. data/test/test_value_hash_set.rb +0 -173
  105. data/test/test_value_list.rb +0 -193
  106. data/test/test_value_queue.rb +0 -275
  107. data/test/test_value_tree_map.rb +0 -176
  108. data/test/test_value_tree_set.rb +0 -173
  109. data/test/test_value_vector.rb +0 -155
  110. data/test/value.rb +0 -80
@@ -1,517 +0,0 @@
1
- require "autoc/collection"
2
-
3
-
4
- require "autoc/collection/iterator"
5
-
6
-
7
- module AutoC
8
-
9
-
10
- =begin
11
-
12
- Queue< *_E_* > is an ordered bidirectional sequence container.
13
- Queue supports addition/removal operations at both ends.
14
- However, it is intended to be used as a FIFO container as opposed to {AutoC::List}
15
- therefore the default submission, polling and retrieval operations are performed on the opposite ends.
16
-
17
- This collection is a synergy of C++ +std::list<>+ and +std::queue<>+ template classes.
18
-
19
- == Generated C interface
20
-
21
- === Collection management
22
-
23
- [cols=2*]
24
- |===
25
- |*_void_* ~type~Copy(*_Type_* * +dst+, *_Type_* * +src+)
26
- |
27
- Create a new queue +dst+ filled with the contents of +src+.
28
- A copy operation is performed on every element in +src+.
29
-
30
- NOTE: Previous contents of +dst+ is overwritten.
31
-
32
- |*_void_* ~type~Ctor(*_Type_* * +self+)
33
- |
34
- Create a new empty queue +self+.
35
-
36
- NOTE: Previous contents of +self+ is overwritten.
37
-
38
- |*_void_* ~type~Dtor(*_Type_* * +self+)
39
- |
40
- Destroy queue +self+.
41
- Stored elements are destroyed as well by calling the respective destructors.
42
-
43
- |*_int_* ~type~Equal(*_Type_* * +lt+, *_Type_* * +rt+)
44
- |
45
- Return non-zero value if queues +lt+ and +rt+ are considered equal by contents and zero value otherwise.
46
-
47
- |*_size_t_* ~type~Identify(*_Type_* * +self+)
48
- |
49
- Return hash code for queue +self+.
50
- |===
51
-
52
- === Basic operations
53
-
54
- [cols=2*]
55
- |===
56
- |*_int_* ~type~Contains(*_Type_* * +self+, *_E_* +what+)
57
- |
58
- Return non-zero value if queue +self+ contains (at least) one element considered equal to +what+ and zero value otherwise.
59
-
60
- |*_int_* ~type~Empty(*_Type_* * +self+)
61
- |
62
- Return non-zero value if queue +self+ contains no elements and zero value otherwise.
63
-
64
- |*_E_* ~type~Find(*_Type_* * +self+, *_E_* +what+)
65
- |
66
- Return the _first_ element of stored in +self+ which is considered equal to +what+.
67
-
68
- WARNING: +self+ *must* contain such element otherwise the behavior is undefined. See ~type~Contains().
69
-
70
- |*_E_* ~type~Peek(*_Type_* * +self+)
71
- |
72
- Alias for ~type~PeekHead().
73
-
74
- |*_E_* ~type~PeekHead(*_Type_* * +self+)
75
- |
76
- Return a _copy_ of the head element of +self+.
77
-
78
- WARNING: +self+ *must not* be empty otherwise the behavior is undefined. See ~type~Empty().
79
-
80
- |*_E_* ~type~PeekTail(*_Type_* * +self+)
81
- |
82
- Return a _copy_ of the tail element of +self+.
83
-
84
- WARNING: +self+ *must not* be empty otherwise the behavior is undefined. See ~type~Empty().
85
-
86
- |*_E_* ~type~Pop(*_Type_* * +self+)
87
- |
88
- Alias for ~type~PopHead().
89
-
90
- |*_E_* ~type~PopHead(*_Type_* * +self+)
91
- |
92
- Remove head element of +self+ *and* return it.
93
-
94
- NOTE: The function returns the element itself, *not* a copy.
95
-
96
- WARNING: +self+ *must not* be empty otherwise the behavior is undefined. See ~type~Empty().
97
-
98
- |*_E_* ~type~PopTail(*_Type_* * +self+)
99
- |
100
- Remove tail element of +self+ *and* return it.
101
-
102
- NOTE: The function returns the element itself, *not* a copy.
103
-
104
- WARNING: +self+ *must not* be empty otherwise the behavior is undefined. See ~type~Empty().
105
-
106
- |*_void_* ~type~Purge(*_Type_* * +self+)
107
- |
108
- Remove and destroy all elements stored in +self+.
109
-
110
- |*_void_* ~type~Push(*_Type_* * +self+, *_E_* +what+)
111
- |
112
- Alias for ~type~PushTail().
113
-
114
- |*_void_* ~type~PushHead(*_Type_* * +self+, *_E_* +what+)
115
- |
116
- Place a _copy_ of the element +what+ to the head of +self+.
117
-
118
- |*_void_* ~type~PushTail(*_Type_* * +self+, *_E_* +what+)
119
- |
120
- Place a _copy_ of the element +what+ to the tail of +self+.
121
-
122
- |*_int_* ~type~Replace(*_Type_* * +self+, *_E_* +what+, *_E_* +with+)
123
- |
124
- Find the _first_ occurrence of +what+ in +self+ and replace it with a _copy_ of the element +with+.
125
- Replaced element is destroyed.
126
-
127
- Return non-zero value on successful replacement and zero value if no suitable element was found.
128
-
129
- |*_int_* ~type~ReplaceAll(*_Type_* * +self+, *_E_* +what+, *_E_* +with+)
130
- |
131
- Find _all_ occurrences of +what+ in +self+ and replace them with _copies_ of the element +with+.
132
- All replaced elements are destroyed.
133
-
134
- Return number of successful replacements.
135
-
136
- |*_int_* ~type~ReplaceEx(*_Type_* * +self+, *_E_* +what+, *_E_* +with+, *_int_* count)
137
- |
138
- Find at most +count+ occurrences of +what+ in +self+ and replace them with _copies_ of the element +with+.
139
- If +count+ is negative, _all_ occurrences are replaced instead.
140
- All replaced elements are destroyed.
141
-
142
- Return number of successful replacements.
143
-
144
- |*_int_* ~type~Remove(*_Type_* * +self+, *_E_* +what+)
145
- |
146
- Remove and destroy the _first_ occurrence of the element +what+ in +self+.
147
-
148
- Return non-zero value if element was removed and zero value otherwise.
149
-
150
- |*_int_* ~type~RemoveAll(*_Type_* * +self+, *_E_* +what+)
151
- |
152
- Remove and destroy _all_ occurrences of the element +what+ in +self+.
153
-
154
- Return number of elements actually removed.
155
-
156
- |*_int_* ~type~RemoveEx(*_Type_* * +self+, *_E_* +what+, *_int_* count)
157
- |
158
- Remove and destroy at most +count+ occurrences of the element +what+ in +self+.
159
- If +count+ is negative, _all_ occurrences are removed instead.
160
-
161
- Return number of elements actually removed.
162
-
163
- |*_size_t_* ~type~Size(*_Type_* * +self+)
164
- |
165
- Return number of elements stored in +self+.
166
- |===
167
-
168
- === Iteration
169
-
170
- [cols=2*]
171
- |===
172
- |*_void_* ~it~Ctor(*_IteratorType_* * +it+, *_Type_* * +self+)
173
- |
174
- Create a new forward (see ~it~CtorEx()) iterator +it+ on queue +self+.
175
-
176
- NOTE: Previous contents of +it+ is overwritten.
177
-
178
- |*_void_* ~it~CtorEx(*_IteratorType_* * +it+, *_Type_* * +self+, *_int_* +forward+)
179
- |
180
- Create a new iterator +it+ on queue +self+.
181
- Non-zero value of +forward+ specifies a forward iterator, zero value specifies a backward iterator.
182
-
183
- NOTE: Previous contents of +it+ is overwritten.
184
-
185
- |*_int_* ~it~Move(*_IteratorType_* * +it+)
186
- |
187
- Advance iterator position of +it+ *and* return non-zero value if new position is valid and zero value otherwise.
188
-
189
- |*_E_* ~it~Get(*_IteratorType_* * +it+)
190
- |
191
- Return a _copy_ of current element pointed to by the iterator +it+.
192
-
193
- WARNING: current position *must* be valid otherwise the behavior is undefined. See ~it~Move().
194
- |===
195
-
196
- =end
197
- class Queue < Collection
198
-
199
- include Iterators::Bidirectional
200
-
201
- def write_intf_types(stream)
202
- super
203
- stream << %$
204
- /***
205
- **** #{type}<#{element.type}>
206
- ***/
207
- $ if public?
208
- stream << %$
209
- typedef struct #{node} #{node};
210
- typedef struct #{type} #{type};
211
- typedef struct #{it} #{it};
212
- struct #{type} {
213
- #{node}* head_node;
214
- #{node}* tail_node;
215
- size_t node_count;
216
- };
217
- struct #{it} {
218
- int start, forward;
219
- #{type_ref} queue;
220
- #{node}* this_node;
221
- };
222
- struct #{node} {
223
- #{element.type} element;
224
- #{node}* prev_node;
225
- #{node}* next_node;
226
- };
227
- $
228
- end
229
-
230
- def write_intf_decls(stream, declare, define)
231
- super
232
- stream << %$
233
- #{declare} #{ctor.declaration};
234
- #{declare} #{dtor.declaration};
235
- #{declare} #{copy.declaration};
236
- #{declare} #{equal.declaration};
237
- #{declare} #{identify.declaration};
238
- #{declare} void #{purge}(#{type_ref});
239
- #define #{peek}(self) #{peekHead}(self)
240
- #{declare} #{element.type} #{peekHead}(#{type_ref});
241
- #{declare} #{element.type} #{peekTail}(#{type_ref});
242
- #define #{push}(self, element) #{pushTail}(self, element)
243
- #{declare} void #{pushTail}(#{type_ref}, #{element.type});
244
- #{declare} void #{pushHead}(#{type_ref}, #{element.type});
245
- #define #{pop}(self) #{popHead}(self)
246
- #{declare} #{element.type} #{popHead}(#{type_ref});
247
- #{declare} #{element.type} #{popTail}(#{type_ref});
248
- #{declare} int #{contains}(#{type_ref}, #{element.type});
249
- #{declare} #{element.type} #{find}(#{type_ref}, #{element.type});
250
- #define #{replace}(self, with) #{replaceEx}(self, with, 1)
251
- #define #{replaceAll}(self, with) #{replaceEx}(self, with, -1)
252
- #{declare} int #{replaceEx}(#{type_ref}, #{element.type}, int);
253
- #define #{remove}(self, what) #{removeEx}(self, what, 1)
254
- #define #{removeAll}(self, what) #{removeEx}(self, what, -1)
255
- #{declare} int #{removeEx}(#{type_ref}, #{element.type}, int);
256
- #{declare} size_t #{size}(#{type_ref});
257
- #define #{empty}(self) (#{size}(self) == 0)
258
- $
259
- end
260
-
261
- def write_impls(stream, define)
262
- super
263
- stream << %$
264
- static #{element.type_ref} #{itGetRef}(#{it_ref});
265
- #{define} #{ctor.definition} {
266
- #{assert}(self);
267
- self->head_node = self->tail_node = NULL;
268
- self->node_count = 0;
269
- }
270
- #{define} #{dtor.definition} {
271
- #{node}* node;
272
- #{assert}(self);
273
- node = self->head_node;
274
- while(node) {
275
- #{node}* this_node = node;
276
- node = node->next_node;
277
- #{element.dtor("this_node->element")};
278
- #{free}(this_node);
279
- }
280
- }
281
- #{define} #{copy.definition} {
282
- #{it} it;
283
- #{assert}(src);
284
- #{assert}(dst);
285
- #{ctor}(dst);
286
- #{itCtor}(&it, src);
287
- while(#{itMove}(&it)) {
288
- #{element.type} element;
289
- #{pushTail}(dst, element = #{itGet}(&it));
290
- #{element.dtor("element")};
291
- }
292
- }
293
- #{define} #{equal.definition} {
294
- if(#{size}(lt) == #{size}(rt)) {
295
- #{it} lit, rit;
296
- #{itCtor}(&lit, lt);
297
- #{itCtor}(&rit, rt);
298
- while(#{itMove}(&lit) && #{itMove}(&rit)) {
299
- int equal;
300
- #{element.type} *le, *re;
301
- le = #{itGetRef}(&lit);
302
- re = #{itGetRef}(&rit);
303
- equal = #{element.equal("*le", "*re")};
304
- if(!equal) return 0;
305
- }
306
- return 1;
307
- } else
308
- return 0;
309
- }
310
- #{define} #{identify.definition} {
311
- #{node}* node;
312
- size_t result = 0;
313
- #{assert}(self);
314
- for(node = self->head_node; node != NULL; node = node->next_node) {
315
- result ^= #{element.identify("node->element")};
316
- result = AUTOC_RCYCLE(result);
317
- }
318
- return result;
319
- }
320
- #{define} void #{purge}(#{type_ref} self) {
321
- #{dtor}(self);
322
- #{ctor}(self);
323
- }
324
- #{define} #{element.type} #{peekHead}(#{type_ref} self) {
325
- #{element.type} result;
326
- #{assert}(self);
327
- #{assert}(!#{empty}(self));
328
- #{element.copy("result", "self->head_node->element")};
329
- return result;
330
- }
331
- #{define} #{element.type} #{peekTail}(#{type_ref} self) {
332
- #{element.type} result;
333
- #{assert}(self);
334
- #{assert}(!#{empty}(self));
335
- #{element.copy("result", "self->tail_node->element")};
336
- return result;
337
- }
338
- #{define} #{element.type} #{popHead}(#{type_ref} self) {
339
- #{node}* node;
340
- #{element.type} result;
341
- #{assert}(self);
342
- #{assert}(!#{empty}(self));
343
- node = self->head_node;
344
- result = node->element;
345
- self->head_node = self->head_node->next_node;
346
- self->head_node->prev_node = NULL;
347
- --self->node_count;
348
- #{free}(node);
349
- return result;
350
- }
351
- #{define} #{element.type} #{popTail}(#{type_ref} self) {
352
- #{node}* node;
353
- #{element.type} result;
354
- #{assert}(self);
355
- #{assert}(!#{empty}(self));
356
- node = self->tail_node;
357
- result = node->element;
358
- self->tail_node = self->tail_node->prev_node;
359
- self->tail_node->next_node = NULL;
360
- --self->node_count;
361
- #{free}(node);
362
- return result;
363
- }
364
- #{define} void #{pushTail}(#{type_ref} self, #{element.type} element) {
365
- #{node}* node;
366
- #{assert}(self);
367
- node = (#{node}*)#{malloc}(sizeof(#{node})); #{assert}(node);
368
- #{element.copy("node->element", "element")};
369
- if(#{empty}(self)) {
370
- node->prev_node = node->next_node = NULL;
371
- self->tail_node = self->head_node = node;
372
- } else {
373
- node->next_node = NULL;
374
- node->prev_node = self->tail_node;
375
- self->tail_node->next_node = node;
376
- self->tail_node = node;
377
- }
378
- ++self->node_count;
379
- }
380
- #{define} void #{pushHead}(#{type_ref} self, #{element.type} element) {
381
- #{node}* node;
382
- #{assert}(self);
383
- node = (#{node}*)#{malloc}(sizeof(#{node})); #{assert}(node);
384
- #{element.copy("node->element", "element")};
385
- if(#{empty}(self)) {
386
- node->prev_node = node->next_node = NULL;
387
- self->tail_node = self->head_node = node;
388
- } else {
389
- node->prev_node = NULL;
390
- node->next_node = self->head_node;
391
- self->head_node->prev_node = node;
392
- self->head_node = node;
393
- }
394
- ++self->node_count;
395
- }
396
- #{define} int #{contains}(#{type_ref} self, #{element.type} what) {
397
- #{node}* node;
398
- int found = 0;
399
- #{assert}(self);
400
- node = self->head_node;
401
- while(node) {
402
- if(#{element.equal("node->element", "what")}) {
403
- found = 1;
404
- break;
405
- }
406
- node = node->next_node;
407
- }
408
- return found;
409
- }
410
- #{define} #{element.type} #{find}(#{type_ref} self, #{element.type} what) {
411
- #{node}* node;
412
- #{assert}(self);
413
- #{assert}(#{contains}(self, what));
414
- node = self->head_node;
415
- while(node) {
416
- if(#{element.equal("node->element", "what")}) {
417
- #{element.type} result;
418
- #{element.copy("result", "node->element")};
419
- return result;
420
- }
421
- node = node->next_node;
422
- }
423
- #{abort}();
424
- }
425
- #{define} int #{replaceEx}(#{type_ref} self, #{element.type} with, int count) {
426
- #{node}* node;
427
- int replaced = 0;
428
- #{assert}(self);
429
- if(count == 0) return 0;
430
- node = self->head_node;
431
- while(node) {
432
- if(#{element.equal("node->element", "with")}) {
433
- #{element.dtor("node->element")};
434
- #{element.copy("node->element", "with")};
435
- ++replaced;
436
- if(count > 0 && replaced >= count) break;
437
- }
438
- node = node->next_node;
439
- }
440
- return replaced;
441
- }
442
- #{define} int #{removeEx}(#{type_ref} self, #{element.type} what, int count) {
443
- #{node}* node;
444
- int removed = 0;
445
- #{assert}(self);
446
- if(count == 0) return 0;
447
- node = self->head_node;
448
- while(node) {
449
- if(#{element.equal("node->element", "what")}) {
450
- #{node}* this_node;
451
- if(node == self->head_node) {
452
- #{assert}(!node->prev_node);
453
- this_node = self->head_node = node->next_node;
454
- if(self->head_node) self->head_node->prev_node = NULL;
455
- } else if(node == self->tail_node) {
456
- #{assert}(!node->next_node);
457
- self->tail_node = node->prev_node;
458
- this_node = self->tail_node->next_node = NULL;
459
- } else {
460
- #{assert}(node->prev_node);
461
- #{assert}(node->next_node);
462
- this_node = node->next_node;
463
- node->next_node->prev_node = node->prev_node;
464
- node->prev_node->next_node = node->next_node;
465
- }
466
- ++removed;
467
- --self->node_count;
468
- #{element.dtor("node->element")};
469
- #{free}(node);
470
- node = this_node;
471
- if(count > 0 && removed >= count) break;
472
- } else {
473
- node = node->next_node;
474
- }
475
- }
476
- return removed;
477
- }
478
- #{define} size_t #{size}(#{type_ref} self) {
479
- #{assert}(self);
480
- return self->node_count;
481
- }
482
- #{define} void #{itCtorEx}(#{it_ref} self, #{type_ref} queue, int forward) {
483
- #{assert}(self);
484
- #{assert}(queue);
485
- self->start = 1;
486
- self->queue = queue;
487
- self->forward = forward;
488
- }
489
- #{define} int #{itMove}(#{it_ref} self) {
490
- #{assert}(self);
491
- if(self->start) {
492
- self->this_node = self->forward ? self->queue->head_node : self->queue->tail_node;
493
- self->start = 0;
494
- } else {
495
- self->this_node = self->forward ? self->this_node->next_node : self->this_node->prev_node;
496
- }
497
- return self->this_node != NULL;
498
- }
499
- #{define} #{element.type} #{itGet}(#{it_ref} self) {
500
- #{element.type} result;
501
- #{assert}(self);
502
- #{assert}(self->this_node);
503
- #{element.copy("result", "self->this_node->element")};
504
- return result;
505
- }
506
- static #{element.type_ref} #{itGetRef}(#{it_ref} self) {
507
- #{assert}(self);
508
- #{assert}(self->this_node);
509
- return &self->this_node->element;
510
- }
511
- $
512
- end
513
-
514
- end # Queue
515
-
516
-
517
- end # AutoC
@@ -1,134 +0,0 @@
1
- module AutoC
2
-
3
-
4
- # :nodoc
5
- module Sets
6
-
7
- def write_intf_types(stream)
8
- super
9
- stream << %$
10
- /***
11
- **** #{type}<#{element.type}>
12
- ***/
13
- $ if public?
14
- end
15
-
16
- def write_intf_decls(stream, declare, define)
17
- super
18
- stream << %$
19
- #{declare} #{ctor.declaration};
20
- #{declare} #{dtor.declaration};
21
- #{declare} #{copy.declaration};
22
- #{declare} #{equal.declaration};
23
- #{declare} #{identify.declaration};
24
- #{declare} void #{purge}(#{type_ref});
25
- #{declare} int #{contains}(#{type_ref}, #{element.type});
26
- #{declare} #{element.type} #{get}(#{type_ref}, #{element.type});
27
- #{declare} size_t #{size}(#{type_ref});
28
- #define #{empty}(self) (#{size}(self) == 0)
29
- #{declare} int #{put}(#{type_ref}, #{element.type});
30
- #{declare} int #{replace}(#{type_ref}, #{element.type});
31
- #{declare} int #{remove}(#{type_ref}, #{element.type});
32
- #{declare} void #{exclude}(#{type_ref}, #{type_ref});
33
- #{declare} void #{retain}(#{type_ref}, #{type_ref});
34
- #{declare} void #{include}(#{type_ref}, #{type_ref});
35
- #{declare} void #{invert}(#{type_ref}, #{type_ref});
36
- $
37
- end
38
-
39
- def write_impls(stream, define)
40
- super
41
- stream << %$
42
- static #{element.type_ref} #{itGetRef}(#{it_ref});
43
- static int #{containsAllOf}(#{type_ref} self, #{type_ref} other) {
44
- #{it} it;
45
- #{itCtor}(&it, self);
46
- while(#{itMove}(&it)) {
47
- if(!#{contains}(other, *#{itGetRef}(&it))) return 0;
48
- }
49
- return 1;
50
- }
51
- #{define} #{copy.definition} {
52
- #{it} it;
53
- #{assert}(src);
54
- #{assert}(dst);
55
- #{ctor}(dst);
56
- #{itCtor}(&it, src);
57
- while(#{itMove}(&it)) #{put}(dst, *#{itGetRef}(&it));
58
- }
59
- #{define} #{equal.definition} {
60
- #{assert}(lt);
61
- #{assert}(rt);
62
- return #{size}(lt) == #{size}(rt) && #{containsAllOf}(lt, rt) && #{containsAllOf}(rt, lt);
63
- }
64
- #{define} #{identify.definition} {
65
- #{it} it;
66
- size_t result = 0;
67
- #{assert}(self);
68
- #{itCtor}(&it, self);
69
- while(#{itMove}(&it)) {
70
- #{element.type}* e = #{itGetRef}(&it);
71
- result ^= #{element.identify("*e")};
72
- result = AUTOC_RCYCLE(result);
73
- }
74
- return result;
75
- }
76
- #{define} size_t #{size}(#{type_ref} self) {
77
- #{assert}(self);
78
- return self->size;
79
- }
80
- #{define} void #{include}(#{type_ref} self, #{type_ref} other) {
81
- #{it} it;
82
- #{assert}(self);
83
- #{assert}(other);
84
- #{itCtor}(&it, other);
85
- while(#{itMove}(&it)) #{put}(self, *#{itGetRef}(&it));
86
- }
87
- #{define} void #{retain}(#{type_ref} self, #{type_ref} other) {
88
- #{it} it;
89
- #{type} set;
90
- #{assert}(self);
91
- #{assert}(other);
92
- #{ctor}(&set);
93
- #{itCtor}(&it, self);
94
- while(#{itMove}(&it)) {
95
- #{element.type}* e = #{itGetRef}(&it);
96
- #{assert}(e);
97
- if(#{contains}(other, *e)) #{put}(&set, *e);
98
- }
99
- #{dtor}(self);
100
- *self = set;
101
- }
102
- #{define} void #{invert}(#{type_ref} self, #{type_ref} other) {
103
- #{it} it;
104
- #{type} set;
105
- #{assert}(self);
106
- #{assert}(other);
107
- #{ctor}(&set);
108
- #{itCtor}(&it, self);
109
- while(#{itMove}(&it)) {
110
- #{element.type}* e = #{itGetRef}(&it);
111
- if(!#{contains}(other, *e)) #{put}(&set, *e);
112
- }
113
- #{itCtor}(&it, other);
114
- while(#{itMove}(&it)) {
115
- #{element.type}* e = #{itGetRef}(&it);
116
- if(!#{contains}(self, *e)) #{put}(&set, *e);
117
- }
118
- #{dtor}(self);
119
- *self = set;
120
- }
121
- #{define} void #{exclude}(#{type_ref} self, #{type_ref} other) {
122
- #{it} it;
123
- #{assert}(self);
124
- #{assert}(other);
125
- #{itCtor}(&it, other);
126
- while(#{itMove}(&it)) #{remove}(self, *#{itGetRef}(&it));
127
- }
128
- $
129
- end
130
-
131
- end # Sets
132
-
133
-
134
- end # AutoC