class GirFFI::StructLikeBase
Base class providing methods for generated classes representing GLib
structs, unions and boxed types.
Public Class Methods
copy_from(val)
click to toggle source
Create an unowned copy of the struct represented by val
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 29 def get_value_from_pointer(pointer, offset) pointer + offset end
native_type()
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 17 def native_type FFI::Type::Struct.new(self::Struct) end
new()
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 9 def initialize store_pointer(nil) struct.owned = true struct.to_ptr.autorelease = false end
size()
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 33 def size self::Struct.size end
to_ffi_type()
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 21 def to_ffi_type self end
to_native(value, _context)
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 25 def to_native(value, _context) value.struct end
wrap_copy(val)
click to toggle source
Wrap an owned copy of the struct represented by val
# File lib/gir_ffi/struct_like_base.rb, line 50 def wrap_copy(val) return unless val own copy(val) end
wrap_own(val)
click to toggle source
Wrap value and take ownership of it
# 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
Private Class Methods
copy(val)
click to toggle source
Create a copy of the struct represented by val
# File lib/gir_ffi/struct_like_base.rb, line 77 def copy(val) new.tap do |copy| copy_value_to_pointer(val, copy.to_ptr) end end
disown(val)
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 71 def disown(val) val.struct.owned = nil val end
own(val)
click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 66 def own(val) val.struct.owned = true val end