Sha256: 7cd9fe1b46c13e3498fa34b63b9167709c345e9f1ae1d71713a584a725feeae6

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 Bytes

Contents

require 'gir_ffi/class_base'

module GirFFI
  # Base class for generated classes representing boxed types.
  class BoxedBase < ClassBase
    extend FFI::DataConverter

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

    # @deprecated Use #to_ffi_type instead. Will be removed in 0.8.0.
    def self.to_ffitype
      to_ffi_type
    end

    def self.to_ffi_type
      self
    end

    def self.to_native value, _context
      value.struct
    end

    def self.get_value_from_pointer pointer
      pointer.to_ptr
    end

    def self.copy_value_to_pointer value, pointer, offset = 0
      size = self::Struct.size
      pointer.put_bytes offset, value.to_ptr.read_bytes(size), 0, size
    end

    def self._allocate
      obj = _real_new
      obj.instance_variable_set :@struct, self::Struct.new
      obj
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gir_ffi-0.7.10 lib/gir_ffi/boxed_base.rb
gir_ffi-0.7.9 lib/gir_ffi/boxed_base.rb