AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
GNAT.Table Example (David Botton)

-- 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;


(c) 1998-2004 All Rights Reserved David Botton