Class: CStruct::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/cstruct/field.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, size, offset, sign, dimension = nil, *args) ⇒ Field

Returns a new instance of Field.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cstruct/field.rb', line 9

def initialize(tag,size,offset,sign,dimension = nil,*args)
  @tag    = tag
  @size   = size 
  @offset = offset
  @sign   = sign
  @dimension = dimension
  @byte_size = size

  if @dimension
    @byte_size = @size * dimension.inject(1){|m,i| m*=i}
    @sign = :struct_array if @sign == :struct      
  end

end

Instance Attribute Details

#dimensionObject

Returns the value of attribute dimension.



7
8
9
# File 'lib/cstruct/field.rb', line 7

def dimension
  @dimension
end

#offsetObject

Returns the value of attribute offset.



5
6
7
# File 'lib/cstruct/field.rb', line 5

def offset
  @offset
end

#signObject

Returns the value of attribute sign.



6
7
8
# File 'lib/cstruct/field.rb', line 6

def sign
  @sign
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/cstruct/field.rb', line 4

def size
  @size
end

#tagObject

Returns the value of attribute tag.



3
4
5
# File 'lib/cstruct/field.rb', line 3

def tag
  @tag
end

Instance Method Details

#byte_sizeObject



24
25
26
# File 'lib/cstruct/field.rb', line 24

def byte_size
  @byte_size
end

#is_double?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cstruct/field.rb', line 32

def is_double?
  @sign == :double
end

#is_float?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cstruct/field.rb', line 28

def is_float?
  @sign == :float
end

#is_struct?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cstruct/field.rb', line 36

def is_struct?
  @sign == :struct
end

#is_union?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cstruct/field.rb', line 40

def is_union?
  @sign == :union
end