Class: GirFFI::BoxedBase

Inherits:
ClassBase show all
Extended by:
FFI::DataConverter
Defined in:
lib/gir_ffi/boxed_base.rb

Overview

Base class for generated classes representing boxed types.

Direct Known Subclasses

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, setup_instance_method, setup_method, try_in_ancestors, wrap

Methods included from RegisteredTypeBase

#gtype

Methods included from TypeBase

#gir_ffi_builder, #gir_info

Constructor Details

#initializeBoxedBase

Returns a new instance of BoxedBase.



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

def initialize
  @struct = self.class::Struct.new
end

Class Method Details

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



25
26
27
28
29
30
31
32
33
# File 'lib/gir_ffi/boxed_base.rb', line 25

def self.copy_value_to_pointer(value, pointer, offset = 0)
  size = self::Struct.size
  bytes = if value
            value.to_ptr.read_bytes(size)
          else
            "\x00" * size
          end
  pointer.put_bytes offset, bytes, 0, size
end

.get_value_from_pointer(pointer, offset) ⇒ Object



21
22
23
# File 'lib/gir_ffi/boxed_base.rb', line 21

def self.get_value_from_pointer(pointer, offset)
  pointer + offset
end

.native_typeObject



8
9
10
# File 'lib/gir_ffi/boxed_base.rb', line 8

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

.to_ffi_typeObject



12
13
14
# File 'lib/gir_ffi/boxed_base.rb', line 12

def self.to_ffi_type
  self
end

.to_native(value, _context) ⇒ Object

NOTE: Needed for JRuby’s FFI



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

def self.to_native(value, _context)
  value.struct
end