Sha256: add3cebb4d607e95cac75d0b2cebba2bad10abc1519dcdb5a9cc59ca5781a2e5

Contents?: true

Size: 740 Bytes

Versions: 5

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

require 'ffi'

module GirFFI
  # Class representing a boolean (natively, an int).
  class Boolean
    extend FFI::DataConverter
    native_type FFI::Type::INT

    FROM_NATIVE = { 0 => false, 1 => true }.freeze
    TO_NATIVE = FROM_NATIVE.invert

    def self.from_native(value, _context)
      FROM_NATIVE.fetch(value)
    end

    def self.to_native(value, _context)
      TO_NATIVE.fetch(value ? true : false)
    end

    def self.size
      FFI.type_size FFI::Type::INT
    end

    def self.copy_value_to_pointer(value, pointer)
      pointer.put_int 0, to_native(value, nil)
    end

    def self.get_value_from_pointer(pointer, offset)
      from_native pointer.get_int(offset), nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-0.13.0 lib/gir_ffi/boolean.rb
gir_ffi-0.12.1 lib/gir_ffi/boolean.rb
gir_ffi-0.12.0 lib/gir_ffi/boolean.rb
gir_ffi-0.11.4 lib/gir_ffi/boolean.rb
gir_ffi-0.11.3 lib/gir_ffi/boolean.rb