(* 10.2 Bounded Queue Interface Presented below is the interface definition for the bounded form of queue described abstractly in Chapter 9. The algorithmic complexity measure for each operation is supplied in Table 10.1. *) DEFINITION MODULE QSBMI; (*=========================================================== Version : 1.00 18 May 1989 C. Lins Compiler : TopSpeed Modula-2 Component: Monolithic Structures - Queue (Opaque version) Non-priority Non-balking Sequential Bounded Managed Iterator REVISION HISTORY v1.00 18 May 1989 C. Lins: Initial TopSpeed Modula-2 implementation. (C) Copyright 1989 Charles A. Lins ===========================================================*) FROM ErrorHandling IMPORT (*--Type*) HandlerProc; FROM Items IMPORT (*--Type*) Item, AccessProc, LoopAccessProc; FROM QEnum IMPORT (*--Type*) Exceptions; FROM TypeManager IMPORT (*--Type*) TypeID; (*--------------------*) (* 10.2.1 Type Declarations A queue is declared as the abstract data type, Queue. In the bounded form presented here, a queue is limited to a maximum size of 8100 items due to implementation constraints placed on us by the compiler. *) TYPE Queue; TYPE QueueSize = [1..8100]; CONST NullQueue = Queue(NIL); (* 10.2.2 Exceptions The ModuleID uniquely identifies this module from all others. QueueError returns the most recent queue exception, or noerr if the last operation was successful. While SetHandler and GetHandler allow assignment and retrieval of exception handling routines for specific exceptions. *) CONST ModuleID = 13; PROCEDURE QueueError () : Exceptions (*-- out *); PROCEDURE SetHandler ( theError : Exceptions (*-- in *); theHandler : HandlerProc (*-- in *)); PROCEDURE GetHandler ( theError : Exceptions (*-- in *)) : HandlerProc (*-- out *); (* 10.2.3 Constructors All of the constructor interfaces directly match that given in Chapter 9 on the queue abstraction. The exception is Create which accepts parameters describing the queue's data type and maximum size. *) PROCEDURE Create ( theType : TypeID (*-- in *); theSize : QueueSize (*-- in *)) : Queue (*-- out *); PROCEDURE Destroy (VAR theQueue : Queue (*-- inout *)); PROCEDURE Clear (VAR theQueue : Queue (*-- inout *)); PROCEDURE Assign ( theQueue : Queue (*-- in *); VAR toQueue : Queue (*-- inout *)); PROCEDURE Arrive (VAR theQueue : Queue (*-- inout *); theItem : Item (*-- in *)); PROCEDURE Depart (VAR theQueue : Queue (*-- inout *)); (* 10.2.4 Selectors *) PROCEDURE IsDefined ( theQueue : Queue (*-- in *)) : BOOLEAN (*-- out *); PROCEDURE IsEmpty ( theQueue : Queue (*-- in *)) : BOOLEAN (*-- out *); PROCEDURE IsEqual ( left : Queue (*-- in *); right : Queue (*-- in *)) : BOOLEAN (*-- out *); PROCEDURE LengthOf ( theQueue : Queue (*-- in *)) : CARDINAL (*-- out *); PROCEDURE SizeOf ( theQueue : Queue (*-- in *)) : CARDINAL (*-- out *); PROCEDURE TypeOf ( theQueue : Queue (*-- in *)) : TypeID (*-- out *); PROCEDURE FrontOf ( theQueue : Queue (*-- in *)) : Item (*-- out *); (* 10.2.5 Iterators *) PROCEDURE LoopOver ( theQueue : Queue (*-- in *); theProcess: LoopAccessProc (*-- in *)); PROCEDURE Traverse ( theQueue : Queue (*-- in *); theProcess: AccessProc (*-- in *)); END QSBMI.