* [Ada] Add new Assign and Copy operations to unbounded containers
@ 2011-11-04 10:25 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2011-11-04 10:25 UTC (permalink / raw)
To: gcc-patches; +Cc: Matthew Heaney
[-- Attachment #1: Type: text/plain, Size: 788 bytes --]
The new operations Assign and Copy have been added to the (already-existing)
unbounded containers, to achieve parity with the same operations in the newer
bounded forms, described in AI05-0001. This facilitates changing one container
form to the other during program maintenance.
The text of AI05-0001.txt can be found here:
http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0001-1.txt
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-11-04 Matthew Heaney <heaney@adacore.com>
* a-cdlili.ad[sb], a-cidlli.ad[sb], a-coorse.ad[sb], a-ciorse.ad[sb],
a-coorma.ad[sb], a-ciorma.ad[sb], a-coormu.ad[sb], a-ciormu.ad[sb],
a-cohama.ad[sb], a-cihama.ad[sb], a-cohase.ad[sb], a-cihase.ad[sb],
a-convec.ad[sb], a-coinve.ad[sb] (Assign, Copy): New operations
added to package.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 31555 bytes --]
Index: a-cdlili.adb
===================================================================
--- a-cdlili.adb (revision 180929)
+++ a-cdlili.adb (working copy)
@@ -146,6 +146,27 @@
Insert (Container, No_Element, New_Item, Count);
end Append;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out List; Source : List) is
+ Node : Node_Access;
+
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+
+ Node := Source.First;
+ while Node /= null loop
+ Target.Append (Node.Element);
+ Node := Node.Next;
+ end loop;
+ end Assign;
+
-----------
-- Clear --
-----------
@@ -206,6 +227,17 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : List) return List is
+ begin
+ return Target : List do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
------------
-- Delete --
------------
Index: a-cdlili.ads
===================================================================
--- a-cdlili.ads (revision 180929)
+++ a-cdlili.ads (working copy)
@@ -90,6 +90,10 @@
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type));
+ procedure Assign (Target : in out List; Source : List);
+
+ function Copy (Source : List) return List;
+
procedure Move
(Target : in out List;
Source : in out List);
Index: a-cihama.adb
===================================================================
--- a-cihama.adb (revision 180929)
+++ a-cihama.adb (working copy)
@@ -35,6 +35,8 @@
with Ada.Unchecked_Deallocation;
+with System; use type System.Address;
+
package body Ada.Containers.Indefinite_Hashed_Maps is
procedure Free_Key is
@@ -132,6 +134,41 @@
HT_Ops.Adjust (Container.HT);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Map; Source : Map) is
+ procedure Insert_Item (Node : Node_Access);
+ pragma Inline (Insert_Item);
+
+ procedure Insert_Items is new HT_Ops.Generic_Iteration (Insert_Item);
+
+ -----------------
+ -- Insert_Item --
+ -----------------
+
+ procedure Insert_Item (Node : Node_Access) is
+ begin
+ Target.Insert (Key => Node.Key.all, New_Item => Node.Element.all);
+ end Insert_Item;
+
+ -- Start of processing for Assign
+
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+
+ if Target.Capacity < Source.Length then
+ Target.Reserve_Capacity (Source.Length);
+ end if;
+
+ Insert_Items (Target.HT);
+ end Assign;
+
--------------
-- Capacity --
--------------
@@ -159,6 +196,34 @@
return Find (Container, Key) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy
+ (Source : Map;
+ Capacity : Count_Type := 0) return Map
+ is
+ C : Count_Type;
+
+ begin
+ if Capacity = 0 then
+ C := Source.Length;
+
+ elsif Capacity >= Source.Length then
+ C := Capacity;
+
+ else
+ raise Capacity_Error
+ with "Requested capacity is less than Source length";
+ end if;
+
+ return Target : Map do
+ Target.Reserve_Capacity (C);
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-cihama.ads
===================================================================
--- a-cihama.ads (revision 180929)
+++ a-cihama.ads (working copy)
@@ -134,6 +134,10 @@
-- Calls Process with the key (with only a constant view) and element (with
-- a variable view) of the node designed by the cursor.
+ procedure Assign (Target : in out Map; Source : Map);
+
+ function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
+
procedure Move (Target : in out Map; Source : in out Map);
-- Clears Target (if it's not empty), and then moves (not copies) the
-- buckets array and nodes from Source to Target.
Index: a-coinve.adb
===================================================================
--- a-coinve.adb (revision 180929)
+++ a-coinve.adb (working copy)
@@ -616,6 +616,20 @@
Count);
end Append;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Vector; Source : Vector) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Append (Source);
+ end Assign;
+
--------------
-- Capacity --
--------------
@@ -698,6 +712,34 @@
return Find_Index (Container, Item) /= No_Index;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy
+ (Source : Vector;
+ Capacity : Count_Type := 0) return Vector
+ is
+ C : Count_Type;
+
+ begin
+ if Capacity = 0 then
+ C := Source.Length;
+
+ elsif Capacity >= Source.Length then
+ C := Capacity;
+
+ else
+ raise Capacity_Error
+ with "Requested capacity is less than Source length";
+ end if;
+
+ return Target : Vector do
+ Target.Reserve_Capacity (C);
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
------------
-- Delete --
------------
Index: a-coinve.ads
===================================================================
--- a-coinve.ads (revision 180929)
+++ a-coinve.ads (working copy)
@@ -204,6 +204,10 @@
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type));
+ procedure Assign (Target : in out Vector; Source : Vector);
+
+ function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
+
procedure Move (Target : in out Vector; Source : in out Vector);
procedure Insert
Index: a-ciorse.adb
===================================================================
--- a-ciorse.adb (revision 180929)
+++ a-ciorse.adb (working copy)
@@ -38,6 +38,8 @@
with Ada.Unchecked_Deallocation;
+with System; use type System.Address;
+
package body Ada.Containers.Indefinite_Ordered_Sets is
type Iterator is new
@@ -321,6 +323,20 @@
Adjust (Container.Tree);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Set; Source : Set) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Union (Source);
+ end Assign;
+
-------------
-- Ceiling --
-------------
@@ -363,6 +379,17 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : Set) return Set is
+ begin
+ return Target : Set do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-ciorse.ads
===================================================================
--- a-ciorse.ads (revision 180929)
+++ a-ciorse.ads (working copy)
@@ -111,6 +111,10 @@
(Position : Cursor;
Process : not null access procedure (Element : Element_Type));
+ procedure Assign (Target : in out Set; Source : Set);
+
+ function Copy (Source : Set) return Set;
+
procedure Move (Target : in out Set; Source : in out Set);
procedure Insert
Index: a-coorma.adb
===================================================================
--- a-coorma.adb (revision 180929)
+++ a-coorma.adb (working copy)
@@ -35,6 +35,8 @@
with Ada.Containers.Red_Black_Trees.Generic_Keys;
pragma Elaborate_All (Ada.Containers.Red_Black_Trees.Generic_Keys);
+with System; use type System.Address;
+
package body Ada.Containers.Ordered_Maps is
type Iterator is new
@@ -248,6 +250,37 @@
Adjust (Container.Tree);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Map; Source : Map) is
+ procedure Insert_Item (Node : Node_Access);
+ pragma Inline (Insert_Item);
+
+ procedure Insert_Items is
+ new Tree_Operations.Generic_Iteration (Insert_Item);
+
+ -----------------
+ -- Insert_Item --
+ -----------------
+
+ procedure Insert_Item (Node : Node_Access) is
+ begin
+ Target.Insert (Key => Node.Key, New_Item => Node.Element);
+ end Insert_Item;
+
+ -- Start of processing for Assign
+
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Insert_Items (Target.Tree);
+ end Assign;
+
-------------
-- Ceiling --
-------------
@@ -304,6 +337,17 @@
return Find (Container, Key) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : Map) return Map is
+ begin
+ return Target : Map do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-coorma.ads
===================================================================
--- a-coorma.ads (revision 180929)
+++ a-coorma.ads (working copy)
@@ -96,6 +96,10 @@
Process : not null access
procedure (Key : Key_Type; Element : in out Element_Type));
+ procedure Assign (Target : in out Map; Source : Map);
+
+ function Copy (Source : Map) return Map;
+
procedure Move (Target : in out Map; Source : in out Map);
procedure Insert
Index: a-cidlli.adb
===================================================================
--- a-cidlli.adb (revision 180929)
+++ a-cidlli.adb (working copy)
@@ -171,6 +171,27 @@
Insert (Container, No_Element, New_Item, Count);
end Append;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out List; Source : List) is
+ Node : Node_Access;
+
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+
+ Node := Source.First;
+ while Node /= null loop
+ Target.Append (Node.Element.all);
+ Node := Node.Next;
+ end loop;
+ end Assign;
+
-----------
-- Clear --
-----------
@@ -230,6 +251,17 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : List) return List is
+ begin
+ return Target : List do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
------------
-- Delete --
------------
Index: a-cidlli.ads
===================================================================
--- a-cidlli.ads (revision 180929)
+++ a-cidlli.ads (working copy)
@@ -90,6 +90,10 @@
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type));
+ procedure Assign (Target : in out List; Source : List);
+
+ function Copy (Source : List) return List;
+
procedure Move
(Target : in out List;
Source : in out List);
Index: a-ciormu.adb
===================================================================
--- a-ciormu.adb (revision 180929)
+++ a-ciormu.adb (working copy)
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, 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- --
@@ -38,6 +38,8 @@
with Ada.Containers.Red_Black_Trees.Generic_Set_Operations;
pragma Elaborate_All (Ada.Containers.Red_Black_Trees.Generic_Set_Operations);
+with System; use type System.Address;
+
package body Ada.Containers.Indefinite_Ordered_Multisets is
-----------------------------
@@ -298,6 +300,20 @@
Adjust (Container.Tree);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Set; Source : Set) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Union (Source);
+ end Assign;
+
-------------
-- Ceiling --
-------------
@@ -344,6 +360,17 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : Set) return Set is
+ begin
+ return Target : Set do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-ciormu.ads
===================================================================
--- a-ciormu.ads (revision 180929)
+++ a-ciormu.ads (working copy)
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, 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- --
@@ -118,6 +118,10 @@
-- change the value of the element while Process is executing (to "tamper
-- with elements") will raise Program_Error.
+ procedure Assign (Target : in out Set; Source : Set);
+
+ function Copy (Source : Set) return Set;
+
procedure Move (Target : in out Set; Source : in out Set);
-- If Target denotes the same object as Source, the operation does
-- nothing. If either Target or Source is busy (cursor tampering is
Index: a-cihase.adb
===================================================================
--- a-cihase.adb (revision 180929)
+++ a-cihase.adb (working copy)
@@ -173,6 +173,16 @@
Free_Element (X);
end Assign;
+ procedure Assign (Target : in out Set; Source : Set) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Union (Source);
+ end Assign;
+
--------------
-- Capacity --
--------------
@@ -200,6 +210,34 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy
+ (Source : Set;
+ Capacity : Count_Type := 0) return Set
+ is
+ C : Count_Type;
+
+ begin
+ if Capacity = 0 then
+ C := Source.Length;
+
+ elsif Capacity >= Source.Length then
+ C := Capacity;
+
+ else
+ raise Capacity_Error
+ with "Requested capacity is less than Source length";
+ end if;
+
+ return Target : Set do
+ Target.Reserve_Capacity (C);
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-cihase.ads
===================================================================
--- a-cihase.ads (revision 180929)
+++ a-cihase.ads (working copy)
@@ -153,6 +153,10 @@
Position : Cursor)
return Constant_Reference_Type;
+ procedure Assign (Target : in out Set; Source : Set);
+
+ function Copy (Source : Set; Capacity : Count_Type := 0) return Set;
+
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.
Index: a-cohama.adb
===================================================================
--- a-cohama.adb (revision 180929)
+++ a-cohama.adb (working copy)
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, 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- --
@@ -35,6 +35,8 @@
with Ada.Containers.Hash_Tables.Generic_Keys;
pragma Elaborate_All (Ada.Containers.Hash_Tables.Generic_Keys);
+with System; use type System.Address;
+
package body Ada.Containers.Hashed_Maps is
type Iterator is new
@@ -131,6 +133,41 @@
HT_Ops.Adjust (Container.HT);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Map; Source : Map) is
+ procedure Insert_Item (Node : Node_Access);
+ pragma Inline (Insert_Item);
+
+ procedure Insert_Items is new HT_Ops.Generic_Iteration (Insert_Item);
+
+ -----------------
+ -- Insert_Item --
+ -----------------
+
+ procedure Insert_Item (Node : Node_Access) is
+ begin
+ Target.Insert (Key => Node.Key, New_Item => Node.Element);
+ end Insert_Item;
+
+ -- Start of processing for Assign
+
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+
+ if Target.Capacity < Source.Length then
+ Target.Reserve_Capacity (Source.Length);
+ end if;
+
+ Insert_Items (Target.HT);
+ end Assign;
+
--------------
-- Capacity --
--------------
@@ -158,6 +195,34 @@
return Find (Container, Key) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy
+ (Source : Map;
+ Capacity : Count_Type := 0) return Map
+ is
+ C : Count_Type;
+
+ begin
+ if Capacity = 0 then
+ C := Source.Length;
+
+ elsif Capacity >= Source.Length then
+ C := Capacity;
+
+ else
+ raise Capacity_Error
+ with "Requested capacity is less than Source length";
+ end if;
+
+ return Target : Map do
+ Target.Reserve_Capacity (C);
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-cohama.ads
===================================================================
--- a-cohama.ads (revision 180929)
+++ a-cohama.ads (working copy)
@@ -148,6 +148,10 @@
-- Calls Process with the key (with only a constant view) and element (with
-- a variable view) of the node designed by the cursor.
+ procedure Assign (Target : in out Map; Source : Map);
+
+ function Copy (Source : Map; Capacity : Count_Type := 0) return Map;
+
procedure Move (Target : in out Map; Source : in out Map);
-- Clears Target (if it's not empty), and then moves (not copies) the
-- buckets array and nodes from Source to Target.
Index: a-coorse.adb
===================================================================
--- a-coorse.adb (revision 180929)
+++ a-coorse.adb (working copy)
@@ -38,6 +38,8 @@
with Ada.Containers.Red_Black_Trees.Generic_Set_Operations;
pragma Elaborate_All (Ada.Containers.Red_Black_Trees.Generic_Set_Operations);
+with System; use type System.Address;
+
package body Ada.Containers.Ordered_Sets is
type Iterator is new
@@ -281,6 +283,20 @@
Adjust (Container.Tree);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Set; Source : Set) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Union (Source);
+ end Assign;
+
-------------
-- Ceiling --
-------------
@@ -325,6 +341,17 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : Set) return Set is
+ begin
+ return Target : Set do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-coorse.ads
===================================================================
--- a-coorse.ads (revision 180929)
+++ a-coorse.ads (working copy)
@@ -113,6 +113,10 @@
(Position : Cursor;
Process : not null access procedure (Element : Element_Type));
+ procedure Assign (Target : in out Set; Source : Set);
+
+ function Copy (Source : Set) return Set;
+
procedure Move (Target : in out Set; Source : in out Set);
procedure Insert
Index: a-ciorma.adb
===================================================================
--- a-ciorma.adb (revision 180929)
+++ a-ciorma.adb (working copy)
@@ -35,6 +35,8 @@
with Ada.Containers.Red_Black_Trees.Generic_Keys;
pragma Elaborate_All (Ada.Containers.Red_Black_Trees.Generic_Keys);
+with System; use type System.Address;
+
package body Ada.Containers.Indefinite_Ordered_Maps is
pragma Suppress (All_Checks);
@@ -287,6 +289,37 @@
Adjust (Container.Tree);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Map; Source : Map) is
+ procedure Insert_Item (Node : Node_Access);
+ pragma Inline (Insert_Item);
+
+ procedure Insert_Items is
+ new Tree_Operations.Generic_Iteration (Insert_Item);
+
+ -----------------
+ -- Insert_Item --
+ -----------------
+
+ procedure Insert_Item (Node : Node_Access) is
+ begin
+ Target.Insert (Key => Node.Key.all, New_Item => Node.Element.all);
+ end Insert_Item;
+
+ -- Start of processing for Assign
+
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Insert_Items (Target.Tree);
+ end Assign;
+
-------------
-- Ceiling --
-------------
@@ -340,6 +373,17 @@
return Find (Container, Key) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : Map) return Map is
+ begin
+ return Target : Map do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-ciorma.ads
===================================================================
--- a-ciorma.ads (revision 180929)
+++ a-ciorma.ads (working copy)
@@ -96,6 +96,10 @@
Process : not null access procedure (Key : Key_Type;
Element : in out Element_Type));
+ procedure Assign (Target : in out Map; Source : Map);
+
+ function Copy (Source : Map) return Map;
+
procedure Move (Target : in out Map; Source : in out Map);
procedure Insert
Index: a-coormu.adb
===================================================================
--- a-coormu.adb (revision 180929)
+++ a-coormu.adb (working copy)
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, 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- --
@@ -38,6 +38,8 @@
with Ada.Containers.Red_Black_Trees.Generic_Set_Operations;
pragma Elaborate_All (Ada.Containers.Red_Black_Trees.Generic_Set_Operations);
+with System; use type System.Address;
+
package body Ada.Containers.Ordered_Multisets is
-----------------------------
@@ -266,6 +268,20 @@
Adjust (Container.Tree);
end Adjust;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Set; Source : Set) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Union (Source);
+ end Assign;
+
-------------
-- Ceiling --
-------------
@@ -312,6 +328,17 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy (Source : Set) return Set is
+ begin
+ return Target : Set do
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-convec.adb
===================================================================
--- a-convec.adb (revision 180929)
+++ a-convec.adb (working copy)
@@ -432,6 +432,20 @@
Count);
end Append;
+ ------------
+ -- Assign --
+ ------------
+
+ procedure Assign (Target : in out Vector; Source : Vector) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Append (Source);
+ end Assign;
+
--------------
-- Capacity --
--------------
@@ -471,6 +485,34 @@
return Find_Index (Container, Item) /= No_Index;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy
+ (Source : Vector;
+ Capacity : Count_Type := 0) return Vector
+ is
+ C : Count_Type;
+
+ begin
+ if Capacity = 0 then
+ C := Source.Length;
+
+ elsif Capacity >= Source.Length then
+ C := Capacity;
+
+ else
+ raise Capacity_Error
+ with "Requested capacity is less than Source length";
+ end if;
+
+ return Target : Vector do
+ Target.Reserve_Capacity (C);
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
------------
-- Delete --
------------
Index: a-coormu.ads
===================================================================
--- a-coormu.ads (revision 180929)
+++ a-coormu.ads (working copy)
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, 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- --
@@ -117,6 +117,10 @@
-- change the value of the element while Process is executing (to "tamper
-- with elements") will raise Program_Error.
+ procedure Assign (Target : in out Set; Source : Set);
+
+ function Copy (Source : Set) return Set;
+
procedure Move (Target : in out Set; Source : in out Set);
-- If Target denotes the same object as Source, the operation does
-- nothing. If either Target or Source is busy (cursor tampering is
Index: a-convec.ads
===================================================================
--- a-convec.ads (revision 180929)
+++ a-convec.ads (working copy)
@@ -202,7 +202,12 @@
function Reference (Container : Vector; Position : Index_Type)
return Reference_Type;
+ procedure Assign (Target : in out Vector; Source : Vector);
+
+ function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
+
procedure Move (Target : in out Vector; Source : in out Vector);
+
procedure Insert
(Container : in out Vector;
Before : Extended_Index;
Index: a-cohase.adb
===================================================================
--- a-cohase.adb (revision 180929)
+++ a-cohase.adb (working copy)
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, 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- --
@@ -159,6 +159,16 @@
Node.Element := Item;
end Assign;
+ procedure Assign (Target : in out Set; Source : Set) is
+ begin
+ if Target'Address = Source'Address then
+ return;
+ end if;
+
+ Target.Clear;
+ Target.Union (Source);
+ end Assign;
+
--------------
-- Capacity --
--------------
@@ -186,6 +196,34 @@
return Find (Container, Item) /= No_Element;
end Contains;
+ ----------
+ -- Copy --
+ ----------
+
+ function Copy
+ (Source : Set;
+ Capacity : Count_Type := 0) return Set
+ is
+ C : Count_Type;
+
+ begin
+ if Capacity = 0 then
+ C := Source.Length;
+
+ elsif Capacity >= Source.Length then
+ C := Capacity;
+
+ else
+ raise Capacity_Error
+ with "Requested capacity is less than Source length";
+ end if;
+
+ return Target : Set do
+ Target.Reserve_Capacity (C);
+ Target.Assign (Source);
+ end return;
+ end Copy;
+
---------------
-- Copy_Node --
---------------
Index: a-cohase.ads
===================================================================
--- a-cohase.ads (revision 180929)
+++ a-cohase.ads (working copy)
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 2004-2010, Free Software Foundation, Inc. --
+-- Copyright (C) 2004-2011, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
@@ -133,6 +133,10 @@
-- Calls Process with the element (having only a constant view) of the node
-- designed by the cursor.
+ procedure Assign (Target : in out Set; Source : Set);
+
+ function Copy (Source : Set; Capacity : Count_Type := 0) return Set;
+
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-11-04 10:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-04 10:25 [Ada] Add new Assign and Copy operations to unbounded containers Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).