# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved. # License:: LGPL # Revision:: $Id: /w/fey/uttk/trunk/lib/uttk/filters/Compact.rb 21844 2006-02-17T17:26:59.771162Z pouillar $ module Uttk module Filters class Compact < Id include Concrete class InternalError < Exception end def initialize ( *a, &b ) super @record = {} end def new_node ( path, node ) if type = node.options[:type] unless type.is_a? Class if type.is_a? String and type =~ /^[A-Z]([a-zA-Z_]|::)*$/ type = eval type else raise ArgumentError, "bad type name #{type} : #{type.class}" end end # We record the flow if the type is NOT a subclass of Composite nor # a subclass of SubCmd (SubCmd and Composite included) unless type <= Strategies::Composite or type <= Strategies::SubCmd @record[path.to_s] = [Buffer.new, node] end end if node.segment == :attributes @record[path.to_s] = [Buffer.new, node] end end protected :new_node def up ( path ) if buf = @record[path.to_s] # If this path was recorded @record.delete path.to_s path << buf.last # We dump it as leaf leaf = buf.first.buffer.rpath_find(:first, path.to_regex_path_string) raise InternalError, 'in Compact#up the leaf cannot be nil' if leaf.nil? notif :new_leaf, path, leaf end super end protected :up def new_leaf ( path, leaf ) if @record.empty? # We are recording nothing so we transmit the message as is. super else # Each buffer receive the message @record.each do |path_s, buf| buf.first.update(:new_leaf, path, leaf) end end end end # class Compact end # module Filters end # module Uttk