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,385 +0,0 @@
1
- require "autoc/collection"
2
- require "autoc/collection/hash_set"
3
-
4
-
5
- require "autoc/collection/map"
6
-
7
-
8
- module AutoC
9
-
10
-
11
- =begin
12
-
13
- HashMap< *_K_* => *_E_* > is a hash-based unordered random access container holding unique keys with each key having an element bound to it.
14
-
15
- HashMap is backed by {AutoC::HashSet} container.
16
-
17
- The collection's C++ counterpart is +std::unordered_map<>+ template class.
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 map +dst+ filled with the contents of +src+.
28
- A copy operation is performed on all keys and values in +src+.
29
-
30
- NOTE: Previous contents of +dst+ is overwritten.
31
-
32
- |*_void_* ~type~Ctor(*_Type_* * +self+)
33
- |
34
- Create a new empty map +self+.
35
-
36
- NOTE: Previous contents of +self+ is overwritten.
37
-
38
- |*_void_* ~type~Dtor(*_Type_* * +self+)
39
- |
40
- Destroy map +self+.
41
- Stored keys and values 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 maps +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 map +self+.
50
- |===
51
-
52
- === Basic operations
53
-
54
- [cols=2*]
55
- |===
56
- |*_int_* ~type~ContainsKey(*_Type_* * +self+, *_K_* +key+)
57
- |
58
- Return non-zero value if map +self+ contains an entry with a key considered equal to the key +key+ and zero value otherwise.
59
-
60
- |*_int_* ~type~Empty(*_Type_* * +self+)
61
- |
62
- Return non-zero value if map +self+ contains no entries and zero value otherwise.
63
-
64
- |*_E_* ~type~Get(*_Type_* * +self+, *_K_* +key+)
65
- |
66
- Return a _copy_ of the element in +self+ bound to a key which is considered equal to the key +key+.
67
-
68
- WARNING: +self+ *must* contain such key otherwise the behavior is undefined. See ~type~ContainsKey().
69
-
70
- |*_void_* ~type~Purge(*_Type_* * +self+)
71
- |
72
- Remove and destroy all keys and elements stored in +self+.
73
-
74
- |*_int_* ~type~Put(*_Type_* * +self+, *_K_* +key+, *_E_* +value+)
75
- |
76
- Put a _copy_ of the element +value+ bound to a _copy_ of the key +key+ into +self+ *only if* there is no such key in +self+ which is considered equal to +key+.
77
-
78
- Return non-zero value on successful put and zero value otherwise.
79
-
80
- |*_int_* ~type~Replace(*_Type_* * +self+, *_K_* +key+, *_E_* +value+)
81
- |
82
- If +self+ contains a key which is considered equal to the key +key+,
83
- remove and destroy that key along with an element bound to it
84
- and put a new pair built of the _copies_ of +key+ and +value+,
85
- otherwise no nothing.
86
-
87
- Return non-zero value if the replacement was actually performed and zero value otherwise.
88
-
89
- |*_int_* ~type~Remove(*_Type_* * +self+, *_K_* +key+)
90
- |
91
- Remove and destroy a key which is considered equal to the key +key+.
92
- Destroy an element bound to that key.
93
-
94
- Return non-zero value on successful key/element pair removal and zero value otherwise.
95
-
96
- |*_size_t_* ~type~Size(*_Type_* * +self+)
97
- |
98
- Return number of key/element pairs stored in +self+.
99
- |===
100
-
101
- === Iteration
102
-
103
- [cols=2*]
104
- |===
105
- |*_void_* ~it~Ctor(*_IteratorType_* * +it+, *_Type_* * +self+)
106
- |
107
- Create a new iterator +it+ on map +self+.
108
-
109
- NOTE: As the map is an unordered sequence, the traversal order is unspecified.
110
-
111
- NOTE: Previous contents of +it+ is overwritten.
112
-
113
- |*_int_* ~it~Move(*_IteratorType_* * +it+)
114
- |
115
- Advance iterator position of +it+ *and* return non-zero value if new position is valid and zero value otherwise.
116
-
117
- |*_K_* ~it~GetKey(*_IteratorType_* * +it+)
118
- |
119
- Return a _copy_ of the key from a key/value pair pointed to by the iterator +it+.
120
-
121
- WARNING: current position *must* be valid otherwise the behavior is undefined. See ~it~Move().
122
-
123
- |*_E_* ~it~GetElement(*_IteratorType_* * +it+)
124
- |
125
- Return a _copy_ of the element from a key/element pair pointed to by the iterator +it+.
126
-
127
- WARNING: current position *must* be valid otherwise the behavior is undefined. See ~it~Move().
128
-
129
- |*_E_* ~it~Get(*_IteratorType_* * +it+)
130
- |
131
- Alias for ~it~GetElement().
132
- |===
133
-
134
- =end
135
- class HashMap < Collection
136
-
137
- include Maps
138
-
139
- attr_reader :key
140
-
141
- alias :value :element
142
-
143
- def hash; super ^ key.hash end
144
-
145
- def ==(other) super && key == other.key end
146
-
147
- alias :eql? :==
148
-
149
- def entities; super << key end
150
-
151
- def initialize(type, key_type, value_type, visibility = :public)
152
- super(type, value_type, visibility)
153
- @key = Type.coerce(key_type)
154
- @entry = UserDefinedType.new(:type => entry, :identify => entryIdentify, :equal => entryEqual, :copy => entryCopy, :dtor => entryDtor)
155
- @set = HashSet.new(set, @entry, :static)
156
- element_requirement(value)
157
- key_requirement(key)
158
- end
159
-
160
- def copyable?; super && key.copyable? end
161
-
162
- def comparable?; super && key.comparable? end
163
-
164
- def hashable?; super && key.hashable? end
165
-
166
- def write_intf_types(stream)
167
- super
168
- stream << %$
169
- typedef struct #{@entry.type} #{@entry.type};
170
- struct #{@entry.type} {
171
- #{key.type} key;
172
- #{value.type} value;
173
- unsigned flags;
174
- };
175
- $
176
- @set.write_intf_types(stream)
177
- stream << %$
178
- typedef struct #{type} #{type};
179
- typedef struct #{it} #{it};
180
- struct #{type} {
181
- #{@set.type} entries;
182
- };
183
- struct #{it} {
184
- #{@set.it} it;
185
- };
186
- $
187
- end
188
-
189
- def write_intf_decls(stream, declare, define)
190
- super
191
- stream << %$
192
- #{declare} void #{itCtor}(#{it_ref}, #{type_ref});
193
- $
194
- end
195
-
196
- def write_impls(stream, define)
197
- super
198
- stream << %$
199
- #define #{validValue} 1
200
- #define #{validKey} 2
201
- #define #{ownedValue} 4
202
- #define #{ownedKey} 8
203
- static #{@entry.type} #{entryKeyOnlyRef}(#{key.type_ref} key) {
204
- #{@entry.type} entry;
205
- entry.key = *key;
206
- entry.flags = #{validKey};
207
- return entry;
208
- }
209
- static #{@entry.type} #{entryKeyValueRef}(#{key.type_ref} key, #{value.type_ref} value) {
210
- #{@entry.type} entry;
211
- entry.key = *key;
212
- entry.value = *value;
213
- entry.flags = (#{validKey} | #{validValue});
214
- return entry;
215
- }
216
- #define #{entryIdentify}(obj) #{entryIdentifyRef}(&obj)
217
- static size_t #{entryIdentifyRef}(#{@entry.type}* entry) {
218
- return #{key.identify("entry->key")};
219
- }
220
- #define #{entryEqual}(lt, rt) #{entryEqualRef}(&lt, &rt)
221
- static int #{entryEqualRef}(#{@entry.type}* lt, #{@entry.type}* rt) {
222
- return #{key.equal("lt->key", "rt->key")};
223
- }
224
- #define #{entryCopy}(dst, src) #{entryCopyRef}(&dst, &src)
225
- static void #{entryCopyRef}(#{@entry.type_ref} dst, #{@entry.type_ref} src) {
226
- #{assert}(src->flags & #{validKey});
227
- dst->flags = (#{validKey} | #{ownedKey});
228
- #{key.copy("dst->key", "src->key")};
229
- if(src->flags & #{validValue}) {
230
- dst->flags |= (#{validValue} | #{ownedValue});
231
- #{value.copy("dst->value", "src->value")};
232
- }
233
- }
234
- #define #{entryDtor}(obj) #{entryDtorRef}(&obj)
235
- static void #{entryDtorRef}(#{@entry.type}* entry) {
236
- #{assert}(entry->flags & #{validKey});
237
- if(entry->flags & #{ownedKey}) #{key.dtor("entry->key")};
238
- if(entry->flags & #{validValue} && entry->flags & #{ownedValue}) #{value.dtor("entry->value")};
239
- }
240
- static #{@entry.type_ref} #{itGetEntryRef}(#{it_ref});
241
- static int #{containsAllOf}(#{type_ref} self, #{type_ref} other) {
242
- #{it} it;
243
- #{itCtor}(&it, self);
244
- while(#{itMove}(&it)) {
245
- int found = 0;
246
- #{@entry.type}* e = #{itGetEntryRef}(&it);
247
- if(#{containsKey}(other, e->key)) {
248
- #{value.type} other_value = #{get}(other, e->key);
249
- found = #{value.equal("e->value", "other_value")};
250
- #{value.dtor("other_value")};
251
- }
252
- if(!found) return 0;
253
- }
254
- return 1;
255
- }
256
- $
257
- @set.write_intf_decls(stream, static, inline)
258
- @set.write_impls(stream, static)
259
- stream << %$
260
- #{define} #{ctor.definition} {
261
- #{assert}(self);
262
- #{@set.ctor}(&self->entries);
263
- }
264
- #{define} #{dtor.definition} {
265
- #{assert}(self);
266
- #{@set.dtor}(&self->entries);
267
- }
268
- static int #{putEntryRef}(#{type_ref} self, #{@entry.type_ref} entry) {
269
- int absent;
270
- #{assert}(self);
271
- #{assert}(entry);
272
- absent = !#{containsKey}(self, entry->key);
273
- if(absent) #{@set.put}(&self->entries, *entry);
274
- return absent;
275
- }
276
- #{define} #{copy.definition} {
277
- #{it} it;
278
- #{assert}(src);
279
- #{assert}(dst);
280
- #{ctor}(dst);
281
- #{itCtor}(&it, src);
282
- while(#{itMove}(&it)) {
283
- #{@entry.type}* e = #{itGetEntryRef}(&it);
284
- #{putEntryRef}(dst, e);
285
- }
286
- }
287
- #{define} #{equal.definition} {
288
- #{assert}(lt);
289
- #{assert}(rt);
290
- return #{size}(lt) == #{size}(rt) && #{containsAllOf}(lt, rt) && #{containsAllOf}(rt, lt);
291
- }
292
- #{define} #{identify.definition} {
293
- #{assert}(self);
294
- return #{@set.identify}(&self->entries); /* TODO : make use of the values' hashes */
295
- }
296
- #{define} void #{purge}(#{type_ref} self) {
297
- #{assert}(self);
298
- #{@set.purge}(&self->entries);
299
- }
300
- #{define} size_t #{size}(#{type_ref} self) {
301
- #{assert}(self);
302
- return #{@set.size}(&self->entries);
303
- }
304
- #{define} int #{containsKey}(#{type_ref} self, #{key.type} key) {
305
- int result;
306
- #{@entry.type} entry;
307
- #{assert}(self);
308
- result = #{@set.contains}(&self->entries, entry = #{entryKeyOnlyRef}(&key));
309
- #{@entry.dtor("entry")};
310
- return result;
311
- }
312
- #{define} #{value.type} #{get}(#{type_ref} self, #{key.type} key) {
313
- #{value.type} result;
314
- #{@entry.type} entry, existing_entry;
315
- #{assert}(self);
316
- #{assert}(#{containsKey}(self, key));
317
- existing_entry = #{@set.get}(&self->entries, entry = #{entryKeyOnlyRef}(&key));
318
- #{value.copy("result", "existing_entry.value")};
319
- #{@entry.dtor("existing_entry")};
320
- #{@entry.dtor("entry")};
321
- return result;
322
- }
323
- #{define} int #{put}(#{type_ref} self, #{key.type} key, #{value.type} value) {
324
- int result;
325
- #{@entry.type} entry;
326
- #{assert}(self);
327
- entry = #{entryKeyValueRef}(&key, &value);
328
- result = #{putEntryRef}(self, &entry);
329
- #{@entry.dtor("entry")};
330
- return result;
331
- }
332
- #{define} int #{replace}(#{type_ref} self, #{key.type} key, #{value.type} value) {
333
- int result;
334
- #{@entry.type} entry;
335
- #{assert}(self);
336
- entry = #{entryKeyValueRef}(&key, &value);
337
- result = #{@set.replace}(&self->entries, entry);
338
- #{@entry.dtor("entry")};
339
- return result;
340
- }
341
- #{define} int #{remove}(#{type_ref} self, #{key.type} key) {
342
- int result;
343
- #{@entry.type} entry;
344
- #{assert}(self);
345
- result = #{@set.remove}(&self->entries, entry = #{entryKeyOnlyRef}(&key));
346
- #{@entry.dtor("entry")};
347
- return result;
348
- }
349
- #{define} void #{itCtor}(#{it_ref} self, #{type_ref} map) {
350
- #{assert}(self);
351
- #{assert}(map);
352
- #{@set.itCtor}(&self->it, &map->entries);
353
- }
354
- #{define} int #{itMove}(#{it_ref} self) {
355
- #{assert}(self);
356
- return #{@set.itMove}(&self->it);
357
- }
358
- #{define} #{key.type} #{itGetKey}(#{it_ref} self) {
359
- #{@entry.type_ref} e;
360
- #{key.type} key;
361
- #{assert}(self);
362
- e = #{itGetEntryRef}(self);
363
- #{key.copy("key", "e->key")};
364
- return key;
365
- }
366
- #{define} #{value.type} #{itGetElement}(#{it_ref} self) {
367
- #{@entry.type_ref} e;
368
- #{value.type} value;
369
- #{assert}(self);
370
- e = #{itGetEntryRef}(self);
371
- #{assert}(e->flags & #{validValue});
372
- #{value.copy("value", "e->value")};
373
- return value;
374
- }
375
- static #{@entry.type_ref} #{itGetEntryRef}(#{it_ref} self) {
376
- #{assert}(self);
377
- return #{@set.itGetRef}(&self->it);
378
- }
379
- $
380
- end
381
-
382
- end # HashMap
383
-
384
-
385
- end # AutoC