This patch updates the container files for hashed sets and indefinite hashed maps, to include the latest Ada RM version, and support element iterator loops over these containers.
Tested on x86_64-pc-linux-gnu, committed on trunk 2011-12-22 Ed Schonberg <schonb...@adacore.com> * a-cohase.ads, a-cohase.adb: Update to latest RM version. Add aspect Constant_Reference to set type, and corresponding functions. * a-cihama.ads, a-cihama.adb: Update to latest RM version. Add function Reference to provide a proper element iterator construct over indefinite maps.
Index: a-cihama.adb =================================================================== --- a-cihama.adb (revision 182615) +++ a-cihama.adb (working copy) @@ -973,6 +973,15 @@ Container.Find (Key).Node.Element.all'Unrestricted_Access); end Reference; + function Reference + (Container : aliased in out Map; + Position : Cursor) return Reference_Type + is + pragma Unreferenced (Container); + begin + return (Element => Element (Position)'Unrestricted_Access); + end Reference; + ------------- -- Replace -- ------------- Index: a-cihama.ads =================================================================== --- a-cihama.ads (revision 182615) +++ a-cihama.ads (working copy) @@ -293,9 +293,14 @@ Key : Key_Type) -- SHOULD BE ALIASED ??? return Constant_Reference_Type; - function Reference (Container : Map; Key : Key_Type) - return Reference_Type; + function Reference + (Container : Map; + Key : Key_Type) return Reference_Type; + function Reference + (Container : aliased in out Map; + Position : Cursor) return Reference_Type; + procedure Iterate (Container : Map; Process : not null access procedure (Position : Cursor)); Index: a-cohase.adb =================================================================== --- a-cohase.adb (revision 182615) +++ a-cohase.adb (working copy) @@ -1100,6 +1100,14 @@ raise Program_Error with "attempt to stream set cursor"; end Read; + procedure Read + (Stream : not null access Root_Stream_Type'Class; + Item : out Constant_Reference_Type) + is + begin + raise Program_Error with "attempt to stream reference"; + end Read; + --------------- -- Read_Node -- --------------- @@ -1118,6 +1126,19 @@ raise; end Read_Node; + --------------- + -- Reference -- + --------------- + + function Constant_Reference + (Container : aliased Set; + Position : Cursor) return Constant_Reference_Type + is + pragma Unreferenced (Container); + begin + return (Element => Position.Node.Element'Unrestricted_Access); + end Constant_Reference; + ------------- -- Replace -- ------------- @@ -1655,6 +1676,14 @@ raise Program_Error with "attempt to stream set cursor"; end Write; + procedure Write + (Stream : not null access Root_Stream_Type'Class; + Item : Constant_Reference_Type) + is + begin + raise Program_Error with "attempt to stream reference"; + end Write; + ---------------- -- Write_Node -- ---------------- @@ -1923,6 +1952,27 @@ raise Program_Error with "key was modified"; end Update_Element_Preserving_Key; + ------------------------------ + -- Reference_Preserving_Key -- + ------------------------------ + + function Reference_Preserving_Key + (Container : aliased in out Set; + Position : Cursor) return Reference_Type + is + pragma Unreferenced (Container); + begin + return (Element => Position.Node.Element'Unrestricted_Access); + end Reference_Preserving_Key; + + function Reference_Preserving_Key + (Container : aliased in out Set; + Key : Key_Type) return Reference_Type + is + Position : constant Cursor := Find (Container, Key); + begin + return (Element => Position.Node.Element'Unrestricted_Access); + end Reference_Preserving_Key; end Generic_Keys; end Ada.Containers.Hashed_Sets; Index: a-cohase.ads =================================================================== --- a-cohase.ads (revision 182615) +++ a-cohase.ads (working copy) @@ -31,10 +31,10 @@ -- This unit was originally developed by Matthew J Heaney. -- ------------------------------------------------------------------------------ +with Ada.Iterator_Interfaces; private with Ada.Containers.Hash_Tables; private with Ada.Streams; private with Ada.Finalization; -with Ada.Iterator_Interfaces; generic type Element_Type is private; @@ -52,6 +52,7 @@ type Set is tagged private with + constant_Indexing => Constant_Reference, Default_Iterator => Iterate, Iterator_Element => Element_Type; @@ -148,6 +149,14 @@ function Copy (Source : Set; Capacity : Count_Type := 0) return Set; + type Constant_Reference_Type + (Element : not null access constant Element_Type) is private + with Implicit_Dereference => Element; + + function Constant_Reference + (Container : aliased Set; + Position : Cursor) return Constant_Reference_Type; + procedure Move (Target : in out Set; Source : in out Set); -- Clears Target (if it's not empty), and then moves (not copies) the -- buckets array and nodes from Source to Target. @@ -403,13 +412,27 @@ -- Equivalent_Keys to compare the saved key-value to the value returned -- by applying generic formal operation Key to the post-Process value of -- element. If the key values compare equal then the operation - -- completes. Otherwise, the node is removed from the map and + -- completes. Otherwise, the node is removed from the set and -- Program_Error is raised. + type Reference_Type (Element : not null access Element_Type) is private + with Implicit_Dereference => Element; + + function Reference_Preserving_Key + (Container : aliased in out Set; + Position : Cursor) return Reference_Type; + + function Reference_Preserving_Key + (Container : aliased in out Set; + Key : Key_Type) return Reference_Type; + + private + type Reference_Type (Element : not null access Element_Type) + is null record; + end Generic_Keys; private - pragma Inline (Next); type Node_Type; @@ -469,6 +492,21 @@ for Set'Read use Read; + type Constant_Reference_Type + (Element : not null access constant Element_Type) is null record; + + procedure Read + (Stream : not null access Root_Stream_Type'Class; + Item : out Constant_Reference_Type); + + for Constant_Reference_Type'Read use Read; + + procedure Write + (Stream : not null access Root_Stream_Type'Class; + Item : Constant_Reference_Type); + + for Constant_Reference_Type'Write use Write; + Empty_Set : constant Set := (Controlled with HT => (null, 0, 0, 0)); end Ada.Containers.Hashed_Sets;