Sha256: f5ed4c91822978d2f4ac44dfb6736bdc33e5f04caccec62184b61ab983a947ec

Contents?: true

Size: 757 Bytes

Versions: 13

Compression:

Stored size: 757 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, offset = 0)
      pointer.put_int offset, 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

13 entries across 13 versions & 1 rubygems

Version Path
gir_ffi-0.17.0 lib/gir_ffi/boolean.rb
gir_ffi-0.16.1 lib/gir_ffi/boolean.rb
gir_ffi-0.16.0 lib/gir_ffi/boolean.rb
gir_ffi-0.15.9 lib/gir_ffi/boolean.rb
gir_ffi-0.15.8 lib/gir_ffi/boolean.rb
gir_ffi-0.15.7 lib/gir_ffi/boolean.rb
gir_ffi-0.15.6 lib/gir_ffi/boolean.rb
gir_ffi-0.15.5 lib/gir_ffi/boolean.rb
gir_ffi-0.15.4 lib/gir_ffi/boolean.rb
gir_ffi-0.15.3 lib/gir_ffi/boolean.rb
gir_ffi-0.15.2 lib/gir_ffi/boolean.rb
gir_ffi-0.15.1 lib/gir_ffi/boolean.rb
gir_ffi-0.15.0 lib/gir_ffi/boolean.rb