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 extende 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
- #set_value(value) ⇒ Object
-
#to_value ⇒ Object
TODO: Rename to get_value.
- #value_ffi_type ⇒ Object
- #value_type_size ⇒ Object
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
62 63 64 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 62 def self.for type self.new(type).tap {|ptr| ptr.set_value nil} end |
.from(type, value) ⇒ Object
66 67 68 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 66 def self.from type, value self.new(type).tap {|ptr| ptr.set_value value} end |
Instance Method Details
#set_value(value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 30 def set_value value value = adjust_value_in value case value_ffi_type when Class self.put_bytes 0, value.to_ptr.read_bytes(value_type_size), 0, value_type_size when Symbol self.send "put_#{value_ffi_type}", 0, value else raise NotImplementedError end end |
#to_value ⇒ Object
TODO: Rename to get_value
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 Class to_ptr when Symbol adjust_value_out self.send("get_#{value_ffi_type}", 0) else raise NotImplementedError end end |
#value_ffi_type ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 42 def value_ffi_type @value_ffi_type ||= case value_type when :gboolean :int else TypeMap.type_specification_to_ffitype value_type end end |
#value_type_size ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gir_ffi/in_out_pointer.rb', line 51 def value_type_size @value_type_size ||= case value_ffi_type when Class value_ffi_type.size when Symbol FFI.type_size value_ffi_type else raise NotImplementedError end end |