Class: GirFFI::InOutPointer
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- GirFFI::InOutPointer
- 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.
TODO: This has now become a more general extended pointer class and should be renamed.
Instance Attribute Summary collapse
-
#value_type ⇒ Object
readonly
Returns the value of attribute value_type.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
- #set_value(value) ⇒ Object
-
#to_ruby_value ⇒ Object
Convert more fully to a ruby value than #to_value.
-
#to_value ⇒ Object
TODO: Create type classes that extract values from pointers.
Instance Attribute Details
#value_type ⇒ Object (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
.for(type) ⇒ Object
60 61 62 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 60 def self.for type new(type).tap {|ptr| ptr.clear} end |
.from(type, value) ⇒ Object
64 65 66 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 64 def self.from type, value new(type).tap {|ptr| ptr.set_value value} end |
Instance Method Details
#clear ⇒ Object
56 57 58 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 56 def clear set_value nil_value end |
#set_value(value) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 45 def set_value value case value_ffi_type when Module value_ffi_type.copy_value_to_pointer(value, self) when Symbol send "put_#{value_ffi_type}", 0, value else raise NotImplementedError, value_ffi_type end end |
#to_ruby_value ⇒ Object
Convert more fully to a ruby value than #to_value
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 31 def to_ruby_value = to_value case value_type when :utf8 .to_utf8 when Array value_type[1].wrap when Class value_type.wrap else end end |
#to_value ⇒ Object
TODO: Create type classes that extract values from pointers.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 19 def to_value case value_ffi_type when Module value_ffi_type.get_value_from_pointer(self) when Symbol send("get_#{value_ffi_type}", 0) else raise NotImplementedError end end |