| ASCL User's Guide: ASCL, ADA Standard Component Library; Version 0.1.0; Document Revision $Revision: 1.7 $ | ||
|---|---|---|
| Prev | Next | |
Keyed_File_IO_Package generic package provides subprograms for creating and maintaining files of keyed data. The subprograms of this package will support any data format, key for access, and file name the user needs in his application. The User instantiates the package for the set of generic actual parameters needed for the application.
Keyed_File_IO_Package provides file-related subprograms and data-related subprograms.
The file-related subprograms perform the following functions:
o Create a file for data storage o Open a file for data storage/access o Verify if a file exists o Close a file
o Add data to a file
o Delete data from a file
o Rewrite data on a file
o Read data equal to a key
o Read data less than or equal to a key
o Read data greater than or equal to a key o Read data associated with the next Index_File position.
EXCEPTIONS
Data_File_Error ==> raised when a Status_Error, Mode_Error, Use_Error,
or Device_Error occurs when opening or creating the data file.
Data_File_Does_Not_Exist ==> raised when a Name_Error occurs when
opening or creating the data file.
Data_File_End_Error ==> raised when End_Error occurs when opening
the data file.
Data_File_Read_Error ==> raised when Data_Error occurs when opening
the data file.
Data_File_Is_Not_Open ==> raised when a Read or Write operation is
attempted when the Data file is not open.
Index_File_Error ==> raised when a Status_Error, Mode_Error,
Use_Error, or Device_Error occurs when opening or creating the index file.
Index_File_Does_Not_Exist ==> raised when a Name_Error occurs when
opening or creating the index file.
Index_File_End_Error ==> raised when End_Error occurs when opening
index file or when end of index file.
Index_File_Read_Error ==> raised when Data_Error occurs when opening
index file.
Index_File_Is_Not_Open ==> raised when a Read or Write operation is
attempted when the Data file is not open.
Data_Already_Exists ==> raised when record of index file already
exists.
Data_Does_Not_Exist ==> raised when record of index file is not
active.
REUSE NOTES
Reuse of this package would be valuable when keyed storage of data is desired and the overhead of a Database Management System (DBMS) is too great, a DBMS is unavailable, or a database is small and only one key is needed. For example, this component would be appropriate for a small database of personnel records using the employee's identification number or social security number for the key.
An example of instantiating this package for a system wanting to store and retrieve person records by social security number is as follows:
Let the types be defined as follows:
subtype SSN_String_Subtype is String (1..9); type Personnel_Record_Type is record Name : String (1..20) := (1..20 => ' '); SSN : SSN_String_Subtype := (1..9 => ' '); Id : Natural := 0; end record;
package Person_Record_IO is new Keyed_File_IO_Package
(Data_Type => Personnel_Record_Type,
Key_Type => SSN_String_Subtype);
use Person_Record_IO;
Exceptions raised by File_Exists subprogram are handled within the subprogram. All other system-defined exceptions will raise an appropriate package defined exception and will propragate the exception back to the reuser.
Restrictions ============
Keyed_File_IO_Package body provides routines to create and maintain the data storage-retrieval structure. This structure consists of two direct files, Data_File and Index_File. The sizes of both files are system dependent.
ASCL is implemented to work with GNAT, the GNU Ada compiler.