-- PragmAda Reusable Component (PragmARC) -- Copyright (C) 2021 by PragmAda Software Engineering. All rights reserved. -- Released under the terms of the BSD 3-Clause license; see https://opensource.org/licenses -- ************************************************************************** -- -- General purpose queue for sequential use -- -- History: -- 2021 May 01 J. Carter V2.4--Adhere to coding standard -- 2021 Feb 01 J. Carter V2.3--Added postcondition to Get -- 2021 Jan 01 J. Carter V2.2--Removed limited and Assign -- 2020 Dec 01 J. Carter V2.1--Changed elaboration pragmas to aspects -- 2020 Nov 01 J. Carter V2.0--Initial Ada-12 version ---------------------------------------------------------------------------- -- 2018 Aug 01 J. Carter V1.1--Make Length O(1) -- 2013 Mar 01 J. Carter V1.0--Initial Ada-07 version --------------------------------------------------------------------------------------------------- -- 2002 Oct 01 J. Carter V1.4--Added Context to Iterate; use mode out to allow scalars -- 2002 May 01 J. Carter V1.3--Added Assign -- 2001 Jun 01 J. Carter V1.2--Added Peek -- 2001 May 01 J. Carter V1.1--Improved time complexity of Is_Empty -- 2000 May 01 J. Carter V1.0--Initial release -- pragma Assertion_Policy (Check); pragma Unsuppress (All_Checks); private with Ada.Containers.Doubly_Linked_Lists; generic -- PragmARC.Data_Structures.Queues.Unbounded.Unprotected type Element is private; package PragmARC.Data_Structures.Queues.Unbounded.Unprotected with Preelaborate is type Handle is tagged private; -- Initial value: empty procedure Clear (Queue : in out Handle) with Post => Queue.Is_Empty; -- Makes Queue empty procedure Put (Onto : in out Handle; Item : in Element) with Post => not Onto.Is_Empty; -- raise Storage_Exhausted -- Adds Item to the tail of Onto -- Raises Storage_Exhausted if no more storage is available for Onto -- Nothing is changed if Storage_Exhausted is raised procedure Get (From : in out Handle; Item : out Element) with Pre => not From.Is_Empty or else raise Empty, Post => From.Length = From'Old.Length - 1; -- Removes the Element at the head of From and assigns it to Item function Length (Queue : in Handle) return Natural; -- Returns the number of Elements in Queue function Is_Empty (Queue : in Handle) return Boolean; -- Returns True if Queue is empty; False otherwise function Peek (Queue : in Handle) return Element with Pre => not Queue.Is_Empty or else raise Empty; -- Return the Element at the head of Queue without altering Queue generic -- Iterate with procedure Action (Item : in Element); procedure Iterate (Over : in out Handle); -- Calls Action with each Element in Over in turn, from head to tail private -- PragmARC.Data_Structures.Queues.Unbounded.Unprotected package Implementation is new Ada.Containers.Doubly_Linked_Lists (Element_Type => Element); type Handle is tagged record List : Implementation.List; end record; end PragmARC.Data_Structures.Queues.Unbounded.Unprotected;