Class: GirFFI::InOutPointer

Inherits:
FFI::Pointer
  • Object
show all
Defined in:
lib/gir_ffi/in_out_pointer.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, ptr) ⇒ InOutPointer

Returns a new instance of InOutPointer.



9
10
11
12
# File 'lib/gir_ffi/in_out_pointer.rb', line 9

def initialize(type, ptr)
  @value_type = type
  super ptr
end

Instance Attribute Details

#value_typeObject (readonly)

Returns the value of attribute value_type.



7
8
9
# File 'lib/gir_ffi/in_out_pointer.rb', line 7

def value_type
  @value_type
end

Class Method Details

.allocate_new(type) ⇒ Object



40
41
42
43
44
# File 'lib/gir_ffi/in_out_pointer.rb', line 40

def self.allocate_new(type)
  ffi_type = TypeMap.type_specification_to_ffi_type type
  ptr = FFI::MemoryPointer.new(ffi_type)
  new type, ptr
end

Instance Method Details

#to_ruby_valueObject

Convert more fully to a ruby value than #to_value



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gir_ffi/in_out_pointer.rb', line 26

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_valueObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/gir_ffi/in_out_pointer.rb', line 14

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