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
|
-- Topal: GPG/GnuPG and Alpine/Pine integration
-- Copyright (C) 2001--2008 Phillip J. Brooke
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License version 3 as
-- published by the Free Software Foundation.
--
-- This program 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 program. If not, see <http://www.gnu.org/licenses/>.
-- This package creates an instance of an array that expands.
with Ada.Finalization;
generic
type Item is private;
package Expanding_Array is
type Big_Array is limited private;
procedure Create (Left : in out Big_Array;
Initial_Size : in Positive);
procedure Copy (Left : in out Big_Array;
Right : in Big_Array);
procedure Set(A : in out Big_Array;
Index : in Positive;
Value : in Item);
function Value(A : Big_Array;
Index : Positive) return Item;
function First (A : Big_Array) return Natural;
function Size (A : Big_Array) return Positive;
function Last (A : Big_Array) return Positive;
-- Increase the array by this much.
procedure Expand(A : in out Big_Array;
S : in Positive);
-- If an attempt is made to use Set for an index beyond Last, then the
-- array size will be doubled until it is large enough. So this call
-- should never need to be explicitly used.
Actual_Is_Null : exception;
private
type Actual_Array is array (Positive range <>) of Item;
type Actual_Array_Pointer is access Actual_Array;
type Natural_Pointer is access all Natural;
type Positive_Pointer is access all Positive;
type Big_Array is new Ada.Finalization.Controlled
with record
Actual : Actual_Array_Pointer;
Array_Size : Positive_Pointer;
Ref_Count : Natural_Pointer;
end record;
procedure Initialize (Object : in out Big_Array);
procedure Adjust (Object : in out Big_Array);
procedure Finalize (Object : in out Big_Array);
end Expanding_Array;
|