1-- Copyright 1994 Grady Booch 2-- Copyright 2003-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.Maps.Unmanaged is 26 27 function "=" (L, R : Unconstrained_Map) return Boolean is 28 begin 29 return Tables."=" (L.Rep, R.Rep); 30 end "="; 31 32 procedure Clear (M : in out Unconstrained_Map) is 33 begin 34 Tables.Clear (M.Rep); 35 end Clear; 36 37 procedure Bind 38 (M : in out Unconstrained_Map; K : Key; I : Item) is 39 begin 40 Tables.Bind (M.Rep, K, I); 41 end Bind; 42 43 procedure Rebind 44 (M : in out Unconstrained_Map; K : Key; I : Item) is 45 begin 46 Tables.Rebind (M.Rep, K, I); 47 end Rebind; 48 49 procedure Unbind (M : in out Unconstrained_Map; K : Key) is 50 begin 51 Tables.Unbind (M.Rep, K); 52 end Unbind; 53 54 function Extent (M : Unconstrained_Map) return Natural is 55 begin 56 return Tables.Extent (M.Rep); 57 end Extent; 58 59 function Is_Empty (M : Unconstrained_Map) return Boolean is 60 begin 61 return Tables.Extent (M.Rep) = 0; 62 end Is_Empty; 63 64 function Is_Bound (M : Unconstrained_Map; K : Key) return Boolean is 65 begin 66 return Tables.Is_Bound (M.Rep, K); 67 end Is_Bound; 68 69 function Item_Of (M : Unconstrained_Map; K : Key) return Item is 70 begin 71 return Tables.Value_Of (M.Rep, K); 72 end Item_Of; 73 74 package Address_Conversions 75 is new System.Address_To_Access_Conversions (Unconstrained_Map); 76 77 function New_Iterator 78 (For_The_Map : Unconstrained_Map) return Iterator'Class is 79 Result : Unmanaged_Map_Iterator; 80 begin 81 Result.For_The_Container := 82 Container_Ptr (Address_Conversions.To_Pointer (For_The_Map'Address)); 83 Reset (Result); 84 return Result; 85 end New_Iterator; 86 87 -- Null containers 88 89 function Null_Container return Unconstrained_Map is 90 Empty_Container : Map; 91 pragma Warnings (Off, Empty_Container); 92 begin 93 return Empty_Container; 94 end Null_Container; 95 96 -- Iterators 97 98 procedure Reset (It : in out Unmanaged_Map_Iterator) is 99 S : Unconstrained_Map'Class 100 renames Unconstrained_Map'Class (It.For_The_Container.all); 101 begin 102 Tables.Reset (S.Rep, It.Bucket_Index, It.Index); 103 end Reset; 104 105 procedure Next (It : in out Unmanaged_Map_Iterator) is 106 S : Unconstrained_Map'Class 107 renames Unconstrained_Map'Class (It.For_The_Container.all); 108 begin 109 Tables.Next (S.Rep, It.Bucket_Index, It.Index); 110 end Next; 111 112 function Is_Done (It : Unmanaged_Map_Iterator) return Boolean is 113 S : Unconstrained_Map'Class 114 renames Unconstrained_Map'Class (It.For_The_Container.all); 115 begin 116 return Tables.Is_Done (S.Rep, It.Bucket_Index, It.Index); 117 end Is_Done; 118 119 function Current_Key (It : Unmanaged_Map_Iterator) return Key is 120 S : Unconstrained_Map'Class 121 renames Unconstrained_Map'Class (It.For_The_Container.all); 122 begin 123 return Tables.Current_Item_Ptr (S.Rep, It.Bucket_Index, It.Index).all; 124 end Current_Key; 125 126 function Current_Item (It : Unmanaged_Map_Iterator) return Item is 127 S : Unconstrained_Map'Class 128 renames Unconstrained_Map'Class (It.For_The_Container.all); 129 begin 130 return Tables.Current_Value_Ptr (S.Rep, It.Bucket_Index, It.Index).all; 131 end Current_Item; 132 133 function Current_Item_Ptr (It : Unmanaged_Map_Iterator) return Item_Ptr is 134 S : Unconstrained_Map'Class 135 renames Unconstrained_Map'Class (It.For_The_Container.all); 136 begin 137 return Tables.Current_Value_Ptr (S.Rep, It.Bucket_Index, It.Index); 138 end Current_Item_Ptr; 139 140 procedure Delete_Item_At (It : in out Unmanaged_Map_Iterator) is 141 S : Unconstrained_Map'Class 142 renames Unconstrained_Map'Class (It.For_The_Container.all); 143 begin 144 Tables.Delete_Item_At (S.Rep, It.Bucket_Index, It.Index); 145 end Delete_Item_At; 146 147end BC.Containers.Maps.Unmanaged; 148