-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgeneric_unbounded_ptr_array.adb
88 lines (80 loc) · 3.53 KB
/
generic_unbounded_ptr_array.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Generic_Unbounded_Ptr_Array Luebeck --
-- Implementation Spring, 2002 --
-- --
-- Last revision : 11:37 13 Oct 2007 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with Ada.Unchecked_Deallocation;
package body Generic_Unbounded_Ptr_Array is
use type Object_Ptr_Array.Object_Array_Ptr;
procedure Delete is
new Ada.Unchecked_Deallocation (Object_Type, Object_Ptr_Type);
procedure Erase (Container : in out Unbounded_Ptr_Array)
renames Finalize;
procedure Finalize (Container : in out Unbounded_Ptr_Array) is
begin
if Container.Vector /= null then
for Index in Container.Vector'range loop
Delete (Container.Vector (Index));
end loop;
end if;
end Finalize;
function Get
( Container : Unbounded_Ptr_Array;
Index : Index_Type
) return Object_Ptr_Type is
begin
if ( Container.Vector = null
or else
Index not in Container.Vector'range
)
then
return null;
else
return Container.Vector (Index);
end if;
end Get;
procedure Put
( Container : in out Unbounded_Ptr_Array;
Index : Index_Type;
Element : Object_Ptr_Type
) is
begin
if ( Container.Vector /= null
and then
Index in Container.Vector'Range
)
then
if Container.Vector (Index) /= Element then
Delete (Container.Vector (Index));
Container.Vector (Index) := Element;
end if;
else
Object_Ptr_Array.Put
( Object_Ptr_Array.Unbounded_Array (Container),
Index,
Element
);
end if;
end Put;
end Generic_Unbounded_Ptr_Array;