Whole document tree basic_file.hGo to the documentation of this file.00001 // Wrapper of C-language FILE struct -*- C++ -*- 00002 00003 // Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 // 00031 // ISO C++ 14882: 27.8 File-based streams 00032 // 00033 00034 #ifndef _CPP_BASIC_FILE 00035 #define _CPP_BASIC_FILE 1 00036 00037 #pragma GCC system_header 00038 00039 #include <bits/c++config.h> 00040 #include <bits/std_ios.h> 00041 00042 namespace std 00043 { 00044 // Ulrich is going to make some detailed comment here, explaining 00045 // all this unpleasantness, providing detailed performance analysis 00046 // as to why we have to do all this lame vtable hacking instead of a 00047 // sane, function-based approach. This verbiage will provide a clear 00048 // and detailed description of the whole object-layout, 00049 // vtable-swapping, sordid history of this hack. 00050 template<typename _CharT> 00051 struct __basic_file_base: public __c_file_type 00052 { 00053 virtual 00054 ~__basic_file_base() { }; 00055 00056 virtual int 00057 overflow(int __c = EOF) = 0; 00058 00059 virtual int 00060 underflow() = 0; 00061 00062 virtual int 00063 uflow() = 0; 00064 00065 virtual int 00066 pbackfail(int __c) = 0; 00067 00068 virtual streamsize 00069 xsputn(const _CharT* __s, streamsize __n) = 0; 00070 00071 virtual streamsize 00072 xsgetn(_CharT* __s, streamsize __n) = 0; 00073 00074 virtual streamoff 00075 seekoff(streamoff __off, ios_base::seekdir __way, 00076 ios_base::openmode __mode = ios_base::in | ios_base::out) = 0; 00077 00078 virtual streamoff 00079 seekpos(streamoff __pos, 00080 ios_base::openmode __mode = ios_base::in | ios_base::out) = 0; 00081 00082 virtual streambuf* 00083 setbuf(_CharT* __b, int __len) = 0; 00084 00085 virtual int 00086 sync() = 0; 00087 00088 virtual int 00089 doallocate() = 0; 00090 00091 virtual streamsize 00092 sys_read(_CharT* __s, streamsize __n) = 0; 00093 00094 virtual streamsize 00095 sys_write(const _CharT* __s, streamsize __n) = 0; 00096 00097 virtual streamoff 00098 sys_seek(streamoff __off, ios_base::seekdir __way) = 0; 00099 00100 virtual int 00101 sys_close() = 0; 00102 00103 virtual int 00104 sys_stat(void* __v) = 0; 00105 00106 virtual int 00107 showmanyc() = 0; 00108 00109 virtual void 00110 imbue(void* __v) = 0; 00111 }; 00112 00113 // Some of these member functions are based on libio/filebuf.cc. 00114 // Also note that the order and number of virtual functions has to precisely 00115 // match the order and number in the _IO_jump_t struct defined in libioP.h. 00116 template<typename _CharT> 00117 #ifdef _GLIBCPP_BASIC_FILE_INHERITANCE 00118 class __basic_file: public __basic_file_base<_CharT> 00119 #else 00120 class __basic_file 00121 #endif 00122 { 00123 #if _GLIBCPP_BASIC_FILE_ENCAPSULATION 00124 __c_file_type* _M_cfile; 00125 bool _M_cfile_created; 00126 #else 00127 # ifdef _GLIBCPP_USE_WCHAR_T 00128 __c_wfile_type _M_wfile; 00129 # endif 00130 #endif 00131 00132 public: 00133 __basic_file(__c_lock* __lock = 0); 00134 00135 void 00136 _M_open_mode(ios_base::openmode __mode, int& __p_mode, int& __rw_mode, 00137 char* __c_mode); 00138 00139 // Equivalent to the normal fopen function. 00140 __basic_file* 00141 open(const char* __name, ios_base::openmode __mode, int __prot = 0664); 00142 00143 // Used for opening the standard streams, cin, cout, cerr, clog, 00144 // and their wide-stream equivalents. Instead of calling open, it 00145 // just sets __c_file_type->_fileno and the respective _flags bits, and 00146 // returns. 00147 __basic_file* 00148 sys_open(__c_file_type* __file, ios_base::openmode __mode); 00149 00150 _CharT 00151 sys_getc(); 00152 00153 _CharT 00154 sys_ungetc(_CharT); 00155 00156 __basic_file* 00157 close(); 00158 00159 bool 00160 is_open(); 00161 00162 // NB: Must match FILE specific jump table starting here--this 00163 // means all virtual functions starting with the dtor must match, 00164 // slot by slot. For glibc-based dystems, this means the _IO_FILE 00165 // as the FILE struct and _IO_jump_t as the jump table. 00166 virtual 00167 ~__basic_file(); // Takes the place of __finish. 00168 00169 virtual int 00170 overflow(int __c = EOF); 00171 00172 virtual int 00173 underflow(); 00174 00175 virtual int 00176 uflow(); 00177 00178 virtual int 00179 pbackfail(int __c); 00180 00181 // A complex "write" function that sets all of __c_file_type's 00182 // pointers and associated data members correctly and manages its 00183 // relation to the external byte sequence. 00184 virtual streamsize 00185 xsputn(const _CharT* __s, streamsize __n); 00186 00187 // A complex "read" function that sets all of __c_file_type's 00188 // pointers and associated data members correctly and manages its 00189 // relation to the external byte sequence. 00190 virtual streamsize 00191 xsgetn(_CharT* __s, streamsize __n); 00192 00193 // A complex "seekoff" function that sets all of __c_file_type's 00194 // pointers and associated data members correctly and manages its 00195 // relation to the external byte sequence. 00196 virtual streamoff 00197 seekoff(streamoff __off, ios_base::seekdir __way, 00198 ios_base::openmode __mode = ios_base::in | ios_base::out); 00199 00200 // A complex "seekpos" function that sets all of __c_file_type's 00201 // pointers and associated data members correctly and manages its 00202 // relation to the external byte sequence. 00203 virtual streamoff 00204 seekpos(streamoff __pos, 00205 ios_base::openmode __mode = ios_base::in | ios_base::out); 00206 00207 virtual streambuf* 00208 setbuf(_CharT* __b, int __len); 00209 00210 virtual int 00211 sync(); 00212 00213 virtual int 00214 doallocate(); 00215 00216 // A simple read function for the external byte sequence, that 00217 // does no mucking around with or setting of the pointers or flags 00218 // in __c_file_type. 00219 virtual streamsize 00220 sys_read(_CharT* __s, streamsize __n); 00221 00222 // A simple write function for the external byte sequence, that 00223 // does no mucking around with or setting of the pointers or flags 00224 // in __c_file_type. 00225 virtual streamsize 00226 sys_write(const _CharT* __s, streamsize __n); 00227 00228 // A simple seek function for the external byte sequence, that 00229 // does no mucking around with or setting of the pointers or flags 00230 // in __c_file_type. 00231 virtual streamoff 00232 sys_seek(streamoff __off, ios_base::seekdir __way); 00233 00234 virtual int 00235 sys_close(); 00236 00237 virtual int 00238 sys_stat(void* __v); 00239 00240 virtual int 00241 showmanyc(); 00242 00243 virtual void 00244 imbue(void* __v); 00245 }; 00246 } // namespace std 00247 00248 // Now include the bits that are dependant on the underlying I/O 00249 // model chosen at configure time. 00250 #include <bits/basic_file_model.h> 00251 00252 #endif // _CPP_BASIC_FILE Generated on Mon Apr 8 03:11:21 2002 for libstdc++-v3 Source by ![]() |