Class: PlcUtil::Awl::StructType

Inherits:
Object
  • Object
show all
Defined in:
lib/plcutil/siemens/awl/struct_type.rb

Instance Method Summary collapse

Constructor Details

#initializeStructType

Returns a new instance of StructType.



4
5
6
# File 'lib/plcutil/siemens/awl/struct_type.rb', line 4

def initialize
	@children = []
end

Instance Method Details

#add(name, type, comment) ⇒ Object



8
9
10
# File 'lib/plcutil/siemens/awl/struct_type.rb', line 8

def add(name, type, comment)
	@children << {:name => name, :type => type, :comment => comment}
end

#each_exploded(start_addr, name_prefix, &block) ⇒ Object



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
46
47
48
# File 'lib/plcutil/siemens/awl/struct_type.rb', line 20

def each_exploded(start_addr, name_prefix, &block)
	addr = skip_padding start_addr
     @children.each do |ch|
       full_name = if !name_prefix || name_prefix.empty?
                     ch[:name]
                   else
                     "#{name_prefix}.#{ch[:name]}"
                   end
       case ch[:type]
       when StructType
         addr = ch[:type].each_exploded(addr, full_name) do |a, n, c, t|
           yield a, n, c, t
         end
       when ArrayType
         ct = ch[:type]
         addr = ct.skip_padding addr
         ct.range.each do |n|
           yield addr, "#{full_name}[#{n}]", ch[:comment], ct.element_type.type_name
           addr = ct.element_type.end_address addr
         end
       when BasicType
         ct = ch[:type]
         addr = ct.skip_padding addr
         yield addr, full_name, ch[:comment], ct.type_name
         addr = ct.end_address addr
       end
     end
     addr
end

#end_address(start_addr) ⇒ Object



16
17
18
# File 'lib/plcutil/siemens/awl/struct_type.rb', line 16

def end_address(start_addr)
  @children.inject(start_addr) {|addr, ch| ch[:type].end_address addr }
end

#skip_padding(addr) ⇒ Object



12
13
14
# File 'lib/plcutil/siemens/awl/struct_type.rb', line 12

def skip_padding(addr)
  addr.next_word
end