123456789_123456789_123456789_123456789_123456789_

Class: Fiddle::StructArray

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Array
Instance Chain:
self, ValueUtil, Array
Inherits: Array
Defined in: ext/fiddle/lib/fiddle/struct.rb

Overview

Wrapper for arrays within a struct

Class Method Summary

Instance Method Summary

Constructor Details

.new(ptr, type, initial_values) ⇒ StructArray

[ GitHub ]

  
# File 'ext/fiddle/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)

[ GitHub ]

  
# File 'ext/fiddle/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

[ GitHub ]

  
# File 'ext/fiddle/lib/fiddle/struct.rb', line 153

def to_ptr
  @ptr
end