Class: GirFFI::StructLikeBase
- Extended by:
- FFI::DataConverter
- Defined in:
- lib/gir_ffi/struct_like_base.rb
Overview
Base class providing methods for generated classes representing GLib structs, unions and boxed types.
Direct Known Subclasses
Constant Summary
Constants inherited from ClassBase
Instance Attribute Summary
Attributes inherited from ClassBase
Class Method Summary collapse
-
.copy_from(val) ⇒ Object
Create an unowned copy of the struct represented by val.
- .copy_value_to_pointer(value, pointer, offset = 0) ⇒ Object
- .get_value_from_pointer(pointer, offset) ⇒ Object
- .native_type ⇒ Object
- .size ⇒ Object
- .to_ffi_type ⇒ Object
- .to_native(value, _context) ⇒ Object
-
.wrap_copy(val) ⇒ Object
Wrap an owned copy of the struct represented by val.
-
.wrap_own(val) ⇒ Object
Wrap value and take ownership of it.
Instance Method Summary collapse
-
#initialize ⇒ StructLikeBase
constructor
A new instance of StructLikeBase.
Methods inherited from ClassBase
#==, direct_wrap, from, #setup_and_call, setup_and_call, to_callback_ffi_type, try_in_ancestors, wrap
Methods included from RegisteredTypeBase
Methods included from TypeBase
Methods included from MethodSetup
Methods included from InstanceMethodSetup
#setup_instance_method, #setup_instance_method!
Constructor Details
#initialize ⇒ StructLikeBase
Returns a new instance of StructLikeBase.
9 10 11 12 13 |
# File 'lib/gir_ffi/struct_like_base.rb', line 9 def initialize store_pointer(nil) struct.owned = true struct.to_ptr.autorelease = false end |
Class Method Details
.copy_from(val) ⇒ Object
Create an unowned copy of the struct represented by val
43 44 45 46 47 |
# File 'lib/gir_ffi/struct_like_base.rb', line 43 def copy_from(val) return unless val disown copy from(val) end |
.copy_value_to_pointer(value, pointer, offset = 0) ⇒ Object
37 38 39 40 |
# File 'lib/gir_ffi/struct_like_base.rb', line 37 def copy_value_to_pointer(value, pointer, offset = 0) bytes = value.to_ptr.read_bytes(size) pointer.put_bytes offset, bytes end |
.get_value_from_pointer(pointer, offset) ⇒ Object
29 30 31 |
# File 'lib/gir_ffi/struct_like_base.rb', line 29 def get_value_from_pointer(pointer, offset) pointer + offset end |
.native_type ⇒ Object
17 18 19 |
# File 'lib/gir_ffi/struct_like_base.rb', line 17 def native_type FFI::Type::Struct.new(self::Struct) end |
.size ⇒ Object
33 34 35 |
# File 'lib/gir_ffi/struct_like_base.rb', line 33 def size self::Struct.size end |
.to_ffi_type ⇒ Object
21 22 23 |
# File 'lib/gir_ffi/struct_like_base.rb', line 21 def to_ffi_type self end |
.to_native(value, _context) ⇒ Object
25 26 27 |
# File 'lib/gir_ffi/struct_like_base.rb', line 25 def to_native(value, _context) value.struct end |
.wrap_copy(val) ⇒ Object
Wrap an owned copy of the struct represented by val
50 51 52 53 54 |
# File 'lib/gir_ffi/struct_like_base.rb', line 50 def wrap_copy(val) return unless val own copy(val) end |
.wrap_own(val) ⇒ Object
Wrap value and take ownership of it
57 58 59 60 61 62 |
# File 'lib/gir_ffi/struct_like_base.rb', line 57 def wrap_own(val) return unless val return if val.null? own wrap(val) end |