OSDN Git Service

* doc/install.texi (xtensa-*-elf): New target.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-ststio.ads
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.14 $                             --
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 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
37 --                                                                          --
38 ------------------------------------------------------------------------------
39
40 with Ada.IO_Exceptions;
41 with System.File_Control_Block;
42
43 package Ada.Streams.Stream_IO is
44
45    type Stream_Access is access all Root_Stream_Type'Class;
46
47    type File_Type is limited private;
48
49    type File_Mode is (In_File, Out_File, Append_File);
50
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.
54
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)
59
60    type Count is new Stream_Element_Offset
61      range 0 .. Stream_Element_Offset'Last;
62
63    subtype Positive_Count is Count range 1 .. Count'Last;
64    --  Index into file, in stream elements
65
66    ---------------------
67    -- File Management --
68    ---------------------
69
70    procedure Create
71      (File : in out File_Type;
72       Mode : in File_Mode := Out_File;
73       Name : in String := "";
74       Form : in String := "");
75
76    procedure Open
77      (File : in out File_Type;
78       Mode : in File_Mode;
79       Name : in String;
80       Form : in String := "");
81
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);
86
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;
90
91    function Is_Open     (File : in File_Type) return Boolean;
92    function End_Of_File (File : in File_Type) return Boolean;
93
94    function Stream (File : in File_Type) return Stream_Access;
95
96    -----------------------------
97    -- Input-Output Operations --
98    -----------------------------
99
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);
105
106    procedure Read
107      (File : in  File_Type;
108       Item : out Stream_Element_Array;
109       Last : out Stream_Element_Offset);
110
111    procedure Write
112      (File : in File_Type;
113       Item : in Stream_Element_Array;
114       To   : in Positive_Count);
115
116    procedure Write
117      (File : in File_Type;
118       Item : in Stream_Element_Array);
119
120    ----------------------------------------
121    -- Operations on Position within File --
122    ----------------------------------------
123
124    procedure Set_Index (File : in File_Type; To : in Positive_Count);
125
126    function Index (File : in File_Type) return Positive_Count;
127    function Size  (File : in File_Type) return Count;
128
129    procedure Set_Mode (File : in out File_Type; Mode : in File_Mode);
130
131    procedure Flush (File : in out File_Type);
132
133    ----------------
134    -- Exceptions --
135    ----------------
136
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;
144
145 private
146    package FCB renames System.File_Control_Block;
147
148    -----------------------------
149    -- Stream_IO Control Block --
150    -----------------------------
151
152    type Operation is (Op_Read, Op_Write, Op_Other);
153    --  Type used to record last operation (to optimize sequential operations)
154
155    type Stream_AFCB is new FCB.AFCB with record
156       Index : Count := 1;
157       --  Current Index value
158
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.
163
164       Last_Op : Operation := Op_Other;
165       --  Last operation performed on file, used to avoid unnecessary
166       --  repositioning between successive read or write operations.
167
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.
171
172    end record;
173
174    type File_Type is access all Stream_AFCB;
175
176    function AFCB_Allocate (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
177
178    procedure AFCB_Close (File : access Stream_AFCB);
179    procedure AFCB_Free  (File : access Stream_AFCB);
180
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
186
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
191
192 end Ada.Streams.Stream_IO;