class GirFFI::InOutPointer

The InOutPointer class handles conversion between ruby types and pointers for arguments with direction :inout and :out.

Attributes

value_type[R]

Public Class Methods

allocate_new(type) click to toggle source
# File lib/gir_ffi/in_out_pointer.rb, line 41
def self.allocate_new(type)
  ffi_type = TypeMap.type_specification_to_ffi_type type
  ptr = FFI::MemoryPointer.new(ffi_type)
  new type, ptr
end
new(type, ptr) click to toggle source
Calls superclass method
# File lib/gir_ffi/in_out_pointer.rb, line 10
def initialize(type, ptr)
  @value_type = type
  super ptr
end

Public Instance Methods

to_ruby_value() click to toggle source

Convert more fully to a ruby value than to_value

# File lib/gir_ffi/in_out_pointer.rb, line 27
def to_ruby_value
  bare_value = to_value
  case value_type
  when :utf8
    bare_value.to_utf8
  when Array
    value_type[1].wrap bare_value
  when Class
    value_type.wrap bare_value
  else
    bare_value
  end
end
to_value() click to toggle source
# File lib/gir_ffi/in_out_pointer.rb, line 15
def to_value
  case value_ffi_type
  when Module
    value_ffi_type.get_value_from_pointer(self, 0)
  when Symbol
    send("get_#{value_ffi_type}", 0)
  else
    raise NotImplementedError
  end
end

Private Instance Methods

value_ffi_type() click to toggle source
# File lib/gir_ffi/in_out_pointer.rb, line 49
def value_ffi_type
  @value_ffi_type ||= TypeMap.type_specification_to_ffi_type value_type
end