1-- Copyright 1994 Grady Booch 2-- Copyright 1998-2014 Simon Wright <simon@pushface.org> 3 4-- This package is free software; you can redistribute it and/or 5-- modify it under terms of the GNU General Public License as 6-- published by the Free Software Foundation; either version 2, or 7-- (at your option) any later version. This package is distributed in 8-- the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9-- even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10-- PARTICULAR PURPOSE. See the GNU General Public License for more 11-- details. You should have received a copy of the GNU General Public 12-- License distributed with this package; see file COPYING. If not, 13-- write to the Free Software Foundation, 59 Temple Place - Suite 14-- 330, Boston, MA 02111-1307, USA. 15 16-- As a special exception, if other files instantiate generics from 17-- this unit, or you link this unit with other files to produce an 18-- executable, this unit does not by itself cause the resulting 19-- executable to be covered by the GNU General Public License. This 20-- exception does not however invalidate any other reasons why the 21-- executable file might be covered by the GNU Public License. 22 23with System.Address_To_Access_Conversions; 24 25package body BC.Containers.Deques.Unbounded is 26 27 procedure Clear (D : in out Deque) is 28 begin 29 Deque_Nodes.Clear (D.Rep); 30 end Clear; 31 32 procedure Append (D : in out Deque; 33 Elem : Item; 34 Location : Deque_End := Back) is 35 begin 36 if Location = Back then 37 Deque_Nodes.Append (D.Rep, Elem); 38 else 39 Deque_Nodes.Insert (D.Rep, Elem); 40 end if; 41 end Append; 42 43 procedure Pop (D : in out Deque; Location : Deque_End := Front) is 44 begin 45 if Location = Front then 46 Deque_Nodes.Remove (D.Rep, 1); 47 else 48 Deque_Nodes.Remove (D.Rep, 49 Deque_Nodes.Length (D.Rep)); 50 end if; 51 end Pop; 52 53 procedure Remove (D : in out Deque; From : Positive) is 54 begin 55 Deque_Nodes.Remove (D.Rep, From); 56 end Remove; 57 58 function Length (D : Deque) return Natural is 59 begin 60 return Deque_Nodes.Length (D.Rep); 61 end Length; 62 63 function Is_Empty (D : Deque) return Boolean is 64 begin 65 return Deque_Nodes.Length (D.Rep) = 0; 66 end Is_Empty; 67 68 function Front (D : Deque) return Item is 69 begin 70 return Deque_Nodes.First (D.Rep); 71 end Front; 72 73 function Back (D : Deque) return Item is 74 begin 75 return Deque_Nodes.Last (D.Rep); 76 end Back; 77 78 function Location (D : Deque; Elem : Item) return Natural is 79 begin 80 return Deque_Nodes.Location (D.Rep, Elem); 81 end Location; 82 83 function "=" (Left, Right : Deque) return Boolean is 84 use Deque_Nodes; 85 begin 86 return Left.Rep = Right.Rep; 87 end "="; 88 89 package Address_Conversions 90 is new System.Address_To_Access_Conversions (Deque); 91 92 function New_Iterator 93 (For_The_Deque : Deque) return Iterator'Class is 94 Result : Deque_Iterator; 95 begin 96 Result.For_The_Container := 97 Container_Ptr (Address_Conversions.To_Pointer (For_The_Deque'Address)); 98 Reset (Result); 99 return Result; 100 end New_Iterator; 101 102 function Item_At (D : Deque; Index : Positive) return Item_Ptr is 103 begin 104 return Deque_Nodes.Item_At (D.Rep, Index); 105 end Item_At; 106 107 function Null_Container return Deque is 108 Empty_Container : Deque; 109 pragma Warnings (Off, Empty_Container); 110 begin 111 return Empty_Container; 112 end Null_Container; 113 114end BC.Containers.Deques.Unbounded; 115