1 // Wrapper of C-language FILE struct -*- C++ -*-
3 // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 27.8 File-based streams
34 /** @file basic_file.h
35 * This is an internal header file, included by other library headers.
36 * You should not attempt to use it directly.
39 #ifndef _CPP_BASIC_FILE
40 #define _CPP_BASIC_FILE 1
42 #pragma GCC system_header
44 #include <bits/c++config.h>
49 // Ulrich is going to make some detailed comment here, explaining
50 // all this unpleasantness, providing detailed performance analysis
51 // as to why we have to do all this lame vtable hacking instead of a
52 // sane, function-based approach. This verbiage will provide a clear
53 // and detailed description of the whole object-layout,
54 // vtable-swapping, sordid history of this hack.
55 template<typename _CharT
>
56 struct __basic_file_base
: public __c_file_type
59 ~__basic_file_base() { };
62 overflow(int __c
= EOF
) = 0;
71 pbackfail(int __c
) = 0;
74 xsputn(const _CharT
* __s
, streamsize __n
) = 0;
77 xsgetn(_CharT
* __s
, streamsize __n
) = 0;
80 seekoff(streamoff __off
, ios_base::seekdir __way
,
81 ios_base::openmode __mode
= ios_base::in
| ios_base::out
) = 0;
84 seekpos(streamoff __pos
,
85 ios_base::openmode __mode
= ios_base::in
| ios_base::out
) = 0;
88 setbuf(_CharT
* __b
, int __len
) = 0;
97 sys_read(_CharT
* __s
, streamsize __n
) = 0;
100 sys_write(const _CharT
* __s
, streamsize __n
) = 0;
103 sys_seek(streamoff __off
, ios_base::seekdir __way
) = 0;
109 sys_stat(void* __v
) = 0;
115 imbue(void* __v
) = 0;
118 // Some of these member functions are based on libio/filebuf.cc.
119 // Also note that the order and number of virtual functions has to precisely
120 // match the order and number in the _IO_jump_t struct defined in libioP.h.
121 template<typename _CharT
>
122 #ifdef _GLIBCPP_BASIC_FILE_INHERITANCE
123 class __basic_file
: public __basic_file_base
<_CharT
>
128 #if _GLIBCPP_BASIC_FILE_ENCAPSULATION
129 // underlying data source/sink
130 __c_file_type
* _M_cfile
;
131 // true iff we opened _M_cfile, and thus must close it ourselves
132 bool _M_cfile_created
;
134 # ifdef _GLIBCPP_USE_WCHAR_T
135 __c_wfile_type _M_wfile
;
140 __basic_file(__c_lock
* __lock
= 0);
143 _M_open_mode(ios_base::openmode __mode
, int& __p_mode
, int& __rw_mode
,
146 // Equivalent to the normal fopen function.
148 open(const char* __name
, ios_base::openmode __mode
, int __prot
= 0664);
150 // Used for opening the standard streams, cin, cout, cerr, clog,
151 // and their wide-stream equivalents. Instead of calling open, it
153 // - for libio: __c_file_type->_fileno and the respective _flags bits
154 // - for stdio: _M_cfile = __file and some internal flags
157 sys_open(__c_file_type
* __file
, ios_base::openmode __mode
);
174 // NB: Must match FILE specific jump table starting here--this
175 // means all virtual functions starting with the dtor must match,
176 // slot by slot. For glibc-based dystems, this means the _IO_FILE
177 // as the FILE struct and _IO_jump_t as the jump table.
179 ~__basic_file(); // Takes the place of __finish.
182 overflow(int __c
= EOF
);
193 // A complex "write" function that sets all of __c_file_type's
194 // pointers and associated data members correctly and manages its
195 // relation to the external byte sequence.
197 xsputn(const _CharT
* __s
, streamsize __n
);
199 // A complex "read" function that sets all of __c_file_type's
200 // pointers and associated data members correctly and manages its
201 // relation to the external byte sequence.
203 xsgetn(_CharT
* __s
, streamsize __n
);
205 // A complex "seekoff" function that sets all of __c_file_type's
206 // pointers and associated data members correctly and manages its
207 // relation to the external byte sequence.
209 seekoff(streamoff __off
, ios_base::seekdir __way
,
210 ios_base::openmode __mode
= ios_base::in
| ios_base::out
);
212 // A complex "seekpos" function that sets all of __c_file_type's
213 // pointers and associated data members correctly and manages its
214 // relation to the external byte sequence.
216 seekpos(streamoff __pos
,
217 ios_base::openmode __mode
= ios_base::in
| ios_base::out
);
220 setbuf(_CharT
* __b
, int __len
);
228 // A simple read function for the external byte sequence, that
229 // does no mucking around with or setting of the pointers or flags
232 sys_read(_CharT
* __s
, streamsize __n
);
234 // A simple write function for the external byte sequence, that
235 // does no mucking around with or setting of the pointers or flags
238 sys_write(const _CharT
* __s
, streamsize __n
);
240 // A simple seek function for the external byte sequence, that
241 // does no mucking around with or setting of the pointers or flags
244 sys_seek(streamoff __off
, ios_base::seekdir __way
);
260 // Now include the bits that are dependent on the underlying I/O
261 // model chosen at configure time.
262 #include <bits/basic_file_model.h>
264 #endif // _CPP_BASIC_FILE