Daily bump.
[official-gcc.git] / gcc / ada / a-ststio.ads
blobf0c8e3e840a192e0f641f6beb854ac8a401acf4b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . S T R E A M S . S T R E A M _ I O --
6 -- --
7 -- S p e c --
8 -- --
9 -- $Revision: 1.1.16.1 $
10 -- --
11 -- Copyright (C) 1992-1997 Free Software Foundation, Inc. --
12 -- --
13 -- This specification is derived from the Ada Reference Manual for use with --
14 -- GNAT. The copyright notice above, and the license provisions that follow --
15 -- apply solely to the contents of the part following the private keyword. --
16 -- --
17 -- GNAT is free software; you can redistribute it and/or modify it under --
18 -- terms of the GNU General Public License as published by the Free Soft- --
19 -- ware Foundation; either version 2, or (at your option) any later ver- --
20 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
21 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
22 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
23 -- for more details. You should have received a copy of the GNU General --
24 -- Public License distributed with GNAT; see file COPYING. If not, write --
25 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
26 -- MA 02111-1307, USA. --
27 -- --
28 -- As a special exception, if other files instantiate generics from this --
29 -- unit, or you link this unit with other files to produce an executable, --
30 -- this unit does not by itself cause the resulting executable to be --
31 -- covered by the GNU General Public License. This exception does not --
32 -- however invalidate any other reasons why the executable file might be --
33 -- covered by the GNU Public License. --
34 -- --
35 -- GNAT was originally developed by the GNAT team at New York University. --
36 -- Extensive contributions were provided by Ada Core Technologies Inc. --
37 -- --
38 ------------------------------------------------------------------------------
40 with Ada.IO_Exceptions;
41 with System.File_Control_Block;
43 package Ada.Streams.Stream_IO is
45 type Stream_Access is access all Root_Stream_Type'Class;
47 type File_Type is limited private;
49 type File_Mode is (In_File, Out_File, Append_File);
51 -- The following representation clause allows the use of unchecked
52 -- conversion for rapid translation between the File_Mode type
53 -- used in this package and System.File_IO.
55 for File_Mode use
56 (In_File => 0, -- System.FIle_IO.File_Mode'Pos (In_File)
57 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
58 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
60 type Count is new Stream_Element_Offset
61 range 0 .. Stream_Element_Offset'Last;
63 subtype Positive_Count is Count range 1 .. Count'Last;
64 -- Index into file, in stream elements
66 ---------------------
67 -- File Management --
68 ---------------------
70 procedure Create
71 (File : in out File_Type;
72 Mode : in File_Mode := Out_File;
73 Name : in String := "";
74 Form : in String := "");
76 procedure Open
77 (File : in out File_Type;
78 Mode : in File_Mode;
79 Name : in String;
80 Form : in String := "");
82 procedure Close (File : in out File_Type);
83 procedure Delete (File : in out File_Type);
84 procedure Reset (File : in out File_Type; Mode : in File_Mode);
85 procedure Reset (File : in out File_Type);
87 function Mode (File : in File_Type) return File_Mode;
88 function Name (File : in File_Type) return String;
89 function Form (File : in File_Type) return String;
91 function Is_Open (File : in File_Type) return Boolean;
92 function End_Of_File (File : in File_Type) return Boolean;
94 function Stream (File : in File_Type) return Stream_Access;
96 -----------------------------
97 -- Input-Output Operations --
98 -----------------------------
100 procedure Read
101 (File : in File_Type;
102 Item : out Stream_Element_Array;
103 Last : out Stream_Element_Offset;
104 From : in Positive_Count);
106 procedure Read
107 (File : in File_Type;
108 Item : out Stream_Element_Array;
109 Last : out Stream_Element_Offset);
111 procedure Write
112 (File : in File_Type;
113 Item : in Stream_Element_Array;
114 To : in Positive_Count);
116 procedure Write
117 (File : in File_Type;
118 Item : in Stream_Element_Array);
120 ----------------------------------------
121 -- Operations on Position within File --
122 ----------------------------------------
124 procedure Set_Index (File : in File_Type; To : in Positive_Count);
126 function Index (File : in File_Type) return Positive_Count;
127 function Size (File : in File_Type) return Count;
129 procedure Set_Mode (File : in out File_Type; Mode : in File_Mode);
131 procedure Flush (File : in out File_Type);
133 ----------------
134 -- Exceptions --
135 ----------------
137 Status_Error : exception renames IO_Exceptions.Status_Error;
138 Mode_Error : exception renames IO_Exceptions.Mode_Error;
139 Name_Error : exception renames IO_Exceptions.Name_Error;
140 Use_Error : exception renames IO_Exceptions.Use_Error;
141 Device_Error : exception renames IO_Exceptions.Device_Error;
142 End_Error : exception renames IO_Exceptions.End_Error;
143 Data_Error : exception renames IO_Exceptions.Data_Error;
145 private
146 package FCB renames System.File_Control_Block;
148 -----------------------------
149 -- Stream_IO Control Block --
150 -----------------------------
152 type Operation is (Op_Read, Op_Write, Op_Other);
153 -- Type used to record last operation (to optimize sequential operations)
155 type Stream_AFCB is new FCB.AFCB with record
156 Index : Count := 1;
157 -- Current Index value
159 File_Size : Stream_Element_Offset := -1;
160 -- Cached value of File_Size, so that we do not keep recomputing it
161 -- when not necessary (otherwise End_Of_File becomes gruesomely slow).
162 -- A value of minus one means that there is no cached value.
164 Last_Op : Operation := Op_Other;
165 -- Last operation performed on file, used to avoid unnecessary
166 -- repositioning between successive read or write operations.
168 Update_Mode : Boolean := False;
169 -- Set if the mode is changed from write to read or vice versa.
170 -- Indicates that the file has been reopened in update mode.
172 end record;
174 type File_Type is access all Stream_AFCB;
176 function AFCB_Allocate (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
178 procedure AFCB_Close (File : access Stream_AFCB);
179 procedure AFCB_Free (File : access Stream_AFCB);
181 procedure Read
182 (File : in out Stream_AFCB;
183 Item : out Ada.Streams.Stream_Element_Array;
184 Last : out Ada.Streams.Stream_Element_Offset);
185 -- Read operation used when Stream_IO file is treated directly as Stream
187 procedure Write
188 (File : in out Stream_AFCB;
189 Item : in Ada.Streams.Stream_Element_Array);
190 -- Write operation used when Stream_IO file is treated directly as Stream
192 end Ada.Streams.Stream_IO;