Copyright (C) А.Гавва V-0.4w май 2004

5. Спецификации пакетов ввода/вывода.

5.1 Пакеты текстового ввода/вывода

5.1.1 Пакет Ada.Text_IO



with Ada.IO_Exceptions;    -- описано в приложении A (Annex A)
                           -- руководства по языку (RM-95)

package Ada.Text_IO is
pragma Elaborate_Body (Text_IO);

   type File_Type is limited private;                   -- внутреннее представление
                                                        --    файла для программы

   type File_Mode is (In_File, Out_File, Append_File);  -- управляет направлением
                                                        --    передачи данных
                                                        --    (в/из файла)



   type Count is range 0 .. Определяется_Реализацией;
   subtype Positive_Count is Count range 1 .. Count'Last;

   Unbounded : constant Count := 0;               -- длина строки и страницы


   subtype Field is Integer range 0 .. Определяется_Реализацией;

   subtype Number_Base is Integer range 2 .. 16;  -- используются только:
                                                  --     2, 8, 10 и 16

   type Type_Set is (Lower_Case, Upper_Case);     -- для перечислимых типов



   -- Подпрограммы управления файлами

   procedure Create
     (File : in out File_Type;          -- ассоциируемая с внешним файлом
                                        --     переменная в программе
      Mode : in File_Mode := Out_File;  -- по умолчанию - файл для вывода данных
      Name : in String := "";           -- имя внешнего файла
      Form : in String := "");          -- использование, не определено стандартом

   procedure Open
     (File : in out File_Type;
      Mode : in File_Mode;
      Name : in String;
      Form : in String := "");

   procedure Close  (File : in out File_Type);
   procedure Delete (File : in out File_Type);
   procedure Reset  (File : in out File_Type; Mode : in File_Mode); -- меняет режим
                                                                    --   доступа
                                                                    --   к файлу
   procedure Reset  (File : in out File_Type);

   function Mode (File : in File_Type) return File_Mode;  -- режим доступа к файлу
   function Name (File : in File_Type) return String;     -- имя внешнего файла
   function Form (File : in File_Type) return String;     -- зависит от реализации

   function Is_Open (File : in File_Type) return Boolean;



   -- Подпрограммы управления файлами ввода, вывода и вывода ошибок
   --    устанавливаемыми по умолчанию

   procedure Set_Input  (File : in File_Type);  -- установить как файл ввода
   procedure Set_Output (File : in File_Type);  -- установить как файл вывода
   procedure Set_Error  (File : in File_Type);  -- установить как файл вывода ошибок
                            -- ПРИМЕЧАНИЕ: перед вызовом подпрограмм Set_Input,
                            --             Set_Output и/или Set_Error,
                            --             файл File должен быть открыт

   function Standard_Input  return File_Type;   -- обычно, клавиатура
   function Standard_Output return File_Type;   -- обычно, видеодисплей
   function Standard_Error  return File_Type;

   function Current_Input  return File_Type;    -- обычно, то же что и Standard_Input
   function Current_Output return File_Type;
   function Current_Error  return File_Type;


   type File_Access is access constant File_Type; -- ссылочный тип (указатель)
                                                  --     позволяющий ссылаться
                                                  --     на переменные внутреннего
                                                  --     представления файла, что
                                                  --     во многих случаях удобно
                                                  -- (введен стандартом ada)

   function Standard_Input  return File_Access;
   function Standard_Output return File_Access;
   function Standard_Error  return File_Access;

   function Current_Input  return File_Access;
   function Current_Output return File_Access;
   function Current_Error  return File_Access;



   -- Подпрограммы управления буферами

   procedure Flush (File : in out File_Type);
   procedure Flush;



   -- Подпрограммы спецификации длин строк и страниц для ввода/вывода

   procedure Set_Line_Length (File : in File_Type; To : in Count);
   procedure Set_Line_Length (To : in Count);

   procedure Set_Page_Length (File : in File_Type; To : in Count);
   procedure Set_Page_Length (To : in Count);

   function Line_Length (File : in File_Type) return Count;
   function Line_Length return Count;

   function Page_Length (File : in File_Type) return Count;
   function Page_Length return Count;



   -- Подпрограммы спецификации Column, Line и Page (колонка, строка и страница)

   procedure New_Line (File : in File_Type;               -- вывод терминатора строки
                       Spacing : in Positive_Count := 1); -- по умолчанию, один раз
   procedure New_Line (Spacing : in Positive_Count := 1);

   procedure Skip_Line (File : in File_Type;              -- отбросить ввод символов
                       Spacing : in Positive_Count := 1); -- по умолчанию, для одной
   procedure Skip_Line (Spacing : in Positive_Count := 1);-- строки

   function End_Of_Line (File : in File_Type) return Boolean;
   function End_Of_Line return Boolean;

   procedure New_Page (File : in File_Type);   -- завершить текущую страницу
   procedure New_Page;                         -- выводом терминатора страницы

   procedure Skip_Page (File : in File_Type);  -- отбросить ввод символов
   procedure Skip_Page;                        -- вплоть до терминатора страницы


   function End_Of_Page (File : in File_Type) return Boolean;
   function End_Of_Page return Boolean;

   function End_Of_File (File : in File_Type) return Boolean;
   function End_Of_File return Boolean;


   procedure Set_Col (File : in File_Type;  To : in Positive_Count);
   procedure Set_Col (To : in Positive_Count);

   procedure Set_Line (File : in File_Type; To : in Positive_Count);
   procedure Set_Line (To : in Positive_Count);

   function Col (File : in File_Type) return Positive_Count;
   function Col return Positive_Count;

   function Line (File : in File_Type) return Positive_Count;
   function Line return Positive_Count;

   function Page (File : in File_Type) return Positive_Count;
   function Page return Positive_Count;



   -- Посимвольный ввод/вывод

   procedure Get (File : in File_Type; Item : out Character);
   procedure Get (Item : out Character);
   procedure Put (File : in File_Type; Item : in Character);
   procedure Put (Item : in Character);

   procedure Look_Ahead
     (File        : in File_Type;
      Item        : out Character;
      End_Of_Line : out Boolean);

   procedure Look_Ahead
     (Item        : out Character;
      End_Of_Line : out Boolean);

   procedure Get_Immediate
     (File : in File_Type;
      Item : out Character);

   procedure Get_Immediate
     (Item : out Character);

   procedure Get_Immediate
     (File      : in File_Type;
      Item      : out Character;
      Available : out Boolean);

   procedure Get_Immediate
     (Item      : out Character;
      Available : out Boolean);




   -- Построчный ввод/вывод

   procedure Get (File : in File_Type; Item : out String);
   procedure Get (Item : out String);
   procedure Put (File : in File_Type; Item : in String);
   procedure Put (Item : int String);

   procedure Get_Line
     (File : in File_Type;
      Item : out String;
      Last : out Natural);

   procedure Get_Line
     (Item : out String;
      Last : out Natural);

   procedure Put_Line
     (File : in File_Type;
      Item : in String);

   procedure Put_Line
     (Item : in String);



   --  Исключения

   Status_Error : exception renames IO_Exceptions.Status_Error;
   Mode_Error   : exception renames IO_Exceptions.Mode_Error;
   Name_Error   : exception renames IO_Exceptions.Name_Error;
   Use_Error    : exception renames IO_Exceptions.Use_Error;
   Device_Error : exception renames IO_Exceptions.Device_Error;
   End_Error    : exception renames IO_Exceptions.End_Error;
   Data_Error   : exception renames IO_Exceptions.Data_Error;
   Layout_Error : exception renames IO_Exceptions.Layout_Error;



