GNAT.Table Example


-- GNAT.Table Example
--
-- Resizable one dimensional array

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with GNAT.Table;
with GNAT.IO; use GNAT.IO;

procedure Table is

   package Test_Table is new GNAT.Table (Table_Component_Type => Unbounded_String,
                                         Table_Index_Type     => Positive,
                                         Table_Low_Bound      => 1,
                                         Table_Initial        => 10,  -- # of elements
                                         Table_Increment      => 40); -- % increase

begin
   for N in Positive range 1 .. 50 loop
      Test_Table.Increment_Last;
      Test_Table.Table(N) := To_Unbounded_String(Integer'Image(N));
   end loop;

   for N in Positive range Test_Table.First .. Test_Table.Last loop
      Put_Line(To_String(Test_Table.Table(N)));
   end loop;

   Put_Line("Reinitialize table");
   Test_Table.Init;
   Test_Table.Increment_Last;
   Test_Table.Table(1) := To_Unbounded_String("I'm the last one.");

   for N in Positive range Test_Table.First .. Test_Table.Last loop
      Put_Line(To_String(Test_Table.Table(N)));
   end loop;

end Table;


Contributed by: David Botton
Contributed on: May 19, 1999
License: Public Domain

Back