Module: Argus::CFields::ClassMethods

Defined in:
lib/argus/cfields.rb

Instance Method Summary collapse

Instance Method Details

#allot(n = 1) ⇒ Object


28
29
30
31
32
# File 'lib/argus/cfields.rb', line 28

def allot(n=1)
  result = data_index
  @data_index += n
  result
end

#data_indexObject


20
21
22
# File 'lib/argus/cfields.rb', line 20

def data_index
  @data_index ||= 0
end

#define_array_field(name, size, format, width, transform) ⇒ Object


48
49
50
51
52
# File 'lib/argus/cfields.rb', line 48

def define_array_field(name, size, format, width, transform)
  index = allot(width*size)
  format_string << "#{format}#{width*size}"
  define_method(name) { @data[index, width*size] }
end

#define_field(name, size, format, width = 1, &transform) ⇒ Object


34
35
36
37
38
39
40
# File 'lib/argus/cfields.rb', line 34

def define_field(name, size, format, width=1, &transform)
  if size
    define_array_field(name, size, format, width, transform)
  else
    define_scaler_field(name, format, width, transform)
  end
end

#define_scaler_field(name, format, width, transform) ⇒ Object


42
43
44
45
46
# File 'lib/argus/cfields.rb', line 42

def define_scaler_field(name, format, width, transform)
  index = allot(width)
  format_string << (width==1 ? format : "#{format}#{width}")
  define_method(name) { @data[index] }
end

#float32_t(name, size = nil) ⇒ Object


62
63
64
# File 'lib/argus/cfields.rb', line 62

def float32_t(name, size=nil)
  define_field(name, size, "e")
end

#format_stringObject


24
25
26
# File 'lib/argus/cfields.rb', line 24

def format_string
  @format_string ||= (defined?(initial_format) ? initial_format : "")
end

#int32_t(name, size = nil) ⇒ Object


66
67
68
# File 'lib/argus/cfields.rb', line 66

def int32_t(name, size=nil)
  define_field(name, size, "l<")
end

#matrix33_t(name, size = nil) ⇒ Object


70
71
72
# File 'lib/argus/cfields.rb', line 70

def matrix33_t(name, size=nil)
  define_field(name, size, "V", 9)
end

#uint16_t(name, size = nil) ⇒ Object


58
59
60
# File 'lib/argus/cfields.rb', line 58

def uint16_t(name, size=nil)
  define_field(name, size, "v")
end

#uint32_t(name, size = nil) ⇒ Object


54
55
56
# File 'lib/argus/cfields.rb', line 54

def uint32_t(name, size=nil)
  define_field(name, size, "V")
end

#vector31_t(name, size = nil) ⇒ Object


74
75
76
# File 'lib/argus/cfields.rb', line 74

def vector31_t(name, size=nil)
  define_field(name, size, "V", 3)
end