private

  . . .   -- стандартом языка не определено

end Ada.Text_IO;

5.1.2 Пакет Ada.Text_IO.Integer_IO



generic
   type Num is range <>;  -- параметр настройки модуля

package Ada.Text_IO.Integer_IO is

   Default_Width : Field := Num'Width;  -- ширина числа в символах
   Default_Base  : Number_Base := 10;   -- устанавливает основание системы счисления
                                        --    принимаемое по умолчанию для всех
                                        --    операций ввода/вывода

   procedure Get               -- ввод числа из указанного файла
     (File  : in File_Type;
      Item  : out Num;         -- тип соответствует формальному параметру настройки
      Width : in Field := 0);  -- может быть использовано для точного указания
                               --   количества вводимых символов

   procedure Get               -- ввод числа из файла стандартного ввода
     (Item  : out Num;
      Width : in Field := 0);

   procedure Put               -- вывод числа в указанный файл
     (File  : in File_Type;
      Item  : in Num;
      Width : in Field := Default_Width;
      Base  : in Number_Base := Default_Base);

   procedure Put               -- вывод числа в файл стандартного вывода
     (Item  : in Num;
      Width : in Field := Default_Width;
      Base  : in Number_Base := Default_Base);

   procedure Get               -- ввод числа из строки
                               --   (преобразование из строкового представления)
     (From : in String;
      Item : out Num;
      Last : out Positive);    -- индекс последнего преобразуемого символа в From

   procedure Put               -- вывод числа в строку
                               --   (преобразование в строковое представление)
     (To   : out String;
      Item : in Num;
      Base : in Number_Base := Default_Base);

