Class: Fiddle::StructArray
- Inherits:
-
Array
- Object
- Array
- Fiddle::StructArray
- Includes:
- ValueUtil
- Defined in:
- lib/fiddle/struct.rb
Overview
Wrapper for arrays within a struct
Instance Method Summary collapse
- #[]=(index, value) ⇒ Object
-
#initialize(ptr, type, initial_values) ⇒ StructArray
constructor
A new instance of StructArray.
- #to_ptr ⇒ Object
Methods included from ValueUtil
#signed_value, #unsigned_value, #wrap_arg, #wrap_args
Constructor Details
#initialize(ptr, type, initial_values) ⇒ StructArray
Returns a new instance of StructArray.
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/fiddle/struct.rb', line 140 def initialize(ptr, type, initial_values) @ptr = ptr @type = type @is_struct = @type.respond_to?(:entity_class) if @is_struct super(initial_values) else @size = Fiddle::PackInfo::SIZE_MAP[type] @pack_format = Fiddle::PackInfo::PACK_MAP[type] super(initial_values.collect { |v| unsigned_value(v, type) }) end end |
Instance Method Details
#[]=(index, value) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/fiddle/struct.rb', line 157 def []=(index, value) if index < 0 || index >= size raise IndexError, 'index %d outside of array bounds 0...%d' % [index, size] end if @is_struct self[index].replace(value) else to_ptr[index * @size, @size] = [value].pack(@pack_format) super(index, value) end end |
#to_ptr ⇒ Object
153 154 155 |
# File 'lib/fiddle/struct.rb', line 153 def to_ptr @ptr end |