This site contains older material on Eiffel. For the main Eiffel page, see http://www.eiffel.com.

EiffelBase class
(HTML page generated by ISE Eiffel 4.2)

Eiffel Class
indexing
	description: "Objects that may be stored and retrieved along with all their dependents. This class may be used as ancestor by classes needing its facilities.";
	status: "See notice at end of class";
	date: "$Date: 2007-03-30 19:10:11 +0000 (Fri, 30 Mar 2007) $";
	revision: "$Revision: 95354 $"

class STORABLE

inherit
	EXCEPTIONS

feature -- Access

	retrieved (medium: IO_MEDIUM): ANY is
			-- Retrieved object structure, from external
			-- representation previously stored in medium.
			-- To access resulting object under correct type,
			-- use assignment attempt.
			-- Will raise an exception (code Retrieve_exception)
			-- if medium content is not a stored Eiffel structure.
		require
			medium_not_void: medium /= void;
			medium_exists: medium.exists;
			medium_is_open_read: medium.is_open_read;
			medium_supports_storable: medium.support_storable
		do
			Result := medium.retrieved
		ensure
			result_exists: Result /= void
		end;

	retrieve_by_name (file_name: STRING): ANY is
			-- Retrieve object structure, from external
			-- representation previously stored in a file
			-- called file_name.
			-- To access resulting object under correct type,
			-- use assignment attempt.
			-- Will raise an exception (code Retrieve_exception)
			-- if file content is not a stored Eiffel structure.
			-- Will return Void if the file does not exist or
			-- is not readable.
		require
			file_name_exists: file_name /= void;
			file_name_meaningful: notfile_name.empty
		local
			file: RAW_FILE
		do
			create file.make (file_name);
			if file.exists and then file.is_readable then
				file.open_read;
				Result := file.retrieved;
				file.close
			end
		end;

feature -- Element change

	basic_store (medium: IO_MEDIUM) is
			-- Produce on medium an external representation of the
			-- entire object structure reachable from current object.
			-- Retrievable within current system only.
		require
			medium_not_void: medium /= void;
			medium_exists: medium.exists;
			medium_is_open_write: medium.is_open_write;
			medium_supports_storable: medium.support_storable
		do
			medium.basic_store (Current)
		end;

	general_store (medium: IO_MEDIUM) is
			-- Produce on medium an external representation of the
			-- entire object structure reachable from current object.
			-- Retrievable from other systems for same platform
			-- (machine architecture).
		require
			medium_not_void: medium /= void;
			medium_exists: medium.exists;
			medium_is_open_write: medium.is_open_write;
			medium_supports_storable: medium.support_storable
		do
			medium.general_store (Current)
		end;

	independent_store (medium: IO_MEDIUM) is
			-- Produce on medium an external representation of the
			-- entire object structure reachable from current object.
			-- Retrievable from other systems for the same or other
			-- platform (machine architecture).
		require
			medium_not_void: medium /= void;
			medium_exists: medium.exists;
			medium_is_open_write: medium.is_open_write;
			medium_supports_storable: medium.support_storable
		do
			medium.independent_store (Current)
		end;

	store_by_name (file_name: STRING) is
			-- Produce on file called file_name an external
			-- representation of the entire object structure
			-- reachable from current object.
			-- Retrievable from other systems for same platform
			-- (machine architecture).
		require
			file_name_not_void: file_name /= void;
			file_name_meaningful: notfile_name.empty
		local
			file: RAW_FILE;
			a: ANY
		do
			create file.make (file_name);
			if (file.exists and then file.is_writable) or else (file.is_creatable) then
				file.open_write;
				file.general_store (Current);
				file.close
			else
				a := ("write permission failure").to_c;
				eraise ($a, io_exception)
			end
		end;

end -- class STORABLE