language-Modula2-0.1: examples/Modula-2_Libraries/C.-Lins_Modula-2_Software_Component_Library/Vol2/QUEUES/QPBSBMI.DEF
DEFINITION MODULE QPBSBMI;
(*===========================================================
Version : 1.00 18 May 1989 C. Lins
Compiler : TopSpeed Modula-2
Component: Monolithic Structures - Queue (Opaque version)
Priority 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 Relations IMPORT
(*--Type*) Relation;
FROM TypeManager IMPORT
(*--Type*) TypeID;
(*--------------------*)
(*
12.1.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.
An item's priority is declared as a generic entity, allowing the client
module to have priorities of any complexity. All that is needed for
the priority form of queue is the ability to retrieve an item's priority
and to compare priorities for the relational ordering between them.
*)
TYPE Queue;
TYPE QueueSize = [1..8100];
CONST NullQueue = Queue(NIL);
TYPE Priority;
TYPE PriorityProc = PROCEDURE (Item) : Priority;
TYPE PriorityCompare = PROCEDURE (Priority, Priority) : Relation;
(*
12.1.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 = 5;
PROCEDURE QueueError () : Exceptions (*-- out *);
PROCEDURE SetHandler ( theError : Exceptions (*-- in *);
theHandler : HandlerProc (*-- in *));
PROCEDURE GetHandler ( theError : Exceptions (*-- in *))
: HandlerProc (*-- out *);
(*
12.1.3 Constructors
The constructor Create has been changed from the non-priority
non-balking form of queue to accomodate procedure parameters to (1)
retrieve the priority for an item, and (2) compare two priorities.
An additional constructor, Leave, has been added to implement the
actual balking mechanism.
All other constructors remain unchanged from the non-priority
non-balking form of queue.
*)
PROCEDURE Create ( theType : TypeID (*-- in *);
theSize : QueueSize (*-- in *);
priorityOf : PriorityProc (*-- in *);
comparison : PriorityCompare (*-- 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 *));
PROCEDURE Leave (VAR theQueue : Queue (*-- inout *);
theItem : Item (*-- in *));
(*
12.1.4 Selectors
All of the selector interfaces are unchanged from the non-priority
non-balking form of queue.
An additional selector has been added, PositionOf, that returns the
number of positions from the given item to the front of the queue. If
theItem is not present in theQueue then zero is returned.
*)
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 *);
PROCEDURE PositionOf ( theQueue: Queue (*-- in *);
theItem : Item (*-- in *))
: CARDINAL (*-- out *);
(*
12.1.5 Iterators
The interfaces to both iterators are unchanged from the non-priority
non-balking form of queue.
*)
PROCEDURE LoopOver ( theQueue : Queue (*-- in *);
theProcess: LoopAccessProc (*-- in *));
PROCEDURE Traverse ( theQueue : Queue (*-- in *);
theProcess: AccessProc (*-- in *));
END QPBSBMI.