summaryrefslogtreecommitdiff
path: root/gcc/ada/a-cbhama.ads
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-29 14:19:32 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-29 14:19:32 +0000
commit2a2129b6f630c9b313f8d3e5055f13eedf0f3077 (patch)
treeb5fe93abb86053d3a44b4175d1842263cdd40c03 /gcc/ada/a-cbhama.ads
parent00447a62af3e0d56871c88c7921bd70399ede3a8 (diff)
downloadgcc-2a2129b6f630c9b313f8d3e5055f13eedf0f3077.tar.gz
2011-08-29 Ed Schonberg <schonberg@adacore.com>
* a-cbhama.adb, a-cbhama.ads, a-cborma.adb, a-cborma.ads, a-cobove.adb, a-cobove.ads, a-coorma.adb, a-coorma.ads: Add iterator machinery to container packages. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@178242 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-cbhama.ads')
-rw-r--r--gcc/ada/a-cbhama.ads73
1 files changed, 66 insertions, 7 deletions
diff --git a/gcc/ada/a-cbhama.ads b/gcc/ada/a-cbhama.ads
index 0102e0221b1..94860f99cc0 100644
--- a/gcc/ada/a-cbhama.ads
+++ b/gcc/ada/a-cbhama.ads
@@ -32,7 +32,8 @@
------------------------------------------------------------------------------
private with Ada.Containers.Hash_Tables;
-private with Ada.Streams;
+with Ada.Streams; use Ada.Streams;
+with Ada.Iterator_Interfaces;
generic
type Key_Type is private;
@@ -46,7 +47,13 @@ package Ada.Containers.Bounded_Hashed_Maps is
pragma Pure;
pragma Remote_Types;
- type Map (Capacity : Count_Type; Modulus : Hash_Type) is tagged private;
+ type Map (Capacity : Count_Type; Modulus : Hash_Type) is tagged private
+ with
+ Constant_Indexing => Constant_Reference,
+ Variable_Indexing => Reference,
+ Default_Iterator => Iterate,
+ Iterator_Element => Element_Type;
+
pragma Preelaborable_Initialization (Map);
type Cursor is private;
@@ -60,6 +67,12 @@ package Ada.Containers.Bounded_Hashed_Maps is
-- Cursor objects declared without an initialization expression are
-- initialized to the value No_Element.
+ function Has_Element (Position : Cursor) return Boolean;
+ -- Equivalent to Position /= No_Element
+
+ package Map_Iterator_Interfaces is new
+ Ada.Iterator_Interfaces (Cursor, Has_Element);
+
function "=" (Left, Right : Map) return Boolean;
-- For each key/element pair in Left, equality attempts to find the key in
-- Right; if a search fails the equality returns False. The search works by
@@ -253,9 +266,6 @@ package Ada.Containers.Bounded_Hashed_Maps is
function Element (Container : Map; Key : Key_Type) return Element_Type;
-- Equivalent to Element (Find (Container, Key))
- function Has_Element (Position : Cursor) return Boolean;
- -- Equivalent to Position /= No_Element
-
function Equivalent_Keys (Left, Right : Cursor) return Boolean;
-- Returns the result of calling Equivalent_Keys with the keys of the nodes
-- designated by cursors Left and Right.
@@ -273,6 +283,50 @@ package Ada.Containers.Bounded_Hashed_Maps is
Process : not null access procedure (Position : Cursor));
-- Calls Process for each node in the map
+ function Iterate (Container : Map)
+ return Map_Iterator_Interfaces.Forward_Iterator'class;
+
+ type Constant_Reference_Type
+ (Element : not null access constant Element_Type) is
+ private
+ with
+ Implicit_Dereference => Element;
+
+ procedure Write
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : Constant_Reference_Type);
+
+ for Constant_Reference_Type'Write use Write;
+
+ procedure Read
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : out Constant_Reference_Type);
+
+ for Constant_Reference_Type'Read use Read;
+
+ type Reference_Type (Element : not null access Element_Type) is private
+ with
+ Implicit_Dereference => Element;
+
+ procedure Write
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : Reference_Type);
+
+ for Reference_Type'Write use Write;
+
+ procedure Read
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : out Reference_Type);
+
+ for Reference_Type'Read use Read;
+
+ function Constant_Reference
+ (Container : Map; Key : Key_Type) -- SHOULD BE ALIASED
+ return Constant_Reference_Type;
+
+ function Reference (Container : Map; Key : Key_Type)
+ return Reference_Type;
+
private
-- pragma Inline ("=");
pragma Inline (Length);
@@ -285,7 +339,7 @@ private
pragma Inline (Capacity);
pragma Inline (Reserve_Capacity);
pragma Inline (Has_Element);
- pragma Inline (Equivalent_Keys);
+ -- pragma Inline (Equivalent_Keys);
pragma Inline (Next);
type Node_Type is record
@@ -301,7 +355,6 @@ private
new HT_Types.Hash_Table_Type (Capacity, Modulus) with null record;
use HT_Types;
- use Ada.Streams;
procedure Write
(Stream : not null access Root_Stream_Type'Class;
@@ -335,6 +388,12 @@ private
for Cursor'Write use Write;
+ type Constant_Reference_Type
+ (Element : not null access constant Element_Type) is null record;
+
+ type Reference_Type
+ (Element : not null access Element_Type) is null record;
+
No_Element : constant Cursor := (Container => null, Node => 0);
Empty_Map : constant Map :=