Class: GirFFI::Builders::FlagsBuilder

Inherits:
EnumBuilder show all
Defined in:
lib/gir_ffi/builders/flags_builder.rb

Overview

Implements the creation of a flags type. The type will be attached to the appropriate namespace module, and will be defined as a bit_mask for FFI.

Instance Attribute Summary

Attributes inherited from GirFFI::BaseTypeBuilder

#info

Instance Method Summary collapse

Methods inherited from RegisteredTypeBuilder

#setup_instance_method, #setup_method, #target_gtype

Methods inherited from GirFFI::BaseTypeBuilder

#build_class, #initialize, #instantiate_class

Methods included from GirFFI::BuilderHelper

#get_or_define_class, #get_or_define_module, #optionally_define_constant

Constructor Details

This class inherits a constructor from GirFFI::BaseTypeBuilder

Instance Method Details

#setup_ffi_typeObject



12
13
14
15
16
# File 'lib/gir_ffi/builders/flags_builder.rb', line 12

def setup_ffi_type
  optionally_define_constant klass, :BitMask do
    lib.bit_mask(enum_sym, value_spec)
  end
end

#superclassObject



25
26
27
# File 'lib/gir_ffi/builders/flags_builder.rb', line 25

def superclass
  FlagsBase
end

#value_specObject



18
19
20
21
22
23
# File 'lib/gir_ffi/builders/flags_builder.rb', line 18

def value_spec
  info.values.map do |vinfo|
    val = GirFFI::ArgHelper.cast_uint32_to_int32(vinfo.value)
    { vinfo.name.to_sym => val }
  end.reduce(:merge)
end