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,429 +0,0 @@
1
- require "autoc/collection"
2
-
3
-
4
- require "autoc/collection/iterator"
5
-
6
-
7
- module AutoC
8
-
9
-
10
- =begin
11
-
12
- List< *_E_* > is an ordered unidirectional sequence container.
13
- List supports submission/polling operations on one end hence it can be used as a LIFO container (a stack).
14
-
15
- The collection's C++ counterpart is +std::forward_list<>+ template class.
16
-
17
- == Generated C interface
18
-
19
- === Collection management
20
-
21
- [cols=2*]
22
- |===
23
- |*_void_* ~type~Copy(*_Type_* * +dst+, *_Type_* * +src+)
24
- |
25
- Create a new list +dst+ filled with the contents of +src+.
26
- A copy operation is performed on every element in +src+.
27
-
28
- NOTE: Previous contents of +dst+ is overwritten.
29
-
30
- |*_void_* ~type~Ctor(*_Type_* * +self+)
31
- |
32
- Create a new empty list +self+.
33
-
34
- NOTE: Previous contents of +self+ is overwritten.
35
-
36
- |*_void_* ~type~Dtor(*_Type_* * +self+)
37
- |
38
- Destroy list +self+.
39
- Stored elements are destroyed as well by calling the respective destructors.
40
-
41
- |*_int_* ~type~Equal(*_Type_* * +lt+, *_Type_* * +rt+)
42
- |
43
- Return non-zero value if lists +lt+ and +rt+ are considered equal by contents and zero value otherwise.
44
-
45
- |*_size_t_* ~type~Identify(*_Type_* * +self+)
46
- |
47
- Return hash code for list +self+.
48
- |===
49
-
50
- === Basic operations
51
-
52
- [cols=2*]
53
- |===
54
- |*_int_* ~type~Contains(*_Type_* * +self+, *_E_* +what+)
55
- |
56
- Return non-zero value if list +self+ contains (at least) one element considered equal to +what+ and zero value otherwise.
57
-
58
- |*_int_* ~type~Empty(*_Type_* * +self+)
59
- |
60
- Return non-zero value if list +self+ contains no elements and zero value otherwise.
61
-
62
- |*_E_* ~type~Find(*_Type_* * +self+, *_E_* +what+)
63
- |
64
- Return the _first_ element of stored in +self+ which is considered equal to +what+.
65
-
66
- WARNING: +self+ *must* contain such element otherwise the behavior is undefined. See ~type~Contains().
67
-
68
- |*_E_* ~type~Peek(*_Type_* * +self+)
69
- |
70
- Return a _copy_ of the head element of +self+.
71
-
72
- WARNING: +self+ *must not* be empty otherwise the behavior is undefined. See ~type~Empty().
73
-
74
- |*_E_* ~type~Pop(*_Type_* * +self+)
75
- |
76
- Remove head element of +self+ *and* return it.
77
-
78
- NOTE: The function returns the element itself, *not* a copy.
79
-
80
- WARNING: +self+ *must not* be empty otherwise the behavior is undefined. See ~type~Empty().
81
-
82
- |*_void_* ~type~Purge(*_Type_* * +self+)
83
- |
84
- Remove and destroy all elements stored in +self+.
85
-
86
- |*_void_* ~type~Push(*_Type_* * +self+, *_E_* +what+)
87
- |
88
- Place a _copy_ of the element +what+ to the head of +self+.
89
-
90
- |*_int_* ~type~Replace(*_Type_* * +self+, *_E_* +with+)
91
- |
92
- Find the _first_ occurrence of +with+ in +self+ and replace it with a _copy_ of the element +with+.
93
- Replaced element is destroyed.
94
-
95
- Return non-zero value on successful replacement and zero value if no suitable element was found.
96
-
97
- |*_int_* ~type~ReplaceAll(*_Type_* * +self+, *_E_* +with+)
98
- |
99
- Find _all_ occurrences of +with+ in +self+ and replace them with _copies_ of the element +with+.
100
- All replaced elements are destroyed.
101
-
102
- Return number of successful replacements.
103
-
104
- |*_int_* ~type~ReplaceEx(*_Type_* * +self+, *_E_* +with+, *_int_* count)
105
- |
106
- Find at most +count+ occurrences of +with+ in +self+ and replace them with _copies_ of the element +with+.
107
- If +count+ is negative, _all_ occurrences are replaced instead.
108
- All replaced elements are destroyed.
109
-
110
- Return number of successful replacements.
111
-
112
- |*_int_* ~type~Remove(*_Type_* * +self+, *_E_* +what+)
113
- |
114
- Remove and destroy the _first_ occurrence of the element +what+ in +self+.
115
-
116
- Return non-zero value if element was removed and zero value otherwise.
117
-
118
- |*_int_* ~type~RemoveAll(*_Type_* * +self+, *_E_* +what+)
119
- |
120
- Remove and destroy _all_ occurrences of the element +what+ in +self+.
121
-
122
- Return number of elements actually removed.
123
-
124
- |*_int_* ~type~RemoveEx(*_Type_* * +self+, *_E_* +what+, *_int_* count)
125
- |
126
- Remove and destroy at most +count+ occurrences of the element +what+ in +self+.
127
- If +count+ is negative, _all_ occurrences are removed instead.
128
-
129
- Return number of elements actually removed.
130
-
131
- |*_size_t_* ~type~Size(*_Type_* * +self+)
132
- |
133
- Return number of elements stored in +self+.
134
- |===
135
-
136
- === Iteration
137
-
138
- [cols=2*]
139
- |===
140
- |*_void_* ~it~Ctor(*_IteratorType_* * +it+, *_Type_* * +self+)
141
- |
142
- Create a new iterator +it+ on list +self+.
143
-
144
- NOTE: Previous contents of +it+ is overwritten.
145
-
146
- |*_int_* ~it~Move(*_IteratorType_* * +it+)
147
- |
148
- Advance iterator position of +it+ *and* return non-zero value if new position is valid and zero value otherwise.
149
-
150
- |*_E_* ~it~Get(*_IteratorType_* * +it+)
151
- |
152
- Return a _copy_ of current element pointed to by the iterator +it+.
153
-
154
- WARNING: current position *must* be valid otherwise the behavior is undefined. See ~it~Move().
155
- |===
156
-
157
- =end
158
- class List < Collection
159
-
160
- include Iterators::Unidirectional
161
-
162
- def write_intf_types(stream)
163
- super
164
- stream << %$
165
- /***
166
- **** #{type}<#{element.type}>
167
- ***/
168
- $ if public?
169
- stream << %$
170
- typedef struct #{node} #{node};
171
- typedef struct #{type} #{type};
172
- typedef struct #{it} #{it};
173
- struct #{type} {
174
- #{node}* head_node;
175
- size_t node_count;
176
- };
177
- struct #{it} {
178
- int start;
179
- #{type_ref} list;
180
- #{node}* this_node;
181
- };
182
- struct #{node} {
183
- #{element.type} element;
184
- #{node}* next_node;
185
- };
186
- $
187
- end
188
-
189
- def write_intf_decls(stream, declare, define)
190
- super
191
- stream << %$
192
- #{declare} #{ctor.declaration};
193
- #{declare} #{dtor.declaration};
194
- #{declare} #{copy.declaration};
195
- #{declare} #{equal.declaration};
196
- #{declare} #{identify.declaration};
197
- #{declare} void #{purge}(#{type_ref});
198
- #{declare} #{element.type} #{peek}(#{type_ref});
199
- #{declare} #{element.type} #{pop}(#{type_ref});
200
- #{declare} void #{push}(#{type_ref}, #{element.type});
201
- #{declare} int #{contains}(#{type_ref}, #{element.type});
202
- #{declare} #{element.type} #{find}(#{type_ref}, #{element.type});
203
- #define #{replace}(self, with) #{replaceEx}(self, with, 1)
204
- #define #{replaceAll}(self, with) #{replaceEx}(self, with, -1)
205
- #{declare} int #{replaceEx}(#{type_ref}, #{element.type}, int);
206
- #define #{remove}(self, what) #{removeEx}(self, what, 1)
207
- #define #{removeAll}(self, what) #{removeEx}(self, what, -1)
208
- #{declare} int #{removeEx}(#{type_ref}, #{element.type}, int);
209
- #{declare} size_t #{size}(#{type_ref});
210
- #define #{empty}(self) (#{size}(self) == 0)
211
- $
212
- end
213
-
214
- def write_impls(stream, define)
215
- super
216
- stream << %$
217
- static #{element.type_ref} #{itGetRef}(#{it_ref});
218
- #{define} #{ctor.definition} {
219
- #{assert}(self);
220
- self->head_node = NULL;
221
- self->node_count = 0;
222
- }
223
- #{define} #{dtor.definition} {
224
- #{node}* node;
225
- #{assert}(self);
226
- node = self->head_node;
227
- while(node) {
228
- #{node}* this_node = node;
229
- node = node->next_node;
230
- #{element.dtor("this_node->element")};
231
- #{free}(this_node);
232
- }
233
- }
234
- #{define} #{copy.definition} {
235
- #{it} it;
236
- size_t index, size;
237
- #{element.type}** elements;
238
- #{assert}(src);
239
- #{assert}(dst);
240
- #{ctor}(dst);
241
- if(!#{empty}(src)) {
242
- /* List is a LIFO type container therefore the insertion order into the destination container should be reversed */
243
- elements = (#{element.type}**)#{malloc}((size = #{size}(src))*sizeof(#{element.type}*)); #{assert}(elements);
244
- index = 0;
245
- #{itCtor}(&it, src);
246
- while(#{itMove}(&it)) {
247
- #{assert}(index < size);
248
- elements[index++] = #{itGetRef}(&it);
249
- }
250
- for(index = size; index > 0; --index) #{push}(dst, *elements[index-1]); /* Be careful not to run into the underflow of the unsigned integer type */
251
- #{free}(elements);
252
- }
253
- }
254
- #{define} #{equal.definition} {
255
- if(#{size}(lt) == #{size}(rt)) {
256
- #{it} lit, rit;
257
- #{itCtor}(&lit, lt);
258
- #{itCtor}(&rit, rt);
259
- while(#{itMove}(&lit) && #{itMove}(&rit)) {
260
- int equal;
261
- #{element.type_ref} le;
262
- #{element.type_ref} re;
263
- le = #{itGetRef}(&lit);
264
- re = #{itGetRef}(&rit);
265
- equal = #{element.equal("*le", "*re")};
266
- if(!equal) return 0;
267
- }
268
- return 1;
269
- } else
270
- return 0;
271
- }
272
- #{define} #{identify.definition} {
273
- #{node}* node;
274
- size_t result = 0;
275
- #{assert}(self);
276
- for(node = self->head_node; node != NULL; node = node->next_node) {
277
- result ^= #{element.identify("node->element")};
278
- result = AUTOC_RCYCLE(result);
279
- }
280
- return result;
281
- }
282
- #{define} void #{purge}(#{type_ref} self) {
283
- #{dtor}(self);
284
- #{ctor}(self);
285
- }
286
- #{define} #{element.type} #{peek}(#{type_ref} self) {
287
- #{element.type} result;
288
- #{assert}(self);
289
- #{assert}(!#{empty}(self));
290
- #{element.copy("result", "self->head_node->element")};
291
- return result;
292
- }
293
- #{define} #{element.type} #{pop}(#{type_ref} self) {
294
- #{node}* node;
295
- #{element.type} result;
296
- #{assert}(self);
297
- #{assert}(!#{empty}(self));
298
- node = self->head_node;
299
- result = node->element;
300
- self->head_node = self->head_node->next_node;
301
- --self->node_count;
302
- #{free}(node);
303
- return result;
304
- }
305
- #{define} void #{push}(#{type_ref} self, #{element.type} element) {
306
- #{node}* node;
307
- #{assert}(self);
308
- node = (#{node}*)#{malloc}(sizeof(#{node})); #{assert}(node);
309
- #{element.copy("node->element", "element")};
310
- node->next_node = self->head_node;
311
- self->head_node = node;
312
- ++self->node_count;
313
- }
314
- #{define} int #{contains}(#{type_ref} self, #{element.type} what) {
315
- #{node}* node;
316
- int found = 0;
317
- #{assert}(self);
318
- node = self->head_node;
319
- while(node) {
320
- if(#{element.equal("node->element", "what")}) {
321
- found = 1;
322
- break;
323
- }
324
- node = node->next_node;
325
- }
326
- return found;
327
- }
328
- #{define} #{element.type} #{find}(#{type_ref} self, #{element.type} what) {
329
- #{node}* node;
330
- #{assert}(self);
331
- #{assert}(#{contains}(self, what));
332
- node = self->head_node;
333
- while(node) {
334
- if(#{element.equal("node->element", "what")}) {
335
- #{element.type} result;
336
- #{element.copy("result", "node->element")};
337
- return result;
338
- }
339
- node = node->next_node;
340
- }
341
- #{abort}();
342
- }
343
- /* FIXME: for the generality's sake there should be both `what` and `with` values
344
- This is not achievable without breaking the interface, however,
345
- therefore defer this change to the major version bump */
346
- #{define} int #{replaceEx}(#{type_ref} self, #{element.type} with, int count) {
347
- #{node}* node;
348
- int replaced = 0;
349
- #{assert}(self);
350
- if(count == 0) return 0;
351
- node = self->head_node;
352
- while(node) {
353
- if(#{element.equal("node->element", "with")}) {
354
- #{element.dtor("node->element")};
355
- #{element.copy("node->element", "with")};
356
- ++replaced;
357
- if(count > 0 && replaced >= count) break;
358
- }
359
- node = node->next_node;
360
- }
361
- return replaced;
362
- }
363
- #{define} int #{removeEx}(#{type_ref} self, #{element.type} what, int count) {
364
- #{node} *node, *prev_node;
365
- int removed = 0;
366
- #{assert}(self);
367
- if(count == 0) return 0;
368
- node = self->head_node;
369
- prev_node = NULL;
370
- while(node) {
371
- if(#{element.equal("node->element", "what")}) {
372
- #{node}* this_node;
373
- if(prev_node) {
374
- this_node = prev_node->next_node = node->next_node;
375
- } else {
376
- this_node = self->head_node = node->next_node;
377
- }
378
- ++removed;
379
- --self->node_count;
380
- #{element.dtor("node->element")};
381
- #{free}(node);
382
- node = this_node;
383
- if(count > 0 && removed >= count) break;
384
- } else {
385
- prev_node = node;
386
- node = node->next_node;
387
- }
388
- }
389
- return removed;
390
- }
391
- #{define} size_t #{size}(#{type_ref} self) {
392
- #{assert}(self);
393
- return self->node_count;
394
- }
395
- #{define} void #{itCtor}(#{it_ref} self, #{type_ref} list) {
396
- #{assert}(self);
397
- #{assert}(list);
398
- self->start = 1;
399
- self->list = list;
400
- }
401
- #{define} int #{itMove}(#{it_ref} self) {
402
- #{assert}(self);
403
- if(self->start) {
404
- self->this_node = self->list->head_node;
405
- self->start = 0;
406
- } else {
407
- self->this_node = self->this_node ? self->this_node->next_node : NULL;
408
- }
409
- return self->this_node != NULL;
410
- }
411
- #{define} #{element.type} #{itGet}(#{it_ref} self) {
412
- #{element.type} result;
413
- #{assert}(self);
414
- #{assert}(self->this_node);
415
- #{element.copy("result", "self->this_node->element")};
416
- return result;
417
- }
418
- static #{element.type_ref} #{itGetRef}(#{it_ref} self) {
419
- #{assert}(self);
420
- #{assert}(self->this_node);
421
- return &self->this_node->element;
422
- }
423
- $
424
- end
425
-
426
- end # List
427
-
428
-
429
- end # AutoC
@@ -1,41 +0,0 @@
1
- module AutoC
2
-
3
- # :nodoc:
4
- module Maps
5
-
6
- def write_intf_types(stream)
7
- super
8
- stream << %$
9
- /***
10
- **** #{type}<#{key.type} -> #{value.type}>
11
- ***/
12
- $ if public?
13
- end
14
-
15
- def write_intf_decls(stream, declare, define)
16
- super
17
- stream << %$
18
- #{declare} #{ctor.declaration};
19
- #{declare} #{dtor.declaration};
20
- #{declare} #{copy.declaration};
21
- #{declare} #{equal.declaration};
22
- #{declare} #{identify.declaration};
23
- #{declare} void #{purge}(#{type_ref});
24
- #{declare} size_t #{size}(#{type_ref});
25
- #define #{empty}(self) (#{size}(self) == 0)
26
- #{declare} int #{containsKey}(#{type_ref}, #{key.type});
27
- #{declare} #{value.type} #{get}(#{type_ref}, #{key.type});
28
- #{declare} int #{put}(#{type_ref}, #{key.type}, #{value.type});
29
- #{declare} int #{replace}(#{type_ref}, #{key.type}, #{value.type});
30
- #{declare} int #{remove}(#{type_ref}, #{key.type});
31
- #{declare} int #{itMove}(#{it_ref});
32
- #{declare} #{key.type} #{itGetKey}(#{it_ref});
33
- #{declare} #{value.type} #{itGetElement}(#{it_ref});
34
- #define #{itGet}(it) #{itGetElement}(it)
35
- $
36
- end
37
-
38
- end # Maps
39
-
40
-
41
- end # AutoC