
-- This file is modified from the SmartEiffel The GNU Eiffel Compiler
-- Tools and Libraries.

-- See the Copyright notice for the SmartEiffel The GNU Eiffel
-- Compiler Tools and Libraries at the end of this file.
class OBSERVABLE
	-- Part of the ''Observer'' Design Pattern. An object of this class
	-- should notify its observers whenever its state changes. Use the
	-- `notify' feature for that.  -- See also OBSERVER

creation {ANY}
	make
feature {ANY}
	-- Element change
	add (a_obs: OBSERVER[like Current]) is
			-- Add an observer that should be notified
		do
			observers.put_last (a_obs)
		end

	remove (a_obs: OBSERVER[like Current]) is
			-- Remove an observer that should not be notified anymore
		require
			has (a_obs)
		do
			observers.start
			observers.search_forth (a_obs)
			observers.remove_at
		end

	has (a_obs: OBSERVER[like Current]): BOOLEAN is
			-- True if the observer will be notified when the state of Current changes
		do
			Result := observers.has (a_obs)
		end

feature {}
	notify is
			-- Notify all the observers that the state of Current changed
		do
			from
				observers.start
			until
				observers.off
			loop
				observers.item_for_iteration.update (Current)
				observers.forth
			end
		end

feature {NONE}
	observers: DS_LINKED_LIST[OBSERVER[like Current]]
			-- The collection of observers

	make is
			-- Make an empty observer
		do
			!!observers.make_default
		end
invariant
	notifiable: observers /= Void

end -- class OBSERVABLE
--
-- ------------------------------------------------------------------------------------------------------------------------------
-- Copyright notice below. Please read.
--
-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
-- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
--
-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
-- Copyright(C) 2003-2005: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
--
-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
--
-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
-- ------------------------------------------------------------------------------------------------------------------------------
