Sha256: 5455d5b3aca6c61ad793a85215df054d766684365a64b1dd480b6fba9ba59abc

Contents?: true

Size: 750 Bytes

Versions: 13

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

require "gir_ffi/builders/enum_builder"
require "gir_ffi/flags_base"

module GirFFI
  module Builders
    # 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.
    class FlagsBuilder < EnumBuilder
      def setup_ffi_type
        optionally_define_constant klass, :BitMask do
          lib.bit_mask(enum_sym, value_spec)
        end
      end

      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

      def superclass
        FlagsBase
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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