Class: GirFFI::Boolean

Inherits:
Object
  • Object
show all
Extended by:
FFI::DataConverter
Defined in:
lib/gir_ffi/boolean.rb

Overview

Class representing a boolean (natively, an int).

Constant Summary collapse

NATIVE_TRUE =
1
NATIVE_FALSE =
0
FROM_NATIVE =
{ NATIVE_FALSE => false, NATIVE_TRUE => true }.freeze

Class Method Summary collapse

Class Method Details

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



28
29
30
# File 'lib/gir_ffi/boolean.rb', line 28

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

.from_native(value, _context) ⇒ Object



16
17
18
# File 'lib/gir_ffi/boolean.rb', line 16

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

.get_value_from_pointer(pointer, offset) ⇒ Object



32
33
34
# File 'lib/gir_ffi/boolean.rb', line 32

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

.sizeObject



24
25
26
# File 'lib/gir_ffi/boolean.rb', line 24

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

.to_native(value, _context) ⇒ Object



20
21
22
# File 'lib/gir_ffi/boolean.rb', line 20

def self.to_native(value, _context)
  value ? NATIVE_TRUE : NATIVE_FALSE
end