Class: CAStruct::Builder::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/carray/struct_builder.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, opt = {}) ⇒ Member

:nodoc:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/carray/struct_builder.rb', line 16

def initialize (name, type, opt={})
  @name, @type, @opt = name, type, opt
  if @type == :bitfield
    # Bit members carry their own offset/length math via the
    # Builder's bit() method; the standard byte cursor in
    # member() does not advance for them.  Setting byte_length=0
    # keeps any defensive byte-loop arithmetic harmless.
    @bytes       = 0
    @byte_length = 0
  elsif @type.kind_of?(CArray)
    @type = @type.copy
    @byte_length = @type.bytes * @type.elements
    @bytes  = 0
  else
    data_type, @bytes = CArray.guess_type_and_bytes(@type, @opt[:bytes])
    if data_type == CA_OBJECT
      raise CAStruct::DefinitionError,
            "CA_OBJECT cannot be a member of struct or union"
    end
    @byte_length = @bytes
  end
  @offset = @opt[:offset]
end

Instance Attribute Details

#byte_lengthObject (readonly)

Returns the value of attribute byte_length.



40
41
42
# File 'lib/carray/struct_builder.rb', line 40

def byte_length
  @byte_length
end

#bytesObject (readonly)

Returns the value of attribute bytes.



40
41
42
# File 'lib/carray/struct_builder.rb', line 40

def bytes
  @bytes
end

#nameObject (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/carray/struct_builder.rb', line 40

def name
  @name
end

#offsetObject (readonly)

Returns the value of attribute offset.



40
41
42
# File 'lib/carray/struct_builder.rb', line 40

def offset
  @offset
end

#optObject (readonly)

Returns the value of attribute opt.



40
41
42
# File 'lib/carray/struct_builder.rb', line 40

def opt
  @opt
end

#typeObject (readonly)

Returns the value of attribute type.



40
41
42
# File 'lib/carray/struct_builder.rb', line 40

def type
  @type
end