OSDN Git Service

* 41intnam.ads, 42intnam.ads, 4aintnam.ads, 4cintnam.ads,
[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$
10 --                                                                          --
11 --          Copyright (C) 1992-2001 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    --  Note: The parameter file is IN OUT in the RM, but this is clearly
132    --  an oversight, and was intended to be IN, see AI95-00057.
133
134    procedure Flush (File : File_Type);
135
136    ----------------
137    -- Exceptions --
138    ----------------
139
140    Status_Error : exception renames IO_Exceptions.Status_Error;
141    Mode_Error   : exception renames IO_Exceptions.Mode_Error;
142    Name_Error   : exception renames IO_Exceptions.Name_Error;
143    Use_Error    : exception renames IO_Exceptions.Use_Error;
144    Device_Error : exception renames IO_Exceptions.Device_Error;
145    End_Error    : exception renames IO_Exceptions.End_Error;
146    Data_Error   : exception renames IO_Exceptions.Data_Error;
147
148 private
149    package FCB renames System.File_Control_Block;
150
151    -----------------------------
152    -- Stream_IO Control Block --
153    -----------------------------
154
155    type Operation is (Op_Read, Op_Write, Op_Other);
156    --  Type used to record last operation (to optimize sequential operations)
157
158    type Stream_AFCB is new FCB.AFCB with record
159       Index : Count := 1;
160       --  Current Index value
161
162       File_Size : Stream_Element_Offset := -1;
163       --  Cached value of File_Size, so that we do not keep recomputing it
164       --  when not necessary (otherwise End_Of_File becomes gruesomely slow).
165       --  A value of minus one means that there is no cached value.
166
167       Last_Op : Operation := Op_Other;
168       --  Last operation performed on file, used to avoid unnecessary
169       --  repositioning between successive read or write operations.
170
171       Update_Mode : Boolean := False;
172       --  Set if the mode is changed from write to read or vice versa.
173       --  Indicates that the file has been reopened in update mode.
174
175    end record;
176
177    type File_Type is access all Stream_AFCB;
178
179    function AFCB_Allocate (Control_Block : Stream_AFCB) return FCB.AFCB_Ptr;
180
181    procedure AFCB_Close (File : access Stream_AFCB);
182    procedure AFCB_Free  (File : access Stream_AFCB);
183
184    procedure Read
185      (File : in out Stream_AFCB;
186       Item : out Ada.Streams.Stream_Element_Array;
187       Last : out Ada.Streams.Stream_Element_Offset);
188    --  Read operation used when Stream_IO file is treated directly as Stream
189
190    procedure Write
191      (File : in out Stream_AFCB;
192       Item : in Ada.Streams.Stream_Element_Array);
193    --  Write operation used when Stream_IO file is treated directly as Stream
194
195 end Ada.Streams.Stream_IO;