home *** CD-ROM | disk | FTP | other *** search
- --
- -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
- -- Author: Gilles Demailly
- --
- --
- -- Permission to use, copy, modify, and distribute this software and its
- -- documentation for any purpose and without fee is hereby granted,
- -- provided that the above copyright and authorship notice appear in all
- -- copies and that both that copyright notice and this permission notice
- -- appear in supporting documentation.
- --
- -- The ARA makes no representations about the suitability of this software
- -- for any purpose. It is provided "as is" without express
- -- or implied warranty.
- --
-
- --
- -- This package provides binary file Input-Ouput services.
- -- These services are platform independant i.e. files manipulated
- -- may use Big_Endian and Little_Endian representations.
- --
- -- basic file services are based on the Ada.Sequential_IO services
- -- (opering, creating, closing ...)
- --
-
- with Basic_Definitions;
- use Basic_Definitions;
-
- with Ada.Sequential_Io;
-
- package Byte_Utilities is
-
- -- definition of the subtype Byte
- ---------------------------------
- subtype Byte is Unsigned_8;
-
- -- array of Bytes
- -----------------
- type Bytes is array (Unsigned_32 range <>) of Byte;
-
- type Acc_Bytes is access Bytes;
-
- -- type of files manipulated by Byte_Utilities
- ----------------------------------------------
- type File_Type is limited private;
-
- -- files opening modes
- ----------------------
- type File_Mode is (In_File, Out_File, Append_File);
-
- -- underlying representation
- ----------------------------
- type Byte_Order_Scheme is (Big_Endian, Little_Endian);
-
- -- create a file
- ----------------
- procedure Create (File : in out File_Type;
- Mode : in File_Mode := Out_File;
- Byte_Order : in Byte_Order_Scheme := Big_Endian;
- Name : in String);
-
- pragma Inline (Create);
-
- -- open a file
- --------------
- procedure Open (File : in out File_Type;
- Mode : in File_Mode;
- Byte_Order : in Byte_Order_Scheme;
- Name : in String);
-
- pragma Inline (Open);
-
- -- close a file
- ---------------
- procedure Close (File : in out File_Type);
-
- pragma Inline (Close);
-
- -- delete a file
- ----------------
- procedure Delete (File : in out File_Type);
-
- pragma Inline (Delete);
-
- -- reset a file (may try to change mode and underlying representation)
- ----------------------------------------------------------------------
- procedure Reset (File : in out File_Type;
- Mode : in File_mode;
- Byte_Order : in Byte_Order_Scheme);
-
- -- reset a file (no mode or underlying representation changes)
- --------------------------------------------------------------
- procedure Reset (File : in out File_Type);
-
-
- --
- -- Read procedures for types defined in Basic_Definitions
- --
-
- procedure Read (File : in File_Type; Item : out Unsigned_8);
-
- procedure Read (File : in File_Type; Item : out Unsigned_16);
-
- procedure Read (File : in File_Type; Item : out Unsigned_32);
-
- procedure Read (File : in File_Type; Item : out Unsigned_64);
-
- procedure Read (File : in File_Type; Item : out Integer_8);
-
- procedure Read (File : in File_Type; Item : out Integer_16);
-
- procedure Read (File : in File_Type; Item : out Integer_32);
-
- procedure Read (File : in File_Type; Item : out Integer_64);
-
- procedure Read (File : in File_Type; Item : out Float_32);
-
- procedure Read (File : in File_Type; Item : out Float_64);
-
- --
- -- Write procedures for types defined in Basic_Definitions
- --
-
- procedure Write (File : in File_Type; Item : in Unsigned_8);
-
- procedure Write (File : in File_Type; Item : in Unsigned_16);
-
- procedure Write (File : in File_Type; Item : in Unsigned_32);
-
- procedure Write (File : in File_Type; Item : in Unsigned_64);
-
- procedure Write (File : in File_Type; Item : in Integer_8);
-
- procedure Write (File : in File_Type; Item : in Integer_16);
-
- procedure Write (File : in File_Type; Item : in Integer_32);
-
- procedure Write (File : in File_Type; Item : in Integer_64);
-
- procedure Write (File : in File_Type; Item : in Float_32);
-
- procedure Write (File : in File_Type; Item : in Float_64);
-
-
- --
- -- Read functions for types defined in Basic_Definitions
- --
-
- function Get_Unsigned_8
- (From : Acc_Bytes;
- Index : Unsigned_32)
- return Unsigned_8;
-
- function Get_Unsigned_16
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Unsigned_16;
-
- function Get_Unsigned_32
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Unsigned_32;
-
- function Get_Unsigned_64
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Unsigned_64;
-
- function Get_Integer_8
- (From : Acc_Bytes;
- Index : Unsigned_32)
- return Integer_8;
-
- function Get_Integer_16
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Integer_16;
-
- function Get_Integer_32
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Integer_32;
-
- function Get_Integer_64
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Integer_64;
-
- function Get_Float_32
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Float_32;
-
- function Get_Float_64
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Byte_Order : Byte_Order_Scheme := Big_Endian)
- return Float_64;
-
- function Get_String
- (From : Acc_Bytes;
- Index : Unsigned_32;
- Length : Positive)
- return String;
-
- private
-
- package Byte_Io is new Ada.Sequential_Io (Byte);
-
- -- just add the underlying representation mode
- ----------------------------------------------
- type File_Type is
- record
- File : Byte_Io.File_Type;
- Byte_Order : Byte_Order_Scheme := Big_Endian;
- end record;
-
- end Byte_Utilities;
-