1-- Copyright 1994 Grady Booch 2-- Copyright 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 BC.Support.Unmanaged; 24 25generic 26package BC.Containers.Collections.Unmanaged is 27 28 pragma Preelaborate; 29 30 type Collection is new Abstract_Collection with private; 31 32 function Null_Container return Collection; 33 34 function "=" (Left, Right : in Collection) return Boolean; 35 36 procedure Clear (C : in out Collection); 37 -- Empty the collection of all items. 38 39 procedure Insert (C : in out Collection; Elem : Item); 40 -- Add the item to the front of the collection. 41 42 procedure Insert (C : in out Collection; 43 Elem : Item; 44 Before : Positive); 45 -- Add the item before the given index item in the collection; if 46 -- before is 1, the item is added to the front of the collection. 47 48 procedure Append (C : in out Collection; Elem : Item); 49 -- Add the item at the end of the collection. 50 51 procedure Append (C : in out Collection; 52 Elem : Item; 53 After : Positive); 54 -- Add the item after the given index item in the collection. 55 56 procedure Remove (C : in out Collection; At_Index : Positive); 57 -- Remove the item at the given index in the collection. 58 59 procedure Replace (C : in out Collection; 60 At_Index : Positive; 61 Elem : Item); 62 -- Replace the item at the given index with the given item. 63 64 function Length (C : Collection) return Natural; 65 -- Return the number of items in the collection. 66 67 function Is_Empty (C : Collection) return Boolean; 68 -- Return True if and only if there are no items in the collection. 69 70 function First (C : Collection) return Item; 71 -- Return a copy of the item at the front of the collection. 72 73 function Last (C : Collection) return Item; 74 -- Return a copy of the item at the end of the collection. 75 76 function Item_At 77 (C : Collection; At_Index : Positive) return Item; 78 -- Return a copy of the item at the indicated position in the 79 -- collection. 80 81 function Location (C : Collection; Elem : Item) return Natural; 82 -- Return the first index at which the item is found (0 if the 83 -- item desn't exist in the collecton). 84 85 function New_Iterator 86 (For_The_Collection : Collection) return Iterator'Class; 87 -- Return a reset Iterator bound to the specific Collection. 88 89private 90 91 function Item_At (C : Collection; Index : Positive) return Item_Ptr; 92 93 package Collection_Nodes 94 is new BC.Support.Unmanaged (Item => Item, 95 Item_Ptr => Item_Ptr); 96 97 type Collection is new Abstract_Collection with record 98 Rep : Collection_Nodes.Unm_Node; 99 end record; 100 101end BC.Containers.Collections.Unmanaged; 102