Site Menu Project Specification Implementation Recommendations Reference Needs Updating Work in Progress Wastebasket Wiki Manual |
Pervasive IO As An Import AggregatorWhen using a library model with one I/O module for each pervasive type, each I/O module must be imported separately before use. In most situations this would be rather inconvenient. It is therefore desirable to be able to import all pervasive I/O modules with a single import directive. The following is an example how module PervasiveIO could be provided as an aggregator module for all pervasive I/O procedures. The example assumes an extension of the import statement syntax whereby module identifiers following DEFINITION MODULE PervasiveIO; (* Aggregator module for all pervasive I/O operations *) (* Import type specific pervasive I/O modules for explicit re-export *) IMPORT BITSET+, BOOLEAN+, OCTET+, CHAR+, UNICHAR+, CARDINAL+, LONGCARD+, INTEGER+, LONGINT+, REAL+, LONGREAL+; END PervasiveIO. The aggregator module may provide additional facilities of its own. The following example shows how module PervasiveIO could further provide aliases for all I/O procedures following old-style Modula-2 naming conventions. For brevity, procedures with formatting parameters are omitted in this example. DEFINITION MODULE PervasiveIO; (* Aggregator module for all pervasive I/O operations *) FROM FileIO IMPORT File; (* Import type specific pervasive I/O modules for explicit re-export *) IMPORT BITSET+, BOOLEAN+, OCTET+, CHAR+, UNICHAR+, CARDINAL+, LONGCARD+, INTEGER+, LONGINT+, REAL+, LONGREAL+; (* Provide old-style Modula-2 naming for I/O procedures *) (* Convenience wrappers for BITSET.Read and BITSET.Write *) <*INLINE*> PROCEDURE ReadBitset( fid : File; VAR b : BOOLEAN ); <*INLINE*> PROCEDURE WriteBitset( fid : File; b : BOOLEAN ); (* Convenience wrappers for BOOLEAN.Read and BOOLEAN.Write *) <*INLINE*> PROCEDURE ReadBool( fid : File; VAR b : BOOLEAN ); <*INLINE*> PROCEDURE WriteBool( fid : File; b : BOOLEAN ); (* Convenience wrappers for OCTET.Read and OCTET.Write *) <*INLINE*> PROCEDURE ReadOctet( fid : File; VAR b : OCTET ); <*INLINE*> PROCEDURE WriteOctet( fid : File; b : OCTET ); (* Convenience wrappers for CHAR.Read and CHAR.Write *) <*INLINE*> PROCEDURE ReadChar( fid : File; VAR ch : CHAR ); <*INLINE*> PROCEDURE WriteChar( fid : File; ch : CHAR ); (* Convenience wrappers for UNICHAR.Read and UNICHAR.Write *) <*INLINE*> PROCEDURE ReadUChar( fid : File; VAR ch : UNICHAR ): <*INLINE*> PROCEDURE WriteUChar( fid : File; ch : UNICHAR ); (* Convenience wrappers for CARDINAL.Read and CARDINAL.Write *) <*INLINE*> PROCEDURE ReadCard( fid : File; VAR num : CARDINAL ); <*INLINE*> PROCEDURE WriteCard( fid : File; num : CARDINAL ); (* Convenience wrappers for LONGCARD.Read and LONGCARD.Write *) <*INLINE*> PROCEDURE ReadLCard( fid : File; VAR num : LONGCARD ); <*INLINE*> PROCEDURE WriteLCard( fid : File; num : LONGCARD ); (* Convenience wrappers for INTEGER.Read and INTEGER.Write *) <*INLINE*> PROCEDURE ReadInt( fid : File; VAR num : INTEGER ); <*INLINE*> PROCEDURE WriteInt( fid : File; num : INTEGER ); (* Convenience wrappers for LONGINT.Read and LONGINT.Write *) <*INLINE*> PROCEDURE ReadLInt( fid : File; VAR num : LONGINT ); <*INLINE*> PROCEDURE WriteLInt( fid : File; num : LONGINT ); (* Convenience wrappers for REAL.Read and REAL.Write *) <*INLINE*> PROCEDURE ReadReal( fid : File; VAR num : REAL ); <*INLINE*> PROCEDURE WriteReal( fid : File; num : REAL ); (* Convenience wrappers for LONGREAL.Read and LONGREAL.Write *) <*INLINE*> PROCEDURE ReadLReal( fid : File; VAR num : LONGREAL ); <*INLINE*> PROCEDURE WriteLReal( fid : File; num : LONGREAL ); END PervasiveIO. All wrapper procedures are implemented as inline procedures as illustrated by the following examples ... (* Implementation of wrappers for CHAR.Read and CHAR.Write *) <*INLINE*> PROCEDURE ReadChar( fid : File; VAR ch : CHAR ); BEGIN CHAR.Read( fid, ch ); END ReadChar; <*INLINE*> PROCEDURE WriteChar( fid : File; ch : CHAR ); BEGIN CHAR.Write( fid, ch ); END WriteChar; |