-- Item : Generic Contingous List Package Specification -- Reference : Data Structures and Program Design, Pascal, p 198 -- Author : Paul Stachour, stachour@winternet.com -- Version : 1.0, 1999/Jan/28 -- For : ICS340, Winter 199, Metro State, Minnesota -- Style : Ada95, in an ada style, to show type paramaterization -- Protection: Written 1999,This code is available to the public generic Max_Size : Natural := 100; -- Maximum size of the list --type Key_type is (<>);-- Any discrete type with "<" defined. type List_Entry is private;-- A record containing necessary data --with function "<"(Left, Right: Key_Type) return Boolean; package adg_cl is -- This file provides the declaration of a contiguous keyed list package -- with the part common to all types of list entries. -- It requires that type List_Entry and Max_Size be provided when this -- specification is instantaited, and it be "with'ed" as appropriate. -- Sample instantiation: -- subtype Position is Natural range 1..Max_Size; subtype List_Count is Natural range 0..Max_Size; --type CL_Keys is array(position) of Key_Type; type CL_Data is array(position) of List_Entry; -- This would usually be private, but is left public so it meshes -- with other routines from the book which do not enforce privacy. type List is record --Keys: Cl_Keys; Data: Cl_Data; Count: List_Count; end record; type Process_List_Entry is access procedure(LE: in out List_Entry); -- Note that the word "list" has been left in the name of the -- subprograms, thought this is not the usual Ada style. -- The Ada style is without the name of the entity. -- This style with the entity name is necessary in languages that -- do not support name overloading, to prevent name clashes. procedure CreateList(L: in out List); -- Pre: None. -- Post: The list L has been created and is initialized to be empty. procedure ClearList(L: in out List); -- Pre: The list L has been created. -- Post: All entries of the list L have been deleted. function ListEmpty(L: in List) return Boolean; -- Pre: The list L has been created. -- Post: The function returns true if the list L is empty, false otherwise. function ListFull(L: List) return Boolean; -- Pre: The list L has been created. -- Post: The function returns true if the list is full, false otherwise. function ListSize(L: List) return List_Count; -- Pre: The list L has been created. -- Post: The function returns the number of entries in list L. procedure InsertList(P: Position; LE: List_Entry; L: in out List); -- Pre: The list L has been created, L is not full, x is a valid list -- entry, and 1 <= p <= n + 1, where n is the number of entries in -- L. -- Post: x has been inserted into position p in L; the entry formerly in -- position p (provided p <= n) and all later entries have their -- position numbers increased by 1. procedure DeleteList(P: Position; LE: out List_Entry; L: in out List); -- Pre: The list L has been created, L is not empty, -- and 1 <= p <= n, where n is the number of entries in L. -- Post: The entry in position p of L has been returned as x and deleted -- from L; the entries in all later positions (provided -- p < n) have their position numbers decreased by 1. procedure RetrieveList(P: Position; LE: out List_Entry; L: in out list); -- Pre: The list L has been created, L is not empty, -- and 1 <= p <= n, where n is the number of entries in L. -- Post: The entry in position p of L has been returned as x. L remains -- unchanged. procedure ReplaceList(p: position; LE: List_Entry; L: in out List); -- Pre: The list L has been created, L is not empty, x is a valid list -- entry, and 1 <= p <= n, where n is the number of entries in L. -- Post: The entry in position p of L has been replaced by x. The other -- entries of L remain unchanged. procedure TraverseList(L: in out list; Visit: Process_List_Entry); -- Pre: The list L has been created. -- Post: The action specified by the procedure Visit has been -- performed on every entry of the list L, beginning at the first -- entry and doing each in turn. -- Uses: RetrieveList, ReplaceList. end adg_cl;