carray 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSES +22 -0
- data/README.md +18 -14
- data/Rakefile +1 -1
- data/carray.gemspec +5 -13
- data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
- data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
- data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
- data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
- data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
- data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
- data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
- data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
- data/{carray.h → ext/carray.h} +73 -51
- data/{carray_access.c → ext/carray_access.c} +83 -83
- data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
- data/{carray_cast.c → ext/carray_cast.c} +6 -6
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
- data/{carray_class.c → ext/carray_class.c} +0 -0
- data/{carray_conversion.c → ext/carray_conversion.c} +8 -10
- data/{carray_copy.c → ext/carray_copy.c} +19 -19
- data/{carray_core.c → ext/carray_core.c} +2 -2
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +9 -9
- data/{carray_generate.c → ext/carray_generate.c} +0 -0
- data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
- data/{carray_loop.c → ext/carray_loop.c} +24 -24
- data/{carray_mask.c → ext/carray_mask.c} +17 -6
- data/{carray_math.rb → ext/carray_math.rb} +3 -3
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
- data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
- data/{carray_operator.c → ext/carray_operator.c} +9 -9
- data/{carray_order.c → ext/carray_order.c} +2 -153
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
- data/{carray_stat.c → ext/carray_stat.c} +5 -5
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
- data/{carray_test.c → ext/carray_test.c} +22 -21
- data/{carray_undef.c → ext/carray_undef.c} +0 -0
- data/{carray_utils.c → ext/carray_utils.c} +0 -0
- data/{extconf.rb → ext/extconf.rb} +0 -5
- data/{mkmath.rb → ext/mkmath.rb} +0 -0
- data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
- data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
- data/{version.h → ext/version.h} +5 -5
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +48 -37
- data/lib/carray/{base/autoload.rb → autoload.rb} +1 -1
- data/lib/carray/autoload/autoload_base.rb +1 -1
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +4 -3
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/basic.rb +193 -0
- data/lib/carray/compose.rb +291 -0
- data/lib/carray/construct.rb +445 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
- data/lib/carray/io/imagemagick.rb +1 -1
- data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
- data/lib/carray/mask.rb +91 -0
- data/lib/carray/{base/math.rb → math.rb} +16 -46
- data/lib/carray/math/histogram.rb +7 -7
- data/lib/carray/mkmf.rb +8 -0
- data/lib/carray/object/ca_obj_pack.rb +8 -8
- data/lib/carray/obsolete.rb +272 -0
- data/lib/carray/ordering.rb +157 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
- data/lib/carray/{base/string.rb → string.rb} +12 -64
- data/lib/carray/{base/struct.rb → struct.rb} +16 -16
- data/lib/carray/{io/table.rb → table.rb} +1 -10
- data/lib/carray/testing.rb +56 -0
- data/lib/carray/time.rb +78 -0
- data/lib/carray/transform.rb +100 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- data/test/test_ALL.rb +0 -2
- data/test/test_order.rb +7 -7
- data/test/test_ref_store.rb +13 -13
- data/test/test_stat.rb +7 -15
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +88 -151
- data/COPYING +0 -56
- data/GPL +0 -340
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- data/devel/im2col.rb +0 -17
- data/ext/calculus/carray_calculus.c +0 -931
- data/ext/calculus/carray_interp.c +0 -358
- data/ext/calculus/extconf.rb +0 -12
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/test/test_hypot.rb +0 -5
- data/ext/mathfunc/test/test_j0.rb +0 -22
- data/ext/mathfunc/test/test_jn.rb +0 -8
- data/ext/mathfunc/test/test_sph.rb +0 -9
- data/lib/carray/autoload/autoload_io_table.rb +0 -1
- data/lib/carray/autoload/autoload_math_interp.rb +0 -4
- data/lib/carray/base/basic.rb +0 -1146
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/test/test_narray.rb +0 -64
- data/test/test_random.rb +0 -15
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
@@ -0,0 +1,157 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray/ordering.rb
|
4
|
+
#
|
5
|
+
# This file is part of Ruby/CArray extension library.
|
6
|
+
# You can redistribute it and/or modify it under the terms of
|
7
|
+
# the Ruby Licence.
|
8
|
+
#
|
9
|
+
# Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
#
|
11
|
+
# ----------------------------------------------------------------------------
|
12
|
+
|
13
|
+
class CArray
|
14
|
+
|
15
|
+
# reversed
|
16
|
+
|
17
|
+
def reversed
|
18
|
+
return self[*([-1..0]*ndim)]
|
19
|
+
end
|
20
|
+
|
21
|
+
# roll / shift
|
22
|
+
|
23
|
+
def shift! (*argv, &block)
|
24
|
+
self[] = self.shifted(*argv, &block)
|
25
|
+
return self
|
26
|
+
end
|
27
|
+
|
28
|
+
def shift (*argv, &block)
|
29
|
+
return self.shifted(*argv, &block).to_ca
|
30
|
+
end
|
31
|
+
|
32
|
+
def rolled (*argv)
|
33
|
+
argv.push({:roll => Array.new(ndim){1} })
|
34
|
+
return shifted(*argv)
|
35
|
+
end
|
36
|
+
|
37
|
+
def roll! (*argv)
|
38
|
+
self[] = self.rolled(*argv)
|
39
|
+
return self
|
40
|
+
end
|
41
|
+
|
42
|
+
def roll (*argv)
|
43
|
+
return self.rolled(*argv).to_ca
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Returns the reference which elements are sorted by the comparison method
|
48
|
+
# given as block
|
49
|
+
def sorted_by (type=nil, opt={}, &block)
|
50
|
+
type, bytes =
|
51
|
+
CArray.guess_type_and_bytes(type||data_type, opt[:bytes]||bytes)
|
52
|
+
cmpary = convert(type, :bytes=>bytes, &block)
|
53
|
+
return self[cmpary.sort_addr]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the array which elements are sorted by the comparison method
|
57
|
+
# given as block
|
58
|
+
def sort_by (type=nil, opt={}, &block)
|
59
|
+
type, bytes =
|
60
|
+
CArray.guess_type_and_bytes(type||data_type, opt[:bytes]||bytes)
|
61
|
+
cmpary = convert(type, :bytes=>bytes, &block)
|
62
|
+
return self[cmpary.sort_addr].to_ca
|
63
|
+
end
|
64
|
+
|
65
|
+
def max_by (&block)
|
66
|
+
if empty?
|
67
|
+
return UNDEF
|
68
|
+
else
|
69
|
+
addr = convert(:object, &block).max_addr
|
70
|
+
return self[addr]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def min_by (&block)
|
75
|
+
if empty?
|
76
|
+
return UNDEF
|
77
|
+
else
|
78
|
+
addr = convert(:object, &block).min_addr
|
79
|
+
return self[addr]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def range
|
84
|
+
return (self.min)..(self.max)
|
85
|
+
end
|
86
|
+
|
87
|
+
def nlargest (n)
|
88
|
+
obj = self.to_ca
|
89
|
+
list = []
|
90
|
+
n.times do |i|
|
91
|
+
k = obj.max_addr
|
92
|
+
list << obj[k]
|
93
|
+
obj[k] = UNDEF
|
94
|
+
end
|
95
|
+
list.to_ca.to_type(data_type)
|
96
|
+
end
|
97
|
+
|
98
|
+
def nlargest_addr (n)
|
99
|
+
obj = self.to_ca
|
100
|
+
list = []
|
101
|
+
n.times do |i|
|
102
|
+
k = obj.max_addr
|
103
|
+
list << k
|
104
|
+
obj[k] = UNDEF
|
105
|
+
end
|
106
|
+
CA_INT64(list)
|
107
|
+
end
|
108
|
+
|
109
|
+
def nsmallest (n)
|
110
|
+
obj = self.to_ca
|
111
|
+
list = []
|
112
|
+
n.times do |i|
|
113
|
+
k = obj.min_addr
|
114
|
+
list << obj[k]
|
115
|
+
obj[k] = UNDEF
|
116
|
+
end
|
117
|
+
list.to_ca.to_type(data_type)
|
118
|
+
end
|
119
|
+
|
120
|
+
def nsmallest_addr (n)
|
121
|
+
obj = self.to_ca
|
122
|
+
list = []
|
123
|
+
n.times do |i|
|
124
|
+
k = obj.min_addr
|
125
|
+
list << k
|
126
|
+
obj[k] = UNDEF
|
127
|
+
end
|
128
|
+
CA_INT64(list)
|
129
|
+
end
|
130
|
+
|
131
|
+
def order (dir = 1)
|
132
|
+
if dir >= 0 ### ascending order
|
133
|
+
if has_mask?
|
134
|
+
obj = template(:int32) { UNDEF }
|
135
|
+
sel = is_not_masked
|
136
|
+
obj[sel][self[sel].sort_addr].seq!
|
137
|
+
return obj
|
138
|
+
else
|
139
|
+
obj = template(:int32)
|
140
|
+
obj[sort_addr].seq!
|
141
|
+
return obj
|
142
|
+
end
|
143
|
+
else ### descending order
|
144
|
+
if has_mask?
|
145
|
+
obj = template(:int32) { UNDEF}
|
146
|
+
sel = is_not_masked
|
147
|
+
obj[sel][self[sel].sort_addr.reversed].seq!
|
148
|
+
return obj
|
149
|
+
else
|
150
|
+
obj = template(:int32)
|
151
|
+
obj[sort_addr.reversed].seq!
|
152
|
+
return obj
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# ----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
# carray/
|
3
|
+
# carray/serialize.rb
|
4
4
|
#
|
5
5
|
# This file is part of Ruby/CArray extension library.
|
6
6
|
# You can redistribute it and/or modify it under the terms of
|
@@ -33,7 +33,7 @@
|
|
33
33
|
# offset 20 bytes
|
34
34
|
# data_type : int32 : data type specifier
|
35
35
|
# bytes : int32 : byte size of each data
|
36
|
-
#
|
36
|
+
# ndim : int32 : ndim of array
|
37
37
|
# elements : int32 : number of all elements
|
38
38
|
# has_mask : int32 : 0 (not masked) or 1 (masked)
|
39
39
|
# offset 40 bytes
|
@@ -54,13 +54,26 @@ class CArray::Serializer # :nodoc:
|
|
54
54
|
char_p :endian, :bytes=>4
|
55
55
|
int32 :data_type
|
56
56
|
int64 :bytes
|
57
|
-
int32 :
|
57
|
+
int32 :ndim
|
58
58
|
int64 :elements
|
59
59
|
int32 :has_mask
|
60
60
|
array :dim, :type => CArray.int64(CA_RANK_MAX)
|
61
61
|
int32 :has_attr
|
62
62
|
}
|
63
63
|
|
64
|
+
Header_Legacy = CA.struct(:pack=>1, :size=>256) {
|
65
|
+
char_p :magic_string, :bytes=>8
|
66
|
+
char_p :data_type_name, :bytes=>8
|
67
|
+
char_p :endian, :bytes=>4
|
68
|
+
int32 :data_type
|
69
|
+
int32 :bytes
|
70
|
+
int32 :ndim
|
71
|
+
int32 :elements
|
72
|
+
int32 :has_mask
|
73
|
+
array :dim, :type => CArray.int32(CA_RANK_MAX)
|
74
|
+
int32 :has_attr
|
75
|
+
}
|
76
|
+
|
64
77
|
def initialize (io)
|
65
78
|
case io
|
66
79
|
when String
|
@@ -79,10 +92,10 @@ class CArray::Serializer # :nodoc:
|
|
79
92
|
header[:endian] = ( endian == CA_LITTLE_ENDIAN ) ? "_LE_" : "_BE_"
|
80
93
|
header[:data_type] = ca.data_type
|
81
94
|
header[:bytes] = ca.bytes
|
82
|
-
header[:
|
95
|
+
header[:ndim] = ca.ndim
|
83
96
|
header[:elements] = ca.elements
|
84
97
|
header[:has_mask] = ca.has_mask? ? 1 : 0
|
85
|
-
header[:dim][[0,ca.
|
98
|
+
header[:dim][[0,ca.ndim]] = ca.dim
|
86
99
|
attr = nil
|
87
100
|
if ca.attribute
|
88
101
|
attr = ca.attribute.clone
|
@@ -114,8 +127,12 @@ class CArray::Serializer # :nodoc:
|
|
114
127
|
return ca
|
115
128
|
end
|
116
129
|
|
117
|
-
def load (opt = {})
|
118
|
-
|
130
|
+
def load (opt = {}, legacy: false)
|
131
|
+
if legacy
|
132
|
+
header = Header_Legacy.decode(@io.read(256))
|
133
|
+
else
|
134
|
+
header = Header.decode(@io.read(256))
|
135
|
+
end
|
119
136
|
if header[:magic_string] != "_CARRAY_"
|
120
137
|
raise "not a CArray binary data"
|
121
138
|
end
|
@@ -130,10 +147,10 @@ class CArray::Serializer # :nodoc:
|
|
130
147
|
end
|
131
148
|
data_type = header[:data_type]
|
132
149
|
bytes = header[:bytes]
|
133
|
-
|
150
|
+
ndim = header[:ndim]
|
134
151
|
elements = header[:elements]
|
135
152
|
has_mask = header[:has_mask] != 0 ? true : false
|
136
|
-
dim = header[:dim][[0,
|
153
|
+
dim = header[:dim][[0, ndim]].to_a
|
137
154
|
has_attr = header[:has_attr]
|
138
155
|
if data_type == 255
|
139
156
|
data_type = header[:data_type_name].strip.to_sym
|
@@ -202,7 +219,8 @@ class CArray
|
|
202
219
|
|
203
220
|
def marshal_dump ()
|
204
221
|
if self.class != CArray and self.class != CScalar
|
205
|
-
|
222
|
+
return CArray.dump(self.to_ca)
|
223
|
+
# raise TypeError, "can't dump a virtual or wrapped array."
|
206
224
|
end
|
207
225
|
return CArray.dump(self)
|
208
226
|
end
|
@@ -213,48 +231,5 @@ class CArray
|
|
213
231
|
initialize_copy(ca)
|
214
232
|
end
|
215
233
|
|
216
|
-
### obsolete methods
|
217
|
-
|
218
|
-
def save_binary (filename, opt={}) # :nodoc:
|
219
|
-
warn "CArray#save_binary will be obsolete, use CArray.save"
|
220
|
-
open(filename, "w") { |io|
|
221
|
-
return Serializer.new(io).save(self, opt)
|
222
|
-
}
|
223
|
-
end
|
224
|
-
|
225
|
-
def self.load_binary (filename, opt={}) # :nodoc:
|
226
|
-
warn "CArray.load_binary will be obsolete, use CArray.load"
|
227
|
-
open(filename) { |io|
|
228
|
-
return Serializer.new(io).load(opt)
|
229
|
-
}
|
230
|
-
end
|
231
|
-
|
232
|
-
def save_binary_io (io, opt={}) # :nodoc:
|
233
|
-
warn "CArray#save_binary_io will be obsolete, use CArray.save"
|
234
|
-
return Serializer.new(io).save(self, opt)
|
235
|
-
end
|
236
|
-
|
237
|
-
def self.load_binary_io (io, opt={}) # :nodoc:
|
238
|
-
warn "CArray#load_binary_io will be obsolete, use CArray.load"
|
239
|
-
return Serializer.new(io).load(opt)
|
240
|
-
end
|
241
|
-
|
242
|
-
def to_binary (io="", opt={}) # :nodoc:
|
243
|
-
warn "CArray#to_binary will be obsolete, use CArray.dump"
|
244
|
-
Serializer.new(io).save(self, opt)
|
245
|
-
return io
|
246
|
-
end
|
247
|
-
|
248
|
-
def self.from_binary (io, opt={}) # :nodoc:
|
249
|
-
warn "CArray.from_binary will be obsolete, use CArray.load"
|
250
|
-
return Serializer.new(io).load(opt)
|
251
|
-
end
|
252
|
-
|
253
|
-
# depleted methods
|
254
|
-
|
255
|
-
def self.load_from_file (filename, data_type, dim, opt={}) # :nodoc:
|
256
|
-
raise "Sorry, CArray.load_from_file is depleted"
|
257
|
-
end
|
258
|
-
|
259
234
|
end
|
260
235
|
|
@@ -1,11 +1,19 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray/string.rb
|
4
|
+
#
|
5
|
+
# This file is part of Ruby/CArray extension library.
|
6
|
+
# You can redistribute it and/or modify it under the terms of
|
7
|
+
# the Ruby Licence.
|
8
|
+
#
|
9
|
+
# Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
#
|
11
|
+
# ----------------------------------------------------------------------------
|
12
|
+
|
1
13
|
require "date"
|
2
14
|
|
3
15
|
class CArray
|
4
16
|
|
5
|
-
def test (&block)
|
6
|
-
return convert(:boolean) {|v| yield(v) ? true : false }
|
7
|
-
end
|
8
|
-
|
9
17
|
def str_len ()
|
10
18
|
return convert(:int, &:length)
|
11
19
|
end
|
@@ -178,65 +186,5 @@ class CArray
|
|
178
186
|
return convert {|s| regexp.match(s) {|m| m[0].sub(regexp, replace) } || "" }
|
179
187
|
end
|
180
188
|
|
181
|
-
def str_to_datetime (template = nil)
|
182
|
-
if template
|
183
|
-
return convert() {|v| DateTime.strptime(v, template) }
|
184
|
-
else
|
185
|
-
return convert() {|v| DateTime.parse(v) }
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def str_to_time (template = nil)
|
190
|
-
if template
|
191
|
-
return str_strptime(template)
|
192
|
-
else
|
193
|
-
return convert() {|v| Time.parse(v) }
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def time_format (template = nil)
|
198
|
-
if template
|
199
|
-
return str_strftime(template)
|
200
|
-
else
|
201
|
-
return convert(&:to_s)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def time_year
|
206
|
-
return convert(:int, &:year)
|
207
|
-
end
|
208
|
-
|
209
|
-
def time_month
|
210
|
-
return convert(:int, &:month)
|
211
|
-
end
|
212
|
-
|
213
|
-
def time_day
|
214
|
-
return convert(:int, &:day)
|
215
|
-
end
|
216
|
-
|
217
|
-
def time_hour
|
218
|
-
return convert(:int, &:hour)
|
219
|
-
end
|
220
|
-
|
221
|
-
def time_minute
|
222
|
-
return convert(:int, &:minute)
|
223
|
-
end
|
224
|
-
|
225
|
-
def time_second
|
226
|
-
return convert(:double) {|d| d.second + d.second_fraction }
|
227
|
-
end
|
228
|
-
|
229
|
-
def time_jd
|
230
|
-
return convert(:int, &:jd)
|
231
|
-
end
|
232
|
-
|
233
|
-
def time_ajd
|
234
|
-
return convert(:double, &:ajd)
|
235
|
-
end
|
236
|
-
|
237
|
-
def time_is_leap
|
238
|
-
return test(&:leap?)
|
239
|
-
end
|
240
|
-
|
241
189
|
end
|
242
190
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# ----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
# carray/
|
3
|
+
# carray/struct.rb
|
4
4
|
#
|
5
5
|
# This file is part of Ruby/CArray extension library.
|
6
6
|
# You can redistribute it and/or modify it under the terms of
|
@@ -22,7 +22,7 @@
|
|
22
22
|
# The implementation of other properties (cf. initialization, instance,
|
23
23
|
# methods ...) are left free.
|
24
24
|
#
|
25
|
-
#
|
25
|
+
# CAStruct and CAUnion are examples of such data class.
|
26
26
|
#
|
27
27
|
# option = {
|
28
28
|
# :pack => 1, # nil for alignment, int for pack(n)
|
@@ -90,7 +90,7 @@ class CArray
|
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
-
class
|
93
|
+
class CAStruct
|
94
94
|
|
95
95
|
include Enumerable
|
96
96
|
|
@@ -264,7 +264,7 @@ class CA::Struct
|
|
264
264
|
|
265
265
|
end
|
266
266
|
|
267
|
-
class
|
267
|
+
class CAUnion < CAStruct
|
268
268
|
class << self
|
269
269
|
def inspect
|
270
270
|
return name.nil? ? "AnonUnion" : name
|
@@ -275,11 +275,11 @@ end
|
|
275
275
|
module CA
|
276
276
|
|
277
277
|
def self.struct (opt={}, &block)
|
278
|
-
return
|
278
|
+
return CAStruct::Builder.new(:struct, opt).define(&block)
|
279
279
|
end
|
280
280
|
|
281
281
|
def self.union (opt={}, &block)
|
282
|
-
return
|
282
|
+
return CAStruct::Builder.new(:union, opt).define(&block)
|
283
283
|
end
|
284
284
|
|
285
285
|
end
|
@@ -290,7 +290,7 @@ end
|
|
290
290
|
#
|
291
291
|
# ---------------------------------------------------------------------
|
292
292
|
|
293
|
-
class
|
293
|
+
class CAStruct::Builder # :nodoc:
|
294
294
|
|
295
295
|
class Member # :nodoc:
|
296
296
|
|
@@ -358,9 +358,9 @@ class CA::Struct::Builder # :nodoc:
|
|
358
358
|
# ---
|
359
359
|
case @type
|
360
360
|
when :struct
|
361
|
-
klass = Class.new(
|
361
|
+
klass = Class.new(CAStruct)
|
362
362
|
when :union
|
363
|
-
klass = Class.new(
|
363
|
+
klass = Class.new(CAUnion)
|
364
364
|
end
|
365
365
|
# ---
|
366
366
|
if @align.nil?
|
@@ -477,7 +477,7 @@ class CA::Struct::Builder # :nodoc:
|
|
477
477
|
if block
|
478
478
|
opt = {:pack => @align}.update(opt)
|
479
479
|
st = self.class.new(:struct, opt).define(&block)
|
480
|
-
elsif opt[:type] and opt[:type] <=
|
480
|
+
elsif opt[:type] and opt[:type] <= CAStruct
|
481
481
|
st = opt[:type]
|
482
482
|
else
|
483
483
|
raise "type is not given for struct member of struct"
|
@@ -494,7 +494,7 @@ class CA::Struct::Builder # :nodoc:
|
|
494
494
|
if block
|
495
495
|
opt = {:pack => @align}.update(opt)
|
496
496
|
st = self.class.new(:union, opt).define(&block)
|
497
|
-
elsif opt[:type] and opt[:type] <=
|
497
|
+
elsif opt[:type] and opt[:type] <= CAStruct
|
498
498
|
st = opt[:type]
|
499
499
|
else
|
500
500
|
raise "type is not given for union member of struct"
|
@@ -556,14 +556,14 @@ end
|
|
556
556
|
|
557
557
|
|
558
558
|
|
559
|
-
class
|
559
|
+
class CAStruct
|
560
560
|
|
561
561
|
def self.spec
|
562
562
|
output = ""
|
563
563
|
table = self::MEMBER_TABLE
|
564
564
|
stlist = []
|
565
565
|
if self.name.nil?
|
566
|
-
if self <=
|
566
|
+
if self <= CAUnion
|
567
567
|
prefix = "union"
|
568
568
|
else
|
569
569
|
prefix = "struct"
|
@@ -573,7 +573,7 @@ class CA::Struct
|
|
573
573
|
else
|
574
574
|
output << sprintf("%s = ", self.name)
|
575
575
|
end
|
576
|
-
if self <
|
576
|
+
if self < CAUnion
|
577
577
|
output << sprintf("CA.union(:size=>%i) {\n", self::DATA_SIZE)
|
578
578
|
else
|
579
579
|
output << sprintf("CA.struct(:size=>%i) {\n", self::DATA_SIZE)
|
@@ -582,10 +582,10 @@ class CA::Struct
|
|
582
582
|
offset, type, option = *table[member]
|
583
583
|
case type
|
584
584
|
when Class
|
585
|
-
if type <
|
585
|
+
if type < CAStruct
|
586
586
|
stlist << type
|
587
587
|
if type.name.nil?
|
588
|
-
if type <=
|
588
|
+
if type <= CAUnion
|
589
589
|
prefix = "union"
|
590
590
|
else
|
591
591
|
prefix = "struct"
|