autoc 1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +3 -0
- data/README.md +149 -0
- data/cmake/AutoC.cmake +39 -0
- data/lib/autoc/allocators.rb +51 -0
- data/lib/autoc/association.rb +126 -0
- data/lib/autoc/box.rb +311 -0
- data/lib/autoc/cmake.rb +54 -0
- data/lib/autoc/collection.rb +83 -110
- data/lib/autoc/composite.rb +333 -0
- data/lib/autoc/cstring.rb +263 -0
- data/lib/autoc/function.rb +247 -0
- data/lib/autoc/hash_map.rb +328 -0
- data/lib/autoc/hash_set.rb +339 -0
- data/lib/autoc/hashers.rb +102 -0
- data/lib/autoc/list.rb +444 -0
- data/lib/autoc/module.rb +434 -0
- data/lib/autoc/openmp.rb +15 -0
- data/lib/autoc/primitive.rb +27 -0
- data/lib/autoc/ranges.rb +707 -0
- data/lib/autoc/record.rb +247 -0
- data/lib/autoc/scaffold/docs.rb +117 -0
- data/lib/autoc/scaffold/generic_value.rb +86 -0
- data/lib/autoc/scaffold/project.rb +75 -0
- data/lib/autoc/scaffold/test_cstring.rb +113 -0
- data/lib/autoc/scaffold/test_cstring_hash_set.rb +35 -0
- data/lib/autoc/scaffold/test_int_box.rb +22 -0
- data/lib/autoc/scaffold/test_int_hash_set.rb +448 -0
- data/lib/autoc/scaffold/test_int_list.rb +106 -0
- data/lib/autoc/scaffold/test_int_vector.rb +83 -0
- data/lib/autoc/scaffold/test_v2v_hash_map.rb +83 -0
- data/lib/autoc/scaffold/test_value_hash_set.rb +60 -0
- data/lib/autoc/scaffold/test_value_vector.rb +146 -0
- data/{test/test.rb → lib/autoc/scaffold/tests.rb} +179 -158
- data/lib/autoc/scaffold.rb +12 -0
- data/lib/autoc/sequential.rb +99 -0
- data/lib/autoc/set.rb +331 -0
- data/lib/autoc/std.rb +149 -0
- data/lib/autoc/type.rb +93 -531
- data/lib/autoc/vector.rb +290 -0
- data/lib/autoc.rb +4 -35
- metadata +55 -85
- data/.yardopts +0 -4
- data/CHANGES +0 -23
- data/README +0 -28
- data/doc/AutoC/Code.html +0 -523
- data/doc/AutoC/Collection.html +0 -1214
- data/doc/AutoC/HashMap.html +0 -1441
- data/doc/AutoC/HashSet.html +0 -916
- data/doc/AutoC/Iterators/Bidirectional.html +0 -204
- data/doc/AutoC/Iterators/Unidirectional.html +0 -200
- data/doc/AutoC/Iterators.html +0 -126
- data/doc/AutoC/List.html +0 -1039
- data/doc/AutoC/Maps.html +0 -290
- data/doc/AutoC/Module/File.html +0 -415
- data/doc/AutoC/Module/Header.html +0 -437
- data/doc/AutoC/Module/Source.html +0 -707
- data/doc/AutoC/Module.html +0 -948
- data/doc/AutoC/Priority.html +0 -138
- data/doc/AutoC/Queue.html +0 -1172
- data/doc/AutoC/Reference.html +0 -735
- data/doc/AutoC/Sets.html +0 -520
- data/doc/AutoC/String.html +0 -1394
- data/doc/AutoC/TreeMap.html +0 -1565
- data/doc/AutoC/TreeSet.html +0 -1447
- data/doc/AutoC/Type.html +0 -2148
- data/doc/AutoC/UserDefinedType.html +0 -1047
- data/doc/AutoC/Vector.html +0 -987
- data/doc/AutoC.html +0 -331
- data/doc/_index.html +0 -388
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -481
- data/doc/file.CHANGES.html +0 -117
- data/doc/file.README.html +0 -116
- data/doc/file_list.html +0 -61
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -116
- data/doc/js/app.js +0 -243
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -1307
- data/doc/top-level-namespace.html +0 -112
- data/lib/autoc/code.rb +0 -237
- data/lib/autoc/collection/hash_map.rb +0 -385
- data/lib/autoc/collection/hash_set.rb +0 -337
- data/lib/autoc/collection/iterator.rb +0 -39
- data/lib/autoc/collection/list.rb +0 -429
- data/lib/autoc/collection/map.rb +0 -41
- data/lib/autoc/collection/queue.rb +0 -517
- data/lib/autoc/collection/set.rb +0 -134
- data/lib/autoc/collection/tree_map.rb +0 -464
- data/lib/autoc/collection/tree_set.rb +0 -611
- data/lib/autoc/collection/vector.rb +0 -336
- data/lib/autoc/string.rb +0 -492
- data/test/test_auto.c +0 -7141
- data/test/test_auto.h +0 -753
- data/test/test_char_string.rb +0 -270
- data/test/test_int_list.rb +0 -35
- data/test/test_int_tree_set.rb +0 -111
- data/test/test_int_vector.rb +0 -34
- data/test/test_value_hash_map.rb +0 -162
- data/test/test_value_hash_set.rb +0 -173
- data/test/test_value_list.rb +0 -193
- data/test/test_value_queue.rb +0 -275
- data/test/test_value_tree_map.rb +0 -176
- data/test/test_value_tree_set.rb +0 -173
- data/test/test_value_vector.rb +0 -155
- data/test/value.rb +0 -80
@@ -1,336 +0,0 @@
|
|
1
|
-
require "autoc/collection"
|
2
|
-
|
3
|
-
|
4
|
-
require "autoc/collection/iterator"
|
5
|
-
|
6
|
-
|
7
|
-
module AutoC
|
8
|
-
|
9
|
-
|
10
|
-
=begin
|
11
|
-
|
12
|
-
Vector< *_E_* > is an ordered random access sequence container.
|
13
|
-
|
14
|
-
The collection's C++ counterpart is +std::vector<>+ template class.
|
15
|
-
|
16
|
-
== Generated C interface
|
17
|
-
|
18
|
-
=== Collection management
|
19
|
-
|
20
|
-
[cols="2*"]
|
21
|
-
|===
|
22
|
-
|*_void_* ~type~Copy(*_Type_* * +dst+, *_Type_* * +src+)
|
23
|
-
|
|
24
|
-
Create a new vector +dst+ filled with the contents of +src+.
|
25
|
-
A copy operation is performed on every element in +src+.
|
26
|
-
|
27
|
-
NOTE: Previous contents of +dst+ is overwritten.
|
28
|
-
|
29
|
-
|*_void_* ~type~Ctor(*_Type_* * +self+, *_size_t_* +size+)
|
30
|
-
|
|
31
|
-
Create a new vector +self+ of size +size+.
|
32
|
-
The elements are initialized with either supplied or generated default parameterless constructor.
|
33
|
-
|
34
|
-
WARNING: +size+ must be greater than zero.
|
35
|
-
|
36
|
-
NOTE: Previous contents of +self+ is overwritten.
|
37
|
-
|
38
|
-
|*_void_* ~type~Dtor(*_Type_* * +self+)
|
39
|
-
|
|
40
|
-
Destroy vector +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 vectors +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 vector +self+.
|
50
|
-
|===
|
51
|
-
|
52
|
-
=== Basic operations
|
53
|
-
|
54
|
-
[cols=2*]
|
55
|
-
|===
|
56
|
-
|*_E_* ~type~Get(*_Type_* * +self+, *_size_t_* +index+)
|
57
|
-
|
|
58
|
-
Return a _copy_ of the element stored in +self+ at position +index+.
|
59
|
-
|
60
|
-
WARNING: +index+ *must* be a valid index otherwise the behavior is undefined. See ~type~Within().
|
61
|
-
|
62
|
-
|*_void_* ~type~Resize(*_Type_* * +self+, *_size_t_* +size+)
|
63
|
-
|
|
64
|
-
Set new size of vector +self+ to +size+.
|
65
|
-
|
66
|
-
If new size is greater than the old one, extra elements are created with default parameterless constructors.
|
67
|
-
If new size is smaller the the old one, excessive elements are destroyed.
|
68
|
-
|
69
|
-
WARNING: +size+ *must* be greater than zero.
|
70
|
-
|
71
|
-
|*_void_* ~type~Set(*_Type_* * +self+, *_size_t_* +index+, *_E_* +what+)
|
72
|
-
|
|
73
|
-
|
74
|
-
Store a _copy_ of the element +what+ in vector +self+ at position +index+ destroying previous contents.
|
75
|
-
|
76
|
-
WARNING: +index+ *must* be a valid index otherwise the behavior is undefined. See ~type~Within().
|
77
|
-
|
78
|
-
|*_size_t_* ~type~Size(*_Type_* * +self+)
|
79
|
-
|
|
80
|
-
Return number of elements stored in vector +self+.
|
81
|
-
|
82
|
-
|*_void_* ~type~Sort(*_Type_* * +self+)
|
83
|
-
|
|
84
|
-
Perform an ascending sort.
|
85
|
-
See ~type~SortEx().
|
86
|
-
|
87
|
-
NOTE : optional operation.
|
88
|
-
|
89
|
-
|*_void_* ~type~SortEx(*_Type_* * +self+, *_int_* ascending)
|
90
|
-
|
|
91
|
-
NOTE : optional operation.
|
92
|
-
|
93
|
-
Perform a sort operation on the contents of vector +self+ utilizing either generated of user supplied ordering functions.
|
94
|
-
If the +ascending+ is non-zero, perform the sorting in ascending order otherwise perform the soring in descending order.
|
95
|
-
|
96
|
-
Note that this operation is defined only if element type is orderable, e.g. has equality testing and comparison operations defined.
|
97
|
-
|
98
|
-
|*_int_* ~type~Within(*_Type_* * +self+, *_size_t_* +index+)
|
99
|
-
|
|
100
|
-
Return non-zero value if +index+ is a valid index and zero value otherwise.
|
101
|
-
Valid index belongs to the range 0 ... ~type~Size()-1.
|
102
|
-
|===
|
103
|
-
|
104
|
-
=== Iteration
|
105
|
-
|
106
|
-
[cols=2*]
|
107
|
-
|===
|
108
|
-
|*_void_* ~it~Ctor(*_IteratorType_* * +it+, *_Type_* * +self+)
|
109
|
-
|
|
110
|
-
Create a new forward iterator +it+ on vector +self+.
|
111
|
-
|
112
|
-
NOTE: Previous contents of +it+ is overwritten.
|
113
|
-
|
114
|
-
|*_void_* ~it~CtorEx(*_IteratorType_* * +it+, *_Type_* * +self+, *_int_* +forward+)
|
115
|
-
|
|
116
|
-
Create a new iterator +it+ on vector +self+.
|
117
|
-
Non-zero value of +forward+ specifies a forward iterator, zero value specifies a backward iterator.
|
118
|
-
|
119
|
-
NOTE: Previous contents of +it+ is overwritten.
|
120
|
-
|
121
|
-
|*_int_* ~it~Move(*_IteratorType_* * +it+)
|
122
|
-
|
|
123
|
-
Advance iterator position of +it+ *and* return non-zero value if new position is valid and zero value otherwise.
|
124
|
-
|
125
|
-
|*_E_* ~it~Get(*_IteratorType_* * +it+)
|
126
|
-
|
|
127
|
-
Return a _copy_ of current element pointed to by the iterator +it+.
|
128
|
-
|
129
|
-
WARNING: current position *must* be valid otherwise the behavior is undefined. See ~it~Move().
|
130
|
-
|===
|
131
|
-
|
132
|
-
=end
|
133
|
-
class Vector < Collection
|
134
|
-
|
135
|
-
include Iterators::Bidirectional
|
136
|
-
|
137
|
-
def initialize(*args)
|
138
|
-
super
|
139
|
-
# Override the default type constructor as the Vector's requires one extra parameter
|
140
|
-
# Note that this makes the Vector instance non-constructible
|
141
|
-
@ctor = define_redirector(:ctor, Function::Signature.new([type_ref^:self, :size_t^:element_count]))
|
142
|
-
end
|
143
|
-
|
144
|
-
# No default constructor provided
|
145
|
-
def constructible?; false end
|
146
|
-
|
147
|
-
def write_intf_types(stream)
|
148
|
-
super
|
149
|
-
stream << %$
|
150
|
-
/***
|
151
|
-
**** #{type}<#{element.type}>
|
152
|
-
***/
|
153
|
-
$ if public?
|
154
|
-
stream << %$
|
155
|
-
typedef struct #{type} #{type};
|
156
|
-
typedef struct #{it} #{it};
|
157
|
-
struct #{type} {
|
158
|
-
#{element.type_ref} values;
|
159
|
-
size_t element_count;
|
160
|
-
};
|
161
|
-
struct #{it} {
|
162
|
-
#{type_ref} vector;
|
163
|
-
int index, forward;
|
164
|
-
};
|
165
|
-
$
|
166
|
-
end
|
167
|
-
|
168
|
-
def write_intf_decls(stream, declare, define)
|
169
|
-
super(stream, define, define) # Need to make prototypes static inline
|
170
|
-
stream << %$
|
171
|
-
#{declare} #{ctor.declaration};
|
172
|
-
#{declare} #{dtor.declaration};
|
173
|
-
#{declare} #{copy.declaration};
|
174
|
-
/* TODO #{copyRange}() */
|
175
|
-
#{declare} #{equal.declaration};
|
176
|
-
#{declare} #{identify.declaration};
|
177
|
-
#{declare} void #{resize}(#{type_ref}, size_t);
|
178
|
-
#{define} size_t #{size}(#{type_ref} self) {
|
179
|
-
#{assert}(self);
|
180
|
-
return self->element_count;
|
181
|
-
}
|
182
|
-
#{define} int #{within}(#{type_ref} self, size_t index) {
|
183
|
-
#{assert}(self);
|
184
|
-
return index < #{size}(self);
|
185
|
-
}
|
186
|
-
#{define} #{element.type} #{get}(#{type_ref} self, size_t index) {
|
187
|
-
#{element.type} result;
|
188
|
-
#{assert}(self);
|
189
|
-
#{assert}(#{within}(self, index));
|
190
|
-
#{element.copy("result", "self->values[index]")};
|
191
|
-
return result;
|
192
|
-
}
|
193
|
-
#{define} void #{set}(#{type_ref} self, size_t index, #{element.type} value) {
|
194
|
-
#{assert}(self);
|
195
|
-
#{assert}(#{within}(self, index));
|
196
|
-
#{element.dtor("self->values[index]")};
|
197
|
-
#{element.copy("self->values[index]", "value")};
|
198
|
-
}
|
199
|
-
#{define} void #{itCtorEx}(#{it_ref} self, #{type_ref} vector, int forward) {
|
200
|
-
#{assert}(self);
|
201
|
-
#{assert}(vector);
|
202
|
-
self->vector = vector;
|
203
|
-
self->forward = forward;
|
204
|
-
self->index = forward ? -1 : #{size}(vector);
|
205
|
-
}
|
206
|
-
#{define} int #{itMove}(#{it_ref} self) {
|
207
|
-
#{assert}(self);
|
208
|
-
if(self->forward) ++self->index; else --self->index;
|
209
|
-
return #{within}(self->vector, self->index);
|
210
|
-
}
|
211
|
-
#{define} #{element.type} #{itGet}(#{it_ref} self) {
|
212
|
-
#{assert}(self);
|
213
|
-
return #{get}(self->vector, self->index);
|
214
|
-
}
|
215
|
-
$
|
216
|
-
stream << %$
|
217
|
-
#define #{sort}(self) #{sortEx}(self, 1)
|
218
|
-
#{declare} void #{sortEx}(#{type_ref}, int);
|
219
|
-
$ if element.orderable?
|
220
|
-
end
|
221
|
-
|
222
|
-
def write_impls(stream, define)
|
223
|
-
super
|
224
|
-
stream << %$
|
225
|
-
static void #{allocate}(#{type_ref} self, size_t element_count) {
|
226
|
-
#{assert}(self);
|
227
|
-
#{assert}(element_count > 0);
|
228
|
-
self->element_count = element_count;
|
229
|
-
self->values = (#{element.type}*)#{malloc}(element_count*sizeof(#{element.type})); #{assert}(self->values);
|
230
|
-
}
|
231
|
-
#{define} #{ctor.definition} {
|
232
|
-
size_t index;
|
233
|
-
#{assert}(self);
|
234
|
-
#{allocate}(self, element_count);
|
235
|
-
for(index = 0; index < #{size}(self); ++index) {
|
236
|
-
#{element.ctor("self->values[index]")};
|
237
|
-
}
|
238
|
-
}
|
239
|
-
#{define} #{dtor.definition} {
|
240
|
-
size_t index;
|
241
|
-
#{assert}(self);
|
242
|
-
for(index = 0; index < #{size}(self); ++index) {
|
243
|
-
#{element.dtor("self->values[index]")};
|
244
|
-
}
|
245
|
-
#{free}(self->values);
|
246
|
-
}
|
247
|
-
#{define} #{copy.definition} {
|
248
|
-
size_t index, size;
|
249
|
-
#{assert}(src);
|
250
|
-
#{assert}(dst);
|
251
|
-
#{allocate}(dst, size = #{size}(src));
|
252
|
-
for(index = 0; index < size; ++index) {
|
253
|
-
#{element.copy("dst->values[index]", "src->values[index]")};
|
254
|
-
}
|
255
|
-
}
|
256
|
-
#{define} #{equal.definition} {
|
257
|
-
size_t index, size;
|
258
|
-
#{assert}(lt);
|
259
|
-
#{assert}(rt);
|
260
|
-
if(#{size}(lt) == (size = #{size}(rt))) {
|
261
|
-
for(index = 0; index < size; ++index) {
|
262
|
-
if(!#{element.equal("lt->values[index]", "rt->values[index]")}) return 0;
|
263
|
-
}
|
264
|
-
return 1;
|
265
|
-
} else
|
266
|
-
return 0;
|
267
|
-
}
|
268
|
-
#{define} #{identify.definition} {
|
269
|
-
size_t index, result = 0;
|
270
|
-
#{assert}(self);
|
271
|
-
for(index = 0; index < self->element_count; ++index) {
|
272
|
-
result ^= #{element.identify("self->values[index]")};
|
273
|
-
result = AUTOC_RCYCLE(result);
|
274
|
-
}
|
275
|
-
return result;
|
276
|
-
}
|
277
|
-
#{define} void #{resize}(#{type_ref} self, size_t new_element_count) {
|
278
|
-
size_t index, element_count, from, to;
|
279
|
-
#{assert}(self);
|
280
|
-
if((element_count = #{size}(self)) != new_element_count) {
|
281
|
-
#{element.type_ref} values = (#{element.type_ref})#{malloc}(new_element_count*sizeof(#{element.type})); #{assert}(values);
|
282
|
-
from = AUTOC_MIN(element_count, new_element_count);
|
283
|
-
to = AUTOC_MAX(element_count, new_element_count);
|
284
|
-
for(index = 0; index < from; ++index) {
|
285
|
-
values[index] = self->values[index];
|
286
|
-
}
|
287
|
-
if(element_count > new_element_count) {
|
288
|
-
for(index = from; index < to; ++index) {
|
289
|
-
#{element.dtor("self->values[index]")};
|
290
|
-
}
|
291
|
-
} else {
|
292
|
-
for(index = from; index < to; ++index) {
|
293
|
-
#{element.ctor("values[index]")};
|
294
|
-
}
|
295
|
-
}
|
296
|
-
#{free}(self->values);
|
297
|
-
self->values = values;
|
298
|
-
self->element_count = new_element_count;
|
299
|
-
}
|
300
|
-
}
|
301
|
-
$
|
302
|
-
stream << %$
|
303
|
-
static int #{ascend}(void* lp_, void* rp_) {
|
304
|
-
#{element.type_ref} lp = (#{element.type_ref})lp_;
|
305
|
-
#{element.type_ref} rp = (#{element.type_ref})rp_;
|
306
|
-
if(#{element.equal("*lp", "*rp")}) {
|
307
|
-
return 0;
|
308
|
-
} else if(#{element.less("*lp", "*rp")}) {
|
309
|
-
return -1;
|
310
|
-
} else {
|
311
|
-
return +1;
|
312
|
-
}
|
313
|
-
}
|
314
|
-
static int #{descend}(void* lp_, void* rp_) {
|
315
|
-
return -#{ascend}(lp_, rp_);
|
316
|
-
}
|
317
|
-
#{define} void #{sortEx}(#{type_ref} self, int ascending) {
|
318
|
-
typedef int (*F)(const void*, const void*);
|
319
|
-
#{assert}(self);
|
320
|
-
qsort(self->values, #{size}(self), sizeof(#{element.type}), ascending ? (F)#{ascend} : (F)#{descend});
|
321
|
-
}
|
322
|
-
$ if element.orderable?
|
323
|
-
end
|
324
|
-
|
325
|
-
private
|
326
|
-
|
327
|
-
def element_requirement(obj)
|
328
|
-
# Vector requires the element to have default parameterless constructor
|
329
|
-
raise "type #{obj.type} (#{obj}) must be constructible" unless obj.constructible?
|
330
|
-
super
|
331
|
-
end
|
332
|
-
|
333
|
-
end # Vector
|
334
|
-
|
335
|
-
|
336
|
-
end # AutoC
|