1. with Ada.Streams;                       use Ada.Streams; 
  2. with Allegro.Bitmaps;                   use Allegro.Bitmaps; 
  3. with Allegro.Files;                     use Allegro.Files; 
  4. with Objects;                           use Objects; 
  5. with Resources;                         use Resources; 
  6.  
  7. private with Ada.Strings.Unbounded; 
  8.  
  9. package Archives is 
  10.  
  11.     -- An Archive is a data file containing individually addressable files. The 
  12.     -- Archive class should be subclassed for each archive file format supported 
  13.     -- by the application. 
  14.     type Archive is abstract new Limited_Object with private; 
  15.     type A_Archive is access all Archive'Class; 
  16.  
  17.     -- Loads an Archive into memory. An exception is raised on error. 
  18.     function Load_Archive( path : String ) return A_Archive; 
  19.     pragma Postcondition( Load_Archive'Result /= null ); 
  20.  
  21.     -- Loads an Archive into memory from a resource file. The resource can be 
  22.     -- unloaded independently of the Archive after calling this function. 
  23.     function Load_Archive( resource : not null A_Resource_File ) return A_Archive; 
  24.     pragma Postcondition( Load_Archive'Result /= null ); 
  25.  
  26.     -- Returns true if 'filename' exists in the Archive. 
  27.     function Exists( this     : access Archive; 
  28.                      filename : String ) return Boolean is abstract; 
  29.  
  30.     -- Reads 'filename' from the Archive and opens it as an Allegro bitmap. The 
  31.     -- Archive can be closed independently of the bitmap after calling this 
  32.     -- function. An exception is raised on error. 
  33.     function Load_Bitmap( this     : access Archive; 
  34.                           filename : String ) return A_Bitmap is abstract; 
  35.  
  36.     -- Reads 'filename' from the Archive and opens it as an in-memory packfile. 
  37.     -- The Archive can be closed independently of the bitmap after calling this 
  38.     -- function. An exception is raised on error. 
  39.     function Open( this     : access Archive; 
  40.                    filename : String ) return A_Packfile is abstract; 
  41.  
  42.     -- Reads 'filename' from the Archive and returns it as an in-memory buffer. 
  43.     -- The caller takes ownership of the returned buffer; closing the Archive 
  44.     -- does not affect it. An exception is raised on error. 
  45.     function Open_Chunk( this     : access Archive; 
  46.                          filename : String ) return access Stream_Element_Array is abstract; 
  47.  
  48.     -- Deletes the Archive. 
  49.     procedure Delete( this : in out A_Archive ); 
  50.     pragma Postcondition( this = null ); 
  51.  
  52.     -- Raised if an archive or a file in an archive can't be found. 
  53.     FILE_NOT_FOUND : exception; 
  54.  
  55.     -- Raised if a read error occurs while attempting to load an archive. The 
  56.     -- archive file is probably corrupt. 
  57.     READ_ERROR : exception; 
  58.  
  59.     -- Raised if the file extension of an archive is not supported. 
  60.     ARCHIVE_FORMAT_ERROR : exception; 
  61.  
  62. private 
  63.  
  64.     use Ada.Strings.Unbounded; 
  65.  
  66.     ---------------------------------------------------------------------------- 
  67.  
  68.     type Archive is abstract new Limited_Object with 
  69.         record 
  70.             path : Unbounded_String; 
  71.         end record; 
  72.  
  73.     procedure Construct( this : access Archive; path : String ); 
  74.  
  75.     ---------------------------------------------------------------------------- 
  76.  
  77.     type A_Path_Loader is 
  78.         access function( path : String ) return A_Archive; 
  79.  
  80.     type A_Resource_Loader is 
  81.         access function( resource : not null A_Resource_File ) return A_Archive; 
  82.  
  83.     -- Registers an archive file format by file extension. 'ext' is not case 
  84.     -- sensitive, should not contain a leading dot character, and may only be 
  85.     -- registered once. This procedure should be called at elaboration time by 
  86.     -- child packages that subclass Archive. 
  87.     procedure Register_Format( ext        : String; 
  88.                                pathLoader : not null A_Path_Loader; 
  89.                                resLoader  : not null A_Resource_Loader ); 
  90.  
  91. end Archives;