indexing
	cluster: "demangler"
	namespace: "candidate"
	description: "A fix for a single error in a `synchronised_directory'."
	original_author: "Justin Finnerty"
	original_date: "July 2005"
	current_date: "$Date: 2005/09/27 06:14:47 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.1 $"	
	-- $Log: transform.e,v $
	-- Revision 2.1  2005/09/27 06:14:47  finnerty
	-- Updated to use GOBO and work with SE and VE
	--
	-- Revision 2.0  2005/08/26 23:31:39  finnerty
	-- == alpha version ==
	--
	-- Revision 1.2  2005/08/21 11:56:31  finnerty
	-- Alpha 1 version
	--
	-- Revision 1.1  2005/08/16 15:05:55  finnerty
	-- Initial abstract data type for a tranformation on a sync dir
	--

deferred class TRANSFORM
	-- A fix for a single error in a `synchronised_directory'. This 
	-- records two sets of operations, one to perform on the 
	-- virtual and one for the real `synchronised_directory'.

	-- Programming note: It is a requirement of the design that all
	-- `TRANSFORM' sub-types are potentially undoable/redoable.

	-- Programming note: When a `TRANSFORM' object is created it must
	-- performs its operation on the virtual directory. If it is
	-- removed from a `sync_report', the report will call `remove' to
	-- undo this operation on the virtual directory. 
	
	-- Programming note: `action' and `undo' are template methods,
	-- derived classes should effect `do_action' and `do_undo'.

feature {ANY}
	-- Queries on class
	last_transform: SE_REFERENCE [TRANSFORM] is
			-- Last transform performed.
		once
			!!Result.default_create
		end

feature {ANY}
	-- Queries on object
	is_actionable: BOOLEAN is
			-- Can this action be done?
		do
			Result := previous_transform = Void
			-- and not last_transform.item = Current
		ensure
			-- Result implies not already done
		end

	is_undoable: BOOLEAN is
			-- Can this action be undone?
		do
			Result := last_transform.item = Current and previous_transform /= Void
		ensure
			-- Result implies this was the last action performed
		end

	name: UC_STRING is
			-- descriptive label for transform type (for REPORT_DISPLAY etc)
		deferred
		end

	previous_transform: TRANSFORM
			-- Transform performed just before this one.
		
	remove is
			-- Perform undo operation on virtual directory.
		require
			Is_actionable: is_actionable
		deferred
		ensure
			Is_not_doable: not is_actionable
								not is_undoable
			-- Note: old is_actionable and previous_transform = Current
			-- implies Is_not_doable
		end
	
	sync_report: SYNC_REPORT
			-- The owning report (set during creation)

	to_text: UC_STRING is
			-- concise description of action to perform (for
			-- REPORT_DISPLAY etc).
		deferred
		end

feature {ANY}
	-- Perform transformations
	frozen action is
			-- Perform a corrective operation on real file system
		require
			Is_actionable: is_actionable
		do
			if last_transform.item = Void then
				-- Indicate we are the first action ever!
				previous_transform := Current
			else
				previous_transform := last_transform.item
			end
			do_action
			last_transform.set_item (Current)
		ensure
			Is_undoable: is_undoable
		end

	frozen undo is
			-- Undo a corrective operation on real file system
		require
			Is_undoable: is_undoable
		do
			do_undo
			if previous_transform = Current then
				-- We were the first action!
				last_transform.set_item (Void)
			else
				last_transform.set_item (previous_transform)
			end
			previous_transform := Void
		ensure
			Is_actionable: is_actionable
		end

feature {ANY}
	-- Perform transformations
	do_action is
			-- Perform a corrective operation on a sync_dir
		deferred
		end

	do_undo is
			-- Undo a corrective operation on a sync_dir
		deferred
		end

invariant
	sync_report /= Void
end -- class TRANSFORM
