2021-10-06 03:56:30 +00:00
|
|
|
with Ada.Finalization;
|
|
|
|
|
|
|
|
generic
|
|
|
|
--type Item_Type is private;
|
|
|
|
type Item_Type is (<>);
|
|
|
|
G_Terminator_Length: System_Zero_Or_One;
|
|
|
|
G_Terminator_Value: Item_Type;
|
|
|
|
package H3.Arrays is
|
2021-10-30 05:32:16 +00:00
|
|
|
--pragma Preelaborate (Arrays);
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-30 01:57:19 +00:00
|
|
|
subtype Item is Item_Type;
|
|
|
|
|
2021-10-06 03:56:30 +00:00
|
|
|
Terminator_Length: constant System_Zero_Or_One := G_Terminator_Length;
|
|
|
|
Terminator_Value: constant Item_Type := G_Terminator_Value;
|
|
|
|
|
2021-10-06 07:50:01 +00:00
|
|
|
type Direction is (DIRECTION_BACKWARD, DIRECTION_FORWARD);
|
|
|
|
|
2021-10-06 03:56:30 +00:00
|
|
|
type Elastic_Array is tagged private;
|
2021-10-27 15:34:30 +00:00
|
|
|
--type Item_Array is array(System_Index range <>) of aliased Item_Type;
|
2021-10-06 03:56:30 +00:00
|
|
|
type Item_Array is array(System_Index range <>) of Item_Type;
|
|
|
|
--type Item_Array_Pointer is access all Item_Array;
|
|
|
|
|
|
|
|
subtype Thin_Item_Array is Item_Array(System_Index'Range);
|
|
|
|
type Thin_Item_Array_Pointer is access Thin_Item_Array;
|
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
function To_Item_Array (Obj: in Elastic_Array) return Item_Array;
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
function Get_Capacity (Obj: in Elastic_Array) return System_Size;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Get_Capacity);
|
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
function Get_Length (Obj: in Elastic_Array) return System_Size;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Get_Length);
|
|
|
|
|
|
|
|
-- the return type is System_Size for consistency with Get_Last_Index.
|
2021-10-06 08:05:21 +00:00
|
|
|
function Get_First_Index (Obj: in Elastic_Array) return System_Size;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Get_First_Index);
|
|
|
|
|
|
|
|
-- the return type is System_Size because the Last index is -1 off the System_Index'First for an empty array
|
2021-10-06 08:05:21 +00:00
|
|
|
function Get_Last_Index (Obj: in Elastic_Array) return System_Size;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Get_Last_index);
|
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
function Get_Item (Obj: in Elastic_Array; Pos: in System_Index) return Item_Type;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Get_Item);
|
|
|
|
|
|
|
|
-- unsafe
|
2021-10-06 08:05:21 +00:00
|
|
|
function Get_Slot_Pointer (Obj: in Elastic_Array) return Thin_Item_Array_Pointer;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Get_Slot_Pointer);
|
|
|
|
|
2021-10-27 15:34:30 +00:00
|
|
|
function Is_Shared(Obj: in Elastic_Array) return Boolean;
|
2021-10-06 03:56:30 +00:00
|
|
|
pragma Inline (Is_Shared);
|
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
procedure Clear (Obj: in out Elastic_Array);
|
|
|
|
procedure Purge (Obj: in out Elastic_Array); -- clear and reset the buffer to Empty_Buffer.
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
procedure Insert (Obj: in out Elastic_Array; Pos: in System_Index; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Insert (Obj: in out Elastic_Array; Pos: in System_Index; V: in Item_Array);
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
procedure Append (Obj: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Append (Obj: in out Elastic_Array; V: in Item_Array);
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
procedure Prepend (Obj: in out Elastic_Array; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Prepend (Obj: in out Elastic_Array; V: in Item_Array);
|
2021-10-27 15:34:30 +00:00
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
procedure Replace (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Type; Repeat: in System_Size := 1);
|
|
|
|
procedure Replace (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size; V: in Item_Array);
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
procedure Delete (Obj: in out Elastic_Array; From_Pos: in System_Index; To_Pos: in System_Size);
|
2021-10-06 03:56:30 +00:00
|
|
|
|
2021-10-27 15:34:30 +00:00
|
|
|
function Find (Obj: in Elastic_Array; V: in Item_Type; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size;
|
|
|
|
function Find (Obj: in Elastic_Array; V: in Item_Array; Start_Pos: in System_Index; Find_Dir: in Direction := DIRECTION_FORWARD) return System_Size;
|
2021-10-06 07:50:01 +00:00
|
|
|
|
2021-10-27 15:34:30 +00:00
|
|
|
function "=" (Obj: in Elastic_Array; Obj2: in Elastic_Array) return Boolean;
|
|
|
|
function "=" (Obj: in Elastic_Array; Obj2: in Item_Array) return Boolean;
|
2021-10-06 03:56:30 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
type Buffer_Record(Capa: System_Size) is limited record
|
|
|
|
Refs: System_Size := 1;
|
|
|
|
Slot: Item_Array(1 .. Capa) := (others => Terminator_Value);
|
|
|
|
Last: System_Size := 0;
|
|
|
|
end record;
|
|
|
|
|
|
|
|
type Buffer_Pointer is access all Buffer_Record;
|
2021-10-16 02:04:24 +00:00
|
|
|
--for Buffer_Pointer'Storage_Pool use <<TODO: custom storage pool?>> H3'Storage_Pool;
|
2021-10-06 03:56:30 +00:00
|
|
|
|
|
|
|
--Empty_Buffer: aliased Buffer_Record(1);
|
|
|
|
-- Use 1 slot to hold the terminator value regardless of th terminator length in Empty_Buffer.
|
|
|
|
Empty_Buffer: aliased Buffer_Record := (Capa => 1, Refs => 0, Slot => (1 => Terminator_Value), Last => 0);
|
|
|
|
|
|
|
|
type Elastic_Array is new Ada.Finalization.Controlled with record
|
|
|
|
Buffer: Buffer_Pointer := Empty_Buffer'Access;
|
|
|
|
end record;
|
|
|
|
|
2021-10-06 08:05:21 +00:00
|
|
|
overriding procedure Initialize (Obj: in out Elastic_Array);
|
|
|
|
overriding procedure Adjust (Obj: in out Elastic_Array);
|
|
|
|
overriding procedure Finalize (Obj: in out Elastic_Array);
|
2021-10-06 03:56:30 +00:00
|
|
|
|
|
|
|
end H3.Arrays;
|