Introducing Queue_Template

from Team 4 Enterprises

Team Four's Queue_Template is an Ada 95 generic queue package which implements various queue types and procedures, including:

A generic queue type (Queue_Type)

A procedure to create and add nodes to a FIFO queue (Enqueue)
A procedure to create and add nodes to a priority queue (Priority_Enqueue)
A procedure to extract an item from a queue (Dequeue)
A procedure to change the maximum number of items the queue may contain (Resize)

A function to indicate the number of items in the queue (Items_In)
A function to indicate the maximum number of items the queue may contain (Size_Of)
A function to indicate a queue is full (Is_Full)
A function to indicate a queue is empty (Is_Empty)

An exception indicating that the queue is empty (Empty_Queue_Error)
An exception indicating that the queue is full (Full_Queue_Error)
An exception occurring if a queue is resized below its current size (Resize_Queue_Error)

To employ this package, the user must take the following actions:
"With" the package
Make it a procedure or set it up for use:
"New" the package
Indicate the type of parameters
"Use" the "newed" generic

Example of these actions are demonstrated below.

"With" the package

with Queue_Template;

Make it a procedure or set it up for use:

procedure IQ_Dvr is

"New" the package and indicate the type of parameters

package integer_Queue is new Queue_Template( Component_Type => integer);

"Use" the "newed" generic

use integer_Queue;

The non-private part of the specification is reproduced below.

generic
type Component_Type is private;

package Queue_Template is

type Queue_Type is limited private;
type Priority_Type is range 1 .. 10;

Empty_Queue_Error  : exception;
Full_Queue_Error   : exception;
Resize_Queue_Error : exception;

function Size_Of  (Queue : Queue_Type) return Integer;
function Items_In (Queue : Queue_Type) return Integer;
function Is_Full  (Queue : Queue_Type) return Boolean;
function Is_Empty (Queue : Queue_Type) return Boolean;

procedure Resize  (Queue    : in out Queue_Type;
                   New_Size : in     Integer);

procedure Enqueue (Item     : in     Component_Type;
                   Queue    : in out Queue_Type);

procedure Dequeue (Item     : out    Component_Type;
                   Queue    : in out Queue_Type);

procedure Priority_Enqueue
                  (Item_Value    : in     Component_Type;
                   Item_Priority : in     Priority_Type;
                   Queue         : in out Queue_Type);

If you wish to test the our package, the following files are available:

Generic Queue Template GenericQ.ada
Integer Priority Queue Demonstration IntQ.ada
Message (string) Priority Queue Demonstration StrQ.ada


Queue_Template was developed by:

Mark A. Crouch
Daniel R. Harris
Robert Kemper
Robert J. Waldt