Module: GirFFI::StructLikeBase::ClassMethods

Defined in:
lib/gir_ffi/struct_like_base.rb

Overview

Class methods for struct-like classes.

Instance Method Summary collapse

Instance Method Details

#copy_from(val) ⇒ Object

Create an unowned copy of the struct represented by val



40
41
42
43
44
# File 'lib/gir_ffi/struct_like_base.rb', line 40

def copy_from(val)
  return unless val

  disown copy from(val)
end

#copy_value_to_pointer(value, pointer, offset = 0) ⇒ Object



34
35
36
37
# File 'lib/gir_ffi/struct_like_base.rb', line 34

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



26
27
28
# File 'lib/gir_ffi/struct_like_base.rb', line 26

def get_value_from_pointer(pointer, offset)
  pointer + offset
end

#native_typeObject



13
14
15
# File 'lib/gir_ffi/struct_like_base.rb', line 13

def native_type
  FFI::Type::Struct.new(self::Struct)
end

#sizeObject



30
31
32
# File 'lib/gir_ffi/struct_like_base.rb', line 30

def size
  self::Struct.size
end

#to_ffi_typeObject



17
18
19
# File 'lib/gir_ffi/struct_like_base.rb', line 17

def to_ffi_type
  self
end

#to_native(value, _context) ⇒ Object

NOTE: Needed for JRuby’s FFI



22
23
24
# File 'lib/gir_ffi/struct_like_base.rb', line 22

def to_native(value, _context)
  value.struct
end

#wrap_copy(val) ⇒ Object

Wrap an owned copy of the struct represented by val



47
48
49
50
51
# File 'lib/gir_ffi/struct_like_base.rb', line 47

def wrap_copy(val)
  return unless val

  own copy(val)
end

#wrap_own(val) ⇒ Object

Wrap value and take ownership of it



54
55
56
57
58
59
# File 'lib/gir_ffi/struct_like_base.rb', line 54

def wrap_own(val)
  return unless val
  return if val.null?

  own wrap(val)
end