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.     -- caller takes ownership of the returned bitmap; closing the archive does 
  32.     -- not affect it. 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 caller takes ownership of the returned packfile; closing the archive 
  38.     -- does not affect it. An exception is raised on error. 
  39.     function Load_Packfile( this     : access Archive; 
  40.                             filename : String ) return A_Packfile is abstract; 
  41.  
  42.     -- Reads 'filename' from the Archive and returns it as a raw in-memory 
  43.     -- buffer. The caller takes ownership of the returned buffer; closing the 
  44.     -- Archive does not affect it. An exception is raised on error. 
  45.     function Load_Raw( 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.     type Archive is abstract new Limited_Object with 
  67.         record 
  68.             path : Unbounded_String; 
  69.         end record; 
  70.  
  71.     -- 'path' is the absolute path of the archive. 
  72.     procedure Construct( this : access Archive; path : String ); 
  73.  
  74.     ---------------------------------------------------------------------------- 
  75.  
  76.     -- Prototype for a function that loads an archive from a physical path. 
  77.     type A_Path_Loader is 
  78.         access function( path : String ) return A_Archive; 
  79.  
  80.     -- Prototype for a function that loads an archive from a Resource_File. 
  81.     type A_Resource_Loader is 
  82.         access function( resource : not null A_Resource_File ) return A_Archive; 
  83.  
  84.     -- Registers an archive file format by file extension. 'ext' is not case 
  85.     -- sensitive, should not contain a leading dot character, and may only be 
  86.     -- registered once. This procedure should be called at elaboration time by 
  87.     -- child packages that subclass Archive. 
  88.     procedure Register_Format( ext        : String; 
  89.                                pathLoader : not null A_Path_Loader; 
  90.                                resLoader  : not null A_Resource_Loader ); 
  91.  
  92. end Archives;