DEFINITION MODULE Stream;

(* Copyright (C) 1996 by Marcel Timmermans *)

(* Stream example *)

FROM SYSTEM IMPORT ADDRESS,BYTE;

FROM Objects IMPORT TObject;
IMPORT DosD,DosL;

CONST 
 BufSize=1024;

TYPE
 errortype = (ok,cantOpen,readErr,writeErr);
 TStream = CLASS(TObject)
             Write,eof:BOOLEAN;
             file:DosD.FileHandlePtr;
             buffer:POINTER TO ARRAY[0..BufSize] OF CHAR;
             pos,
             buflen,
             bufpos:LONGINT;
             Error:errortype;
             PROCEDURE Open(name:ARRAY OF CHAR; write:BOOLEAN):BOOLEAN;
             PROCEDURE ReadBytes(adr:ADDRESS; len:LONGINT);
             PROCEDURE WriteBytes(adr:ADDRESS; len:LONGINT);
             PROCEDURE Close;
           END;

 TReader = CLASS(TObject)
             FStream:TStream;
             PROCEDURE Init(s:TStream);
             PROCEDURE ReadBoolean(VAR b:BOOLEAN);
             PROCEDURE ReadInt(VAR i:LONGINT);
             PROCEDURE ReadChar(VAR ch:CHAR);
             PROCEDURE ReadBlock(VAR blk:ARRAY OF BYTE);
           END;

 TWriter = CLASS(TObject)
             FStream:TStream;
             PROCEDURE Init(s:TStream);
             PROCEDURE WriteBoolean(b:BOOLEAN);
             PROCEDURE WriteInt(i:LONGINT);
             PROCEDURE WriteChar(ch:CHAR);
             PROCEDURE WriteBlock(blk:ARRAY OF BYTE);
           END;

END Stream.