end Ada.Text_IO.Integer_IO;

5.1.3 Пакет Ada.Text_IO.Modular_IO



generic
   type Num is mod <>;  -- параметр настройки модуля

package Ada.Text_IO.Modular_IO is

   Default_Width : Field := Num'Width;  -- ширина числа в символах
   Default_Base  : Number_Base := 10;   -- устанавливает основание системы счисления
                                        --    принимаемое по умолчанию для всех
                                        --    операций ввода/вывода

   procedure Get               -- ввод числа из указанного файла
     (File  : in File_Type;
      Item  : out Num;
      Width : in Field := 0);

   procedure Get               -- ввод числа из файла стандартного ввода
     (Item  : out Num;
      Width : in Field := 0);

   procedure Put               -- вывод числа в указанный файл
     (File  : in File_Type;
      Item  : in Num;
      Width : in Field := Default_Width;
      Base  : in Number_Base := Default_Base);

   procedure Put               -- вывод числа в файл стандартного вывода
     (Item  : in Num;
      Width : in Field := Default_Width;
      Base  : in Number_Base := Default_Base);

   procedure Get               -- ввод числа из строки
                               --   (преобразование из строкового представления)
     (From : in String;
      Item : out Num;
      Last : out Positive);

   procedure Put               -- вывод числа в строку
                               --   (преобразование в строковое представление)
     (To   : out String;
      Item : in Num;
      Base : in Number_Base := Default_Base);

end Ada.Text_IO.Modular_IO;

5.1.4 Пакет Ada.Text_IO.Float_IO



generic
   type Num is digits <>;  -- параметр настройки модуля

