-- --
-- B o d y --
-- --
--- Copyright (C) 2004-2011, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2012, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
HT_Ops.Adjust (Container.HT);
end Adjust;
+ procedure Adjust (Control : in out Reference_Control_Type) is
+ begin
+ if Control.Container /= null then
+ declare
+ M : Map renames Control.Container.all;
+ HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
+ B : Natural renames HT.Busy;
+ L : Natural renames HT.Lock;
+ begin
+ B := B + 1;
+ L := L + 1;
+ end;
+ end if;
+ end Adjust;
+
------------
-- Assign --
------------
HT_Ops.Clear (Container.HT);
end Clear;
+ ------------------------
+ -- Constant_Reference --
+ ------------------------
+
+ function Constant_Reference
+ (Container : aliased Map;
+ Position : Cursor) return Constant_Reference_Type
+ is
+ begin
+ if Position.Container = null then
+ raise Constraint_Error with
+ "Position cursor has no element";
+ end if;
+
+ if Position.Container /= Container'Unrestricted_Access then
+ raise Program_Error with
+ "Position cursor designates wrong map";
+ end if;
+
+ if Position.Node.Element = null then
+ raise Program_Error with
+ "Position cursor has no element";
+ end if;
+
+ pragma Assert
+ (Vet (Position),
+ "Position cursor in Constant_Reference is bad");
+
+ declare
+ M : Map renames Position.Container.all;
+ HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
+ B : Natural renames HT.Busy;
+ L : Natural renames HT.Lock;
+ begin
+ return R : constant Constant_Reference_Type :=
+ (Element => Position.Node.Element.all'Access,
+ Control =>
+ (Controlled with Container'Unrestricted_Access))
+ do
+ B := B + 1;
+ L := L + 1;
+ end return;
+ end;
+ end Constant_Reference;
+
+ function Constant_Reference
+ (Container : aliased Map;
+ Key : Key_Type) return Constant_Reference_Type
+ is
+ Node : constant Node_Access := Key_Ops.Find (Container.HT, Key);
+
+ begin
+ if Node = null then
+ raise Constraint_Error with "key not in map";
+ end if;
+
+ if Node.Element = null then
+ raise Program_Error with "key has no element";
+ end if;
+
+ declare
+ M : Map renames Container'Unrestricted_Access.all;
+ HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
+ B : Natural renames HT.Busy;
+ L : Natural renames HT.Lock;
+ begin
+ return R : constant Constant_Reference_Type :=
+ (Element => Node.Element.all'Access,
+ Control =>
+ (Controlled with Container'Unrestricted_Access))
+ do
+ B := B + 1;
+ L := L + 1;
+ end return;
+ end;
+ end Constant_Reference;
+
--------------
-- Contains --
--------------
end if;
end Finalize;
+ procedure Finalize (Control : in out Reference_Control_Type) is
+ begin
+ if Control.Container /= null then
+ declare
+ M : Map renames Control.Container.all;
+ HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
+ B : Natural renames HT.Busy;
+ L : Natural renames HT.Lock;
+ begin
+ B := B - 1;
+ L := L - 1;
+ end;
+
+ Control.Container := null;
+ end if;
+ end Finalize;
+
----------
-- Find --
----------
-- Reference --
---------------
- function Constant_Reference
- (Container : Map;
- Key : Key_Type) return Constant_Reference_Type
- is
- begin
- return (Element =>
- Container.Find (Key).Node.Element.all'Unrestricted_Access);
- end Constant_Reference;
-
function Reference
- (Container : Map;
- Key : Key_Type) return Reference_Type
+ (Container : aliased in out Map;
+ Position : Cursor) return Reference_Type
is
begin
- return (Element =>
- Container.Find (Key).Node.Element.all'Unrestricted_Access);
+ if Position.Container = null then
+ raise Constraint_Error with
+ "Position cursor has no element";
+ end if;
+
+ if Position.Container /= Container'Unrestricted_Access then
+ raise Program_Error with
+ "Position cursor designates wrong map";
+ end if;
+
+ if Position.Node.Element = null then
+ raise Program_Error with
+ "Position cursor has no element";
+ end if;
+
+ pragma Assert
+ (Vet (Position),
+ "Position cursor in function Reference is bad");
+
+ declare
+ M : Map renames Position.Container.all;
+ HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
+ B : Natural renames HT.Busy;
+ L : Natural renames HT.Lock;
+ begin
+ return R : constant Reference_Type :=
+ (Element => Position.Node.Element.all'Access,
+ Control => (Controlled with Position.Container))
+ do
+ B := B + 1;
+ L := L + 1;
+ end return;
+ end;
end Reference;
function Reference
(Container : aliased in out Map;
- Position : Cursor) return Reference_Type
+ Key : Key_Type) return Reference_Type
is
- pragma Unreferenced (Container);
+ Node : constant Node_Access := Key_Ops.Find (Container.HT, Key);
+
begin
- return (Element => Element (Position)'Unrestricted_Access);
+ if Node = null then
+ raise Constraint_Error with "key not in map";
+ end if;
+
+ if Node.Element = null then
+ raise Program_Error with "key has no element";
+ end if;
+
+ declare
+ M : Map renames Container'Unrestricted_Access.all;
+ HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
+ B : Natural renames HT.Busy;
+ L : Natural renames HT.Lock;
+ begin
+ return R : constant Reference_Type :=
+ (Element => Node.Element.all'Access,
+ Control =>
+ (Controlled with Container'Unrestricted_Access))
+ do
+ B := B + 1;
+ L := L + 1;
+ end return;
+ end;
end Reference;
-------------