File: field.rb

package info (click to toggle)
ruby-cstruct 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 412 kB
  • sloc: ruby: 1,008; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 797 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class CStruct
  class Field #:nodoc: all
    attr_accessor:tag
    attr_accessor:size
    attr_accessor:offset
    attr_accessor:sign
    attr_accessor:dimension

    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
    
    def byte_size
      @byte_size
    end
    
    def is_float?
      @sign == :float
    end
    
    def is_double?
      @sign == :double
    end
    
    def is_struct?
      @sign == :struct
    end
    
    def is_union?
      @sign == :union
    end

  end
end