lib/cpee/processtransformation/structures.rb in cpee-1.3.164 vs lib/cpee/processtransformation/structures.rb in cpee-1.3.166

- old
+ new

@@ -20,26 +20,23 @@ module CPEE module ProcessTransformation - class Link #{{{ - attr_accessor :from, :to - attr_reader :condition, :attributes - def initialize(from,to,cond=nil) - @from = from - @to = to - @condition = cond - @attributes = {} - end - end #}}} - - module Container + module Container #{{{ def container? @container || false end - end + end #}}} + module Struct #{{{ + def each(&a) + @sub.each{|s| a.call(s)} + end + def length + @sub.length + end + end #}}} class Node #{{{ include Container @@niceid = {} attr_reader :id, :label, :niceid @@ -61,25 +58,25 @@ @incoming = incoming @outgoing = outgoing @attributes = {} end end # }}} - - module Struct #{{{ - def each(&a) - @sub.each{|s| a.call(s)} + class Link #{{{ + attr_accessor :from, :to + attr_reader :condition, :attributes + def initialize(from,to,cond=nil) + @from = from + @to = to + @condition = cond + @attributes = {} end - def length - @sub.length - end end #}}} - - class Break < Node + class Break < Node #{{{ def initialize(context) super context, '-1', :break, 'BREAK', 1, [] end - end + end #}}} class Alternative < Array #{{{ include Container attr_accessor :condition, :condition_type attr_reader :id, :attributes @@ -99,10 +96,11 @@ def initialize(id) @container = true @id = id end end #}}} + class Loop #{{{ include Container include Struct include Enumerable attr_reader :id, :sub, :mode @@ -231,26 +229,26 @@ end #}}} class Tree < Array #{{{ def condition?; false; end - def to_s - "TREE:\n" << print_tree(self) + def to_s(verbose=true) + "TREE:\n" << print_tree(self,' ',verbose) end - def print_tree(ele,indent=' ') + def print_tree(ele,indent=' ',verbose=true) ret = '' ele.each_with_index do |e,i| last = (i == ele.length - 1) pchar = last ? '└' : '├' if e.container? ret << indent + pchar + ' ' + e.class.to_s.gsub(/[^:]*::/,'') + "\n" - ret << print_tree(e,indent + (last ? ' ' : '│ ')) - elsif e.is_a?(Break) && + ret << print_tree(e,indent + (last ? ' ' : '│ '),verbose) + elsif e.is_a?(Break) ret << indent + pchar + ' ' + e.class.to_s.gsub(/[^:]*::/,'') + "\n" else - ret << indent + pchar + ' ' + e.niceid.to_s + "\n" + ret << indent + pchar + ' ' + e.niceid.to_s + (verbose ? " (#{e.label})" : "") + "\n" end end ret end private :print_tree @@ -309,11 +307,10 @@ def same_first (n = self.map{|t| t.first }.uniq).length == 1 ? n.first : nil end - # future use def incoming(node) tcount = 1 self.each do |t| break if t.length == 1 tcount += 1 if t.last == node @@ -325,14 +322,10 @@ num = 0 self.each{|n| num += 1 if n.include?(e)} num == self.length end - def aaa - puts 'rrr' - end - def all_loops? num = 0 self.each{|n| num += 1 if n.first == n.last } num == self.length end @@ -415,16 +408,9 @@ end end max end - - def segment_by_loops(loops) - # supress loops - self.delete_if { |t| loops.include?(t) } - self.eliminate(loops) - loops.extend - end def find_endnode # supress loops trcs = self.dup # dangerous TODO