with Ada.Streams; use Ada.Streams;
with Allegro.Bitmaps; use Allegro.Bitmaps;
with Allegro.Files; use Allegro.Files;
with Objects; use Objects;
with Resources; use Resources;
private with Ada.Strings.Unbounded;
package Archives is
-- An Archive is a data file containing individually addressable files. The
-- Archive class should be subclassed for each archive file format supported
-- by the application.
type Archive is abstract new Object with private;
type A_Archive is access all Archive'Class;
-- Loads an Archive into memory. An exception is raised on error.
function Load_Archive( path : String ) return A_Archive;
pragma Postcondition( Load_Archive'Result /= null );
-- Loads an Archive into memory from a resource file. The resource can be
-- unloaded independently of the Archive after calling this function.
function Load_Archive( resource : not null A_Resource_File ) return A_Archive;
pragma Postcondition( Load_Archive'Result /= null );
-- Returns true if 'filename' exists in the Archive.
function Exists( this : access Archive;
filename : String ) return Boolean is abstract;
-- Reads 'filename' from the Archive and opens it as an Allegro bitmap. The
-- Archive can be closed independently of the bitmap after calling this
-- function. An exception is raised on error.
function Load_Bitmap( this : access Archive;
filename : String ) return A_Bitmap is abstract;
-- Reads 'filename' from the Archive and opens it as an in-memory packfile.
-- The Archive can be closed independently of the bitmap after calling this
-- function. An exception is raised on error.
function Open( this : access Archive;
filename : String ) return A_Packfile is abstract;
-- Reads 'filename' from the Archive and returns it as an in-memory buffer.
-- The caller takes ownership of the returned buffer; closing the Archive
-- does not affect it. An exception is raised on error.
function Open_Chunk( this : access Archive;
filename : String ) return access Stream_Element_Array is abstract;
-- Deletes the Archive.
procedure Delete( this : in out A_Archive );
pragma Postcondition( this = null );
-- Raised if an archive or a file in an archive can't be found.
FILE_NOT_FOUND : exception;
-- Raised if a read error occurs while attempting to load an archive. The
-- archive file is probably corrupt.
READ_ERROR : exception;
-- Raised if the file extension of an archive is not supported.
ARCHIVE_FORMAT_ERROR : exception;
private
use Ada.Strings.Unbounded;
----------------------------------------------------------------------------
type Archive is abstract new Object with
record
path : Unbounded_String;
end record;
-- Raises COPY_NOT_ALLOWED.
procedure Adjust( this : access Archive );
procedure Construct( this : access Archive; path : String );
----------------------------------------------------------------------------
type A_Path_Loader is
access function( path : String ) return A_Archive;
type A_Resource_Loader is
access function( resource : not null A_Resource_File ) return A_Archive;
-- Registers an archive file format by file extension. 'ext' is not case
-- sensitive, should not contain a leading dot character, and may only be
-- registered once. This procedure should be called at elaboration time by
-- child packages that subclass Archive.
procedure Register_Format( ext : String;
pathLoader : not null A_Path_Loader;
resLoader : not null A_Resource_Loader );
end Archives;