Class: GirFFI::StructLikeBase

Inherits:
ClassBase show all
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

BoxedBase, StructBase, UnionBase

Constant Summary

Constants inherited from ClassBase

ClassBase::GIR_FFI_BUILDER

Instance Attribute Summary

Attributes inherited from ClassBase

#struct

Class Method Summary collapse

Instance Method Summary collapse

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

#gtype

Methods included from TypeBase

#gir_ffi_builder, #gir_info

Methods included from MethodSetup

#setup_method, #setup_method!

Methods included from InstanceMethodSetup

#setup_instance_method, #setup_instance_method!

Constructor Details

#initializeStructLikeBase

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_typeObject



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

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

.sizeObject



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

def size
  self::Struct.size
end

.to_ffi_typeObject



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