package Ada.Text_IO.Float_IO is

   Default_Fore : Field := 2;               -- количество символов слева
                                            --   от десятичной точки
   Default_Aft  : Field := Num'Digits - 1;  -- количество символов справа
                                            --   от десятичной точки
   Default_Exp  : Field := 3;               -- для нотации используемой
                                            --   в научных рассчетах

   procedure Get               -- ввод числа из указанного файла
     (File  : in File_Type;
      Item  : out Num;
      Width : in Field := 0);

   procedure Get               -- ввод числа из файла стандартного ввода
     (Item  : out Num;
      Width : in Field := 0);

   procedure Put               -- вывод числа в указанный файл
     (File : in File_Type;
      Item : in Num;
      Fore : in Field := Default_Fore;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

   procedure Put               -- вывод числа в файл стандартного вывода
     (Item : in Num;
      Fore : in Field := Default_Fore;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

   procedure Get               -- ввод числа из строки
                               --   (преобразование из строкового представления)
     (From : in String;
      Item : out Num;
      Last : out Positive);

   procedure Put               -- вывод числа в строку
                               --   (преобразование в строковое представление)
     (To   : out String;
      Item : in Num;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

end Ada.Text_IO.Float_IO;

5.1.5 Пакет Ada.Text_IO.Fixed_IO



generic
   type Num is delta <>;  -- параметр настройки модуля

package Ada.Text_IO.Fixed_IO is

   Default_Fore : Field := Num'Fore; -- количество символов слева
                                     --   от десятичной точки
   Default_Aft  : Field := Num'Aft;  -- количество символов справа
                                     --   от десятичной точки
   Default_Exp  : Field := 0;        -- для нотации используемой
                                     --   в научных рассчетах

   procedure Get               -- ввод числа из указанного файла
     (File  : in File_Type;
      Item  : out Num;
      Width : in Field := 0);

   procedure Get               -- ввод числа из файла стандартного ввода
     (Item  : out Num;
      Width : in Field := 0);

   procedure Put               -- вывод числа в указанный файл
     (File : in File_Type;
      Item : in Num;
      Fore : in Field := Default_Fore;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

   procedure Put               -- вывод числа в файл стандартного вывода
     (Item : in Num;
      Fore : in Field := Default_Fore;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

   procedure Get               -- ввод числа из строки
                               --   (преобразование из строкового представления)
     (From : in String;
      Item : out Num;
      Last : out Positive);

   procedure Put               -- вывод числа в строку
                               --   (преобразование в строковое представление)
     (To   : out String;
      Item : in Num;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

end Ada.Text_IO.Fixed_IO;

5.1.6 Пакет Ada.Text_IO.Decimal_IO



generic
   type Num is delta <> digits <>;  -- параметр настройки модуля

package Ada.Text_IO.Decimal_IO is   -- децимальные типы, как правило, используются
                                    --     в финансовых приложениях

   Default_Fore : Field := Num'Fore; -- количество символов слева
                                     --   от десятичной точки
   Default_Aft  : Field := Num'Aft;  -- количество символов справа
                                     --   от десятичной точки
   Default_Exp  : Field := 0;        -- для нотации используемой
                                     --   в научных рассчетах

   procedure Get               -- ввод числа из указанного файла
     (File  : in File_Type;
      Item  : out Num;
      Width : in Field := 0);

   procedure Get               -- ввод числа из файла стандартного ввода
     (Item  : out Num;
      Width : in Field := 0);

   procedure Put               -- вывод числа в указанный файл
     (File : in File_Type;
      Item : in Num;
      Fore : in Field := Default_Fore;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

   procedure Put               -- вывод числа в файл стандартного вывода
     (Item : in Num;
      Fore : in Field := Default_Fore;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

   procedure Get               -- ввод числа из строки
                               --   (преобразование из строкового представления)
     (From : in String;
      Item : out Num;
      Last : out Positive);

   procedure Put               -- вывод числа в строку
                               --   (преобразование в строковое представление)
     (To   : out String;
      Item : in Num;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);

end Ada.Text_IO.Decimal_IO;

5.1.7 Пакет Ada.Text_IO.Enumeration_IO



generic
   type Enum is (<>);  -- параметр настройки модуля

package Ada.Text_IO.Enumeration_IO is

   Default_Width : Field := 0;
   Default_Setting : Type_Set := Upper_Case;

   procedure Get     -- ввод значения перечислимого типа из указанного файла
     (File  : in  File_Type;
      Item  : out Enum);

   procedure Get     -- ввод значения перечислимого типа из файла стандартного ввода
     (Item  : out Enum);

   procedure Put     -- вывод значения перечислимого типа в указанный файл
     (File  : in File_Type;
      Item  : in Enum;
      Width : in Field := Default_Width;
      Set   : in Type_Set := Default_Setting);

   procedure Put     -- вывод значения перечислимого типа в файл стандартного вывода
     (Item  : in Enum;
      Width : in Field := Default_Width;
      Set   : in Type_Set := Default_Setting);

   procedure Get     -- ввод значения перечислимого типа из строки
                     --   (преобразование из строкового представления)
     (From : in String;
      Item : out Enum;
      Last : out Positive);

   procedure Put     -- вывод значения перечислимого типа в строку
                     --   (преобразование в строковое представление)
     (To   : out String;
      Item : in Enum;
      Set  : in Type_Set := Default_Setting);

end Ada.Text_IO.Enumeration_IO;

5.2 Пакет Ada.Sequential_IO



with Ada.IO_Exceptions;

generic
   type Element_Type (<>) is private;  -- параметр настройки модуля

package Ada.Sequential_IO is

   type File_Type is limited private;

   type File_Mode is (In_File, Out_File, Append_File);



   -- Подпрограммы управления файлами

   procedure Create
     (File : in out File_Type;
      Mode : in File_Mode := Out_File;
      Name : in String := "";
      Form : in String := "");

   procedure Open
     (File : in out File_Type;
      Mode : in File_Mode;
      Name : in String;
      Form : in String := "");

   procedure Close  (File : in out File_Type);
   procedure Delete (File : in out File_Type);
   procedure Reset  (File : in out File_Type; Mode : in File_Mode);
   procedure Reset  (File : in out File_Type);

   function Mode    (File : in File_Type) return File_Mode;
   function Name    (File : in File_Type) return String;
   function Form    (File : in File_Type) return String;

   function Is_Open (File : in File_Type) return Boolean;



   -- Подпрограммы ввода/вывода

   procedure Read  (File : in File_Type; Item : out Element_Type);
   procedure Write (File : in File_Type; Item : in Element_Type);

   function End_Of_File (File : in File_Type) return Boolean;



   -- Исключения

   Status_Error : exception renames IO_Exceptions.Status_Error;
   Mode_Error   : exception renames IO_Exceptions.Mode_Error;
   Name_Error   : exception renames IO_Exceptions.Name_Error;
   Use_Error    : exception renames IO_Exceptions.Use_Error;
   Device_Error : exception renames IO_Exceptions.Device_Error;
   End_Error    : exception renames IO_Exceptions.End_Error;
   Data_Error   : exception renames IO_Exceptions.Data_Error;

private

  . . .   -- стандартом языка не определено

end Ada.Sequential_IO;

5.3 Пакет Ada.Direct_IO



with Ada.IO_Exceptions;

generic
   type Element_Type is private;  -- параметр настройки модуля

package Ada.Direct_IO is

   type File_Type is limited private;

   type File_Mode is (In_File, Inout_File, Out_File);


   type Count is range 0 .. System.Direct_IO.Count'Last;

   subtype Positive_Count is Count range 1 .. Count'Last;



   -- Подпрограммы управления файлами

   procedure Create
     (File : in out File_Type;
      Mode : in File_Mode := Inout_File;
      Name : in String := "";
      Form : in String := "");

   procedure Open
     (File : in out File_Type;
      Mode : in File_Mode;
      Name : in String;
      Form : in String := "");

   procedure Close  (File : in out File_Type);
   procedure Delete (File : in out File_Type);
   procedure Reset  (File : in out File_Type; Mode : in File_Mode);
   procedure Reset  (File : in out File_Type);

   function Mode (File : in File_Type) return File_Mode;
   function Name (File : in File_Type) return String;
   function Form (File : in File_Type) return String;

   function Is_Open (File : in File_Type) return Boolean;



   -- Подпрограммы ввода/вывода

   procedure Read
     (File : in File_Type;
      Item : out Element_Type;
      From : in Positive_Count);

   procedure Read
     (File : in File_Type;
      Item : out Element_Type);

   procedure Write
     (File : in File_Type;
      Item : in Element_Type;
      To   : in Positive_Count);

   procedure Write
     (File : in File_Type;
      Item : in Element_Type);

   procedure Set_Index (File : in File_Type; To : in Positive_Count);

   function Index (File : in File_Type) return Positive_Count;
   function Size  (File : in File_Type) return Count;

   function End_Of_File (File : in File_Type) return Boolean;



   -- Исключения

   Status_Error : exception renames IO_Exceptions.Status_Error;
   Mode_Error   : exception renames IO_Exceptions.Mode_Error;
   Name_Error   : exception renames IO_Exceptions.Name_Error;
   Use_Error    : exception renames IO_Exceptions.Use_Error;
   Device_Error : exception renames IO_Exceptions.Device_Error;
   End_Error    : exception renames IO_Exceptions.End_Error;
   Data_Error   : exception renames IO_Exceptions.Data_Error;


private

  . . .   -- стандартом языка не определено

end Ada.Direct_IO;

5.4 Пакет Ada.Streams.Stream_IO



with Ada.IO_Exceptions;

package Ada.Streams.Stream_IO is

   type Stream_Access is access all Root_Stream_Type'Class;
   type File_Type is limited private;
   type File_Mode is (In_File, Out_File, Append_File);


   type Count is range 0 .. Определяется_Реализацией;

   subtype Positive_Count is Count range 1 .. Count'Last;  --  индекс в файле,
                                                            --   в потоковых
                                                            --   элементах

   -- Подпрограммы управления файлами

   procedure Create
     (File : in out File_Type;
      Mode : in File_Mode := Out_File;
      Name : in String := "";
      Form : in String := "");

   procedure Open
     (File : in out File_Type;
      Mode : in File_Mode;
      Name : in String;
      Form : in String := "");

   procedure Close  (File : in out File_Type);
   procedure Delete (File : in out File_Type);
   procedure Reset  (File : in out File_Type; Mode : in File_Mode);
   procedure Reset  (File : in out File_Type);

   function Mode (File : in File_Type) return File_Mode;
   function Name (File : in File_Type) return String;
   function Form (File : in File_Type) return String;

   function Is_Open     (File : in File_Type) return Boolean;
   function End_Of_File (File : in File_Type) return Boolean;

   function Stream (File : in File_Type) return Stream_Access;



   -- Подпрограммы ввода/вывода

   procedure Read
     (File : in  File_Type;
      Item : out Stream_Element_Array;
      Last : out Stream_Element_Offset;
      From : in  Positive_Count);

   procedure Read
     (File : in  File_Type;
      Item : out Stream_Element_Array;
      Last : out Stream_Element_Offset);

   procedure Write
     (File : in File_Type;
      Item : in Stream_Element_Array;
      To   : in Positive_Count);

   procedure Write
     (File : in File_Type;
      Item : in Stream_Element_Array);



   -- Подпрограммы управления позиционированием внутри файла

   procedure Set_Index (File : in File_Type; To : in Positive_Count);

   function Index (File : in File_Type) return Positive_Count;
   function Size  (File : in File_Type) return Count;

   procedure Set_Mode (File : in out File_Type; Mode : in File_Mode);

   procedure Flush (File : in out File_Type);



   -- Исключения

   Status_Error : exception renames IO_Exceptions.Status_Error;
   Mode_Error   : exception renames IO_Exceptions.Mode_Error;
   Name_Error   : exception renames IO_Exceptions.Name_Error;
   Use_Error    : exception renames IO_Exceptions.Use_Error;
   Device_Error : exception renames IO_Exceptions.Device_Error;
   End_Error    : exception renames IO_Exceptions.End_Error;
   Data_Error   : exception renames IO_Exceptions.Data_Error;

private

  . . .   -- стандартом языка не определено

end Ada.Streams.Stream_IO;


Copyright (C) А.Гавва V-0.4w май 2004