carray 1.3.5 → 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 -21
- data/Rakefile +31 -0
- data/carray.gemspec +13 -26
- 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} +77 -51
- data/{carray_access.c → ext/carray_access.c} +133 -91
- 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} +11 -13
- 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} +67 -1
- 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} +25 -25
- 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} +32 -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} +12 -2
- 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 +49 -7
- data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
- data/lib/carray/autoload/autoload_base.rb +1 -5
- data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
- data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
- data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
- data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
- data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -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} +17 -47
- 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/string.rb +190 -0
- data/lib/carray/{base/struct.rb → struct.rb} +20 -20
- data/lib/carray/{io/table.rb → table.rb} +1 -9
- 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 +100 -254
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- 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/autoload/autoload_math_calculus.rb +0 -2
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/fortio/extconf.rb +0 -3
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
- data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
- data/ext/fortio/lib/fortio.rb +0 -3
- data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
- data/ext/fortio/lib/fortio/fortran_format.y +0 -215
- data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
- data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
- data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
- data/ext/fortio/ruby_fortio.c +0 -182
- data/ext/fortio/test/test_H.rb +0 -5
- data/ext/fortio/test/test_T.rb +0 -7
- data/ext/fortio/test/test_fortran_format.rb +0 -86
- data/ext/fortio/test/test_namelist.rb +0 -25
- data/ext/fortio/test/test_namelist_write.rb +0 -10
- data/ext/fortio/test/test_sequential.rb +0 -13
- data/ext/fortio/test/test_sequential2.rb +0 -13
- data/ext/fortio/work/test.rb +0 -10
- data/ext/fortio/work/test_e.rb +0 -19
- data/ext/fortio/work/test_ep.rb +0 -10
- data/ext/fortio/work/test_parse.rb +0 -12
- data/ext/imagemap/carray_imagemap.c +0 -495
- data/ext/imagemap/doc/call_graph.dot +0 -28
- data/ext/imagemap/draw.c +0 -567
- data/ext/imagemap/extconf.rb +0 -13
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
- data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
- data/ext/imagemap/lib/image_map.rb +0 -4
- data/ext/imagemap/test/swath_index.rb +0 -83
- data/ext/imagemap/test/swath_warp.rb +0 -99
- data/ext/imagemap/test/test.rb +0 -23
- data/ext/imagemap/test/test_image.rb +0 -42
- data/ext/imagemap/test/test_line.rb +0 -14
- data/ext/imagemap/test/test_rotate.rb +0 -17
- data/ext/imagemap/test/test_triangle.rb +0 -20
- data/ext/imagemap/test/test_warp.rb +0 -26
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
- data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
- 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/ext/narray/README +0 -22
- data/ext/narray/ca_wrap_narray.c +0 -500
- data/ext/narray/carray_narray.c +0 -21
- data/ext/narray/extconf.rb +0 -57
- data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
- data/ext/narray/lib/math/narray.rb +0 -17
- data/ext/narray/lib/math/narray_miss.rb +0 -45
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
- data/lib/carray/autoload/autoload_io_csv.rb +0 -14
- data/lib/carray/autoload/autoload_io_pg.rb +0 -6
- data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
- 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 -1090
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/graphics/gnuplot.rb +0 -2131
- data/lib/carray/graphics/zimg.rb +0 -296
- data/lib/carray/io/csv.rb +0 -572
- data/lib/carray/io/pg.rb +0 -101
- data/lib/carray/io/sqlite3.rb +0 -215
- 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
@@ -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
|
|
@@ -0,0 +1,190 @@
|
|
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
|
+
|
13
|
+
require "date"
|
14
|
+
|
15
|
+
class CArray
|
16
|
+
|
17
|
+
def str_len ()
|
18
|
+
return convert(:int, &:length)
|
19
|
+
end
|
20
|
+
|
21
|
+
def str_size ()
|
22
|
+
return convert(:int, &:size)
|
23
|
+
end
|
24
|
+
|
25
|
+
def str_bytesize ()
|
26
|
+
return convert(:int, &:bytesize)
|
27
|
+
end
|
28
|
+
|
29
|
+
def str_gsub (*args, &block)
|
30
|
+
return convert() {|s| s.gsub(*args, &block) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def str_sub (*args, &block)
|
34
|
+
return convert() {|s| s.sub(*args, &block) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def str_encode (*args)
|
38
|
+
return convert() {|s| s.encode(*args) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def str_force_encoding (encoding)
|
42
|
+
return convert() {|s| s.force_encoding(encoding) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def str_encoding ()
|
46
|
+
return convert(&:encoding)
|
47
|
+
end
|
48
|
+
|
49
|
+
def str_is_end_with (*args)
|
50
|
+
return test {|s| s.end_with?(*args) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def str_is_start_with (*args)
|
54
|
+
return test {|s| s.start_with?(*args) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def str_includes (substr)
|
58
|
+
return test {|s| s.include?(substr) }
|
59
|
+
end
|
60
|
+
|
61
|
+
alias str_contains str_includes
|
62
|
+
|
63
|
+
def str_index (*args)
|
64
|
+
return convert(:int) {|s| s.index(*args) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def str_rindex (*args)
|
68
|
+
return convert(:int) {|s| s.rindex(*args) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def str_intern ()
|
72
|
+
return convert(&:intern)
|
73
|
+
end
|
74
|
+
|
75
|
+
def str_scrub ()
|
76
|
+
return convert(&:scrub)
|
77
|
+
end
|
78
|
+
|
79
|
+
def str_downcase ()
|
80
|
+
return convert(&:downcase)
|
81
|
+
end
|
82
|
+
|
83
|
+
def str_upcase ()
|
84
|
+
return convert(&:upcase)
|
85
|
+
end
|
86
|
+
|
87
|
+
def str_capitalize ()
|
88
|
+
return convert(&:capitalize)
|
89
|
+
end
|
90
|
+
|
91
|
+
def str_swapcase ()
|
92
|
+
return convert(&:swapcase)
|
93
|
+
end
|
94
|
+
|
95
|
+
def str_chomp (*args)
|
96
|
+
return convert() {|s| s.chomp(*args) }
|
97
|
+
end
|
98
|
+
|
99
|
+
def str_chop ()
|
100
|
+
return convert(&:chop)
|
101
|
+
end
|
102
|
+
|
103
|
+
def str_chr ()
|
104
|
+
return convert(&:chr)
|
105
|
+
end
|
106
|
+
|
107
|
+
def str_clear ()
|
108
|
+
return convert(&:clear)
|
109
|
+
end
|
110
|
+
|
111
|
+
def str_count (*args)
|
112
|
+
return convert(:int) {|s| s.count(*args) }
|
113
|
+
end
|
114
|
+
|
115
|
+
def str_delete (*args)
|
116
|
+
return convert() {|s| s.delete(*args) }
|
117
|
+
end
|
118
|
+
|
119
|
+
def str_delete_prefix (prefix)
|
120
|
+
return convert() {|s| s.delete_prefix(prefix) }
|
121
|
+
end
|
122
|
+
|
123
|
+
def str_delete_suffix (suffix)
|
124
|
+
return convert() {|s| s.delete_suffix(suffix) }
|
125
|
+
end
|
126
|
+
|
127
|
+
def str_dump ()
|
128
|
+
return convert(&:dump)
|
129
|
+
end
|
130
|
+
|
131
|
+
def str_center (*args)
|
132
|
+
return convert() {|s| s.center(*args) }
|
133
|
+
end
|
134
|
+
|
135
|
+
def str_ljust (*args)
|
136
|
+
return convert() {|s| s.ljust(*args) }
|
137
|
+
end
|
138
|
+
|
139
|
+
def str_rjust (*args)
|
140
|
+
return convert() {|s| s.rjust(*args) }
|
141
|
+
end
|
142
|
+
|
143
|
+
def str_to_i ()
|
144
|
+
return convert(&:to_i)
|
145
|
+
end
|
146
|
+
|
147
|
+
def str_to_f ()
|
148
|
+
return convert(&:to_f)
|
149
|
+
end
|
150
|
+
|
151
|
+
def str_to_r ()
|
152
|
+
return convert(&:to_r)
|
153
|
+
end
|
154
|
+
|
155
|
+
def str_strip ()
|
156
|
+
return convert(&:strip)
|
157
|
+
end
|
158
|
+
|
159
|
+
def str_rstrip ()
|
160
|
+
return convert(&:rstrip)
|
161
|
+
end
|
162
|
+
|
163
|
+
def str_lstrip ()
|
164
|
+
return convert(&:lstrip)
|
165
|
+
end
|
166
|
+
|
167
|
+
def str_is_empty ()
|
168
|
+
return test(&:empty?)
|
169
|
+
end
|
170
|
+
|
171
|
+
def str_matches (*args)
|
172
|
+
if args.size == 1 && args.first.is_a?(Regexp)
|
173
|
+
regexp = args.first
|
174
|
+
return test {|v| v =~ regexp }
|
175
|
+
else
|
176
|
+
mask = template(:boolean) { false }
|
177
|
+
args.each do |str|
|
178
|
+
addr = search(str)
|
179
|
+
mask[addr] = true if addr
|
180
|
+
end
|
181
|
+
return mask
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def str_extract (regexp, replace = '\0')
|
186
|
+
return convert {|s| regexp.match(s) {|m| m[0].sub(regexp, replace) } || "" }
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
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,14 +90,14 @@ class CArray
|
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
-
class
|
93
|
+
class CAStruct
|
94
94
|
|
95
95
|
include Enumerable
|
96
96
|
|
97
97
|
class << self
|
98
98
|
|
99
99
|
def inspect
|
100
|
-
return name.
|
100
|
+
return name.nil? ? "AnonStruct" : name
|
101
101
|
end
|
102
102
|
|
103
103
|
def [] (*argv)
|
@@ -264,10 +264,10 @@ 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
|
-
return name.
|
270
|
+
return name.nil? ? "AnonUnion" : name
|
271
271
|
end
|
272
272
|
end
|
273
273
|
end
|
@@ -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
|
-
if self.name.
|
566
|
-
if self <=
|
565
|
+
if self.name.nil?
|
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
|
-
if type.name.
|
588
|
-
if type <=
|
587
|
+
if type.name.nil?
|
588
|
+
if type <= CAUnion
|
589
589
|
prefix = "union"
|
590
590
|
else
|
591
591
|
prefix = "struct"
|