module GirFFI::StructLikeBase::ClassMethods

Class methods for struct-like classes.

Public Instance 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 40
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 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) click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 26
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 13
def native_type
  FFI::Type::Struct.new(self::Struct)
end
size() click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 30
def size
  self::Struct.size
end
to_ffi_type() click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 17
def to_ffi_type
  self
end
to_native(value, _context) click to toggle source

NOTE: Needed for JRuby's FFI

# File lib/gir_ffi/struct_like_base.rb, line 22
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 47
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 54
def wrap_own(val)
  return unless val
  return if val.null?

  own wrap(val)
end

Private Instance 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 74
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 68
def disown(val)
  val.struct.owned = nil
  val
end
own(val) click to toggle source
# File lib/gir_ffi/struct_like_base.rb, line 63
def own(val)
  val.struct.owned = true
  val
end