gcc:
[official-gcc.git] / gcc / ada / a-ststio.ads
blob232672985d57f410ffe38abea3062921be866858
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 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
25 -- --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 with Ada.IO_Exceptions;
39 with System.File_Control_Block;
41 package Ada.Streams.Stream_IO is
43 type Stream_Access is access all Root_Stream_Type'Class;
45 type File_Type is limited private;
47 type File_Mode is (In_File, Out_File, Append_File);
49 -- The following representation clause allows the use of unchecked
50 -- conversion for rapid translation between the File_Mode type
51 -- used in this package and System.File_IO.
53 for File_Mode use
54 (In_File => 0, -- System.File_IO.File_Mode'Pos (In_File)
55 Out_File => 2, -- System.File_IO.File_Mode'Pos (Out_File)
56 Append_File => 3); -- System.File_IO.File_Mode'Pos (Append_File)
58 type Count is new Stream_Element_Offset
59 range 0 .. Stream_Element_Offset'Last;
61 subtype Positive_Count is Count range 1 .. Count'Last;
62 -- Index into file, in stream elements
64 ---------------------
65 -- File Management --
66 ---------------------
68 procedure Create
69 (File : in out File_Type;
70 Mode : File_Mode := Out_File;
71 Name : String := "";
72 Form : String := "");
74 procedure Open
75 (File : in out File_Type;
76 Mode : File_Mode;
77 Name : String;
78 Form : String := "");
80 procedure Close (File : in out File_Type);
81 procedure Delete (File : in out File_Type);
82 procedure Reset (File : in out File_Type; Mode : File_Mode);
83 procedure Reset (File : in out File_Type);
85 function Mode (File : File_Type) return File_Mode;
86 function Name (File : File_Type) return String;
87 function Form (File : File_Type) return String;
89 function Is_Open (File : File_Type) return Boolean;
90 function End_Of_File (File : File_Type) return Boolean;
92 function Stream (File : File_Type) return Stream_Access;
94 -----------------------------
95 -- Input-Output Operations --
96 -----------------------------
98 procedure Read
99 (File : File_Type;
100 Item : out Stream_Element_Array;
101 Last : out Stream_Element_Offset;
102 From : Positive_Count);
104 procedure Read
105 (File : File_Type;
106 Item : out Stream_Element_Array;
107 Last : out Stream_Element_Offset);
109 procedure Write
110 (File : File_Type;
111 Item : Stream_Element_Array;
112 To : Positive_Count);
114 procedure Write
115 (File : File_Type;
116 Item : Stream_Element_Array);
118 ----------------------------------------
119 -- Operations on Position within File --
120 ----------------------------------------
122 procedure Set_Index (File : File_Type; To : Positive_Count);
124 function Index (File : File_Type) return Positive_Count;
125 function Size (File : File_Type) return Count;
127 procedure Set_Mode (File : in out File_Type; Mode : File_Mode);
129 -- Note: The parameter file is IN OUT in the RM, but this is clearly
130 -- an oversight, and was intended to be IN, see AI95-00057.
132 procedure Flush (File : File_Type);
134 ----------------
135 -- Exceptions --
136 ----------------
138 Status_Error : exception renames IO_Exceptions.Status_Error;
139 Mode_Error : exception renames IO_Exceptions.Mode_Error;
140 Name_Error : exception renames IO_Exceptions.Name_Error;
141 Use_Error : exception renames IO_Exceptions.Use_Error;
142 Device_Error : exception renames IO_Exceptions.Device_Error;
143 End_Error : exception renames IO_Exceptions.End_Error;
144 Data_Error : exception renames IO_Exceptions.Data_Error;
146 private
147 package FCB renames System.File_Control_Block;
149 -----------------------------
150 -- Stream_IO Control Block --
151 -----------------------------
153 type Operation is (Op_Read, Op_Write, Op_Other);
154 -- Type used to record last operation (to optimize sequential operations)
156 type Stream_AFCB is new FCB.AFCB with record
157 Index : Count := 1;
158 -- Current Index value
160 File_Size : Stream_Element_Offset := -1;
161 -- Cached value of File_Size, so that we do not keep recomputing it
162 -- when not necessary (otherwise End_Of_File becomes gruesomely slow).
163 -- A value of minus one means that there is no cached value.
165 Last_Op : Operation := Op_Other;
166 -- Last operation performed on file, used to avoid unnecessary
167 -- repositioning between successive read or write operations.
169 Update_Mode : Boolean := False;
170 -- Set if the mode is changed from write to read or vice versa.
171 -- Indicates that the file has been reopened in update mode.
173 end record;
175 type File_Type is access all Stream_AFCB;
177 function AFCB_Allocate (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
179 procedure AFCB_Close (File : access Stream_AFCB);
180 procedure AFCB_Free (File : access Stream_AFCB);
182 procedure Read
183 (File : in out Stream_AFCB;
184 Item : out Ada.Streams.Stream_Element_Array;
185 Last : out Ada.Streams.Stream_Element_Offset);
186 -- Read operation used when Stream_IO file is treated directly as Stream
188 procedure Write
189 (File : in out Stream_AFCB;
190 Item : Ada.Streams.Stream_Element_Array);
191 -- Write operation used when Stream_IO file is treated directly as Stream
193 end Ada.Streams.Stream_IO;