Method: CTypes::Bitmap#initialize

Defined in:
lib/ctypes/bitmap.rb

#initialize(bits:, type: Helpers.uint32) ⇒ Bitmap

create a new Bitmap

Parameters:

  • bits (Enum)

    mapping of bit position to name

  • type (Type) (defaults to: Helpers.uint32)

    ctype to encode value as; defaults to uint32

Raises:



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ctypes/bitmap.rb', line 46

def initialize(bits:, type: Helpers.uint32)
  raise Error, "bits must be an Enum instance: %p" % bits unless
    bits.is_a?(Enum)

  @type = type
  @bits = bits
  @bits_max = type.size * 8
  @bits_constraint = Dry::Types["integer"]
    .constrained(gteq: 0, lt: @bits_max)
  @dry_type = Dry::Types["array"].of(@bits.dry_type).default([].freeze)
end