Class: GirFFI::Builders::PointerValueConvertor
- Inherits:
-
Object
- Object
- GirFFI::Builders::PointerValueConvertor
- Defined in:
- lib/gir_ffi/builders/pointer_value_convertor.rb
Overview
Encapsulates knowledge about how to store values in pointers, and how to fetch values from pointers.
Instance Method Summary collapse
-
#initialize(type_spec) ⇒ PointerValueConvertor
constructor
A new instance of PointerValueConvertor.
- #pointer_to_value(ptr_exp, offset = 0) ⇒ Object
- #value_to_pointer(ptr_exp, value_exp, offset = 0) ⇒ Object
Constructor Details
#initialize(type_spec) ⇒ PointerValueConvertor
Returns a new instance of PointerValueConvertor.
8 9 10 |
# File 'lib/gir_ffi/builders/pointer_value_convertor.rb', line 8 def initialize(type_spec) @type_spec = type_spec end |
Instance Method Details
#pointer_to_value(ptr_exp, offset = 0) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/gir_ffi/builders/pointer_value_convertor.rb', line 12 def pointer_to_value(ptr_exp, offset = 0) case ffi_type_spec when Module "#{ffi_type_spec}.get_value_from_pointer(#{ptr_exp}, #{offset})" when Symbol "#{ptr_exp}.get_#{ffi_type_spec}(#{offset})" end end |
#value_to_pointer(ptr_exp, value_exp, offset = 0) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gir_ffi/builders/pointer_value_convertor.rb', line 21 def value_to_pointer(ptr_exp, value_exp, offset = 0) case ffi_type_spec when Module args = [value_exp, ptr_exp] args << offset unless offset == 0 "#{ffi_type_spec}.copy_value_to_pointer(#{args.join(", ")})" when Symbol "#{ptr_exp}.put_#{ffi_type_spec} #{offset}, #{value_exp}" end end |