File : generic_rectangular_vectors-text_io.adb
------------------------------------------------------------------------------
--
-- package Generic_Rectangular_Vectors.Text_IO (body)
--
------------------------------------------------------------------------------
-- Update information:
--
-- 1996.09.10 (Jacob Sparre Andersen)
-- Written.
--
-- (Insert additional update information above this line.)
------------------------------------------------------------------------------
package body Generic_Rectangular_Vectors.Text_IO is
---------------------------------------------------------------------------
-- package Scalar_Text_IO:
package Scalar_Text_IO is new Ada.Text_IO.Float_IO (Scalar);
---------------------------------------------------------------------------
-- Vector I/O:
------------------------------------------------------------------------
-- procedure Put:
procedure Put (File : in Ada.Text_IO.File_Type;
Item : in Vector) is
use Ada.Text_IO;
use Scalar_Text_IO;
begin -- Put
Put (File, "(");
Put (File, Item (Item'First));
for Coordinate in Item'First + 1 .. Item'Last loop
Put (File, ", ");
Put (File, Item (Coordinate));
end loop;
Put (File, ")");
end Put;
------------------------------------------------------------------------
-- procedure Put:
procedure Put (Item : in Vector) is
begin -- Put
Put (Ada.Text_IO.Current_Output, Item);
end Put;
------------------------------------------------------------------------
-- procedure Get:
procedure Get (File : in Ada.Text_IO.File_Type;
Item : out Vector) is
use Ada.Text_IO;
use Scalar_Text_IO;
Current_Character : Character := ' ';
At_End_Of_Line : Boolean := False;
begin -- Get
Skip_Start_Paranthesis:
loop
Look_Ahead (File, Current_Character, At_End_Of_Line);
if At_End_Of_Line then
Skip_Line (File);
elsif Current_Character = '(' then
Get (File, Current_Character);
exit Skip_Start_Paranthesis;
elsif Current_Character = ' ' then
Get (File, Current_Character);
else
raise Data_Error;
end if;
end loop Skip_Start_Paranthesis;
Read_Coordinates:
for Coordinate in Item'Range loop
Get (File, Item (Coordinate));
Get (File, Current_Character);
if Current_Character /= ',' then
raise Data_Error;
end if;
end loop Read_Coordinates;
Skip_End_Paranthesis:
begin
Get (File, Current_Character);
if Current_Character /= ')' then
raise Data_Error;
end if;
end Skip_End_Paranthesis;
end Get;
------------------------------------------------------------------------
-- procedure Get:
procedure Get (Item : out Vector) is
begin -- Get
Get (Ada.Text_IO.Current_Input, Item);
end Get;
---------------------------------------------------------------------------
-- Point I/O:
------------------------------------------------------------------------
-- procedure Put:
procedure Put (File : in Ada.Text_IO.File_Type;
Item : in Point) is
begin -- Put
Put (File, Vector (Item));
end Put;
------------------------------------------------------------------------
-- procedure Put:
procedure Put (Item : in Point) is
begin -- Put
Put (Ada.Text_IO.Current_Output, Item);
end Put;
------------------------------------------------------------------------
-- procedure Get:
procedure Get (File : in Ada.Text_IO.File_Type;
Item : out Point) is
Buffer : Vector;
begin -- Get
Get (File, Buffer);
Item := Point (Buffer);
end Get;
------------------------------------------------------------------------
-- procedure Get:
procedure Get (Item : out Point) is
begin -- Get
Get (Ada.Text_IO.Current_Input, Item);
end Get;
---------------------------------------------------------------------------
end Generic_Rectangular_Vectors.Text_IO;