00001 // File based streams -*- C++ -*- 00002 00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 00004 // Free Software Foundation, Inc. 00005 // 00006 // This file is part of the GNU ISO C++ Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 // 00032 // ISO C++ 14882: 27.8 File-based streams 00033 // 00034 00035 /** @file fstream 00036 * This is a Standard C++ Library header. 00037 */ 00038 00039 #ifndef _GLIBCXX_FSTREAM 00040 #define _GLIBCXX_FSTREAM 1 00041 00042 #pragma GCC system_header 00043 00044 #include <istream> 00045 #include <ostream> 00046 #include <locale> // For codecvt 00047 #include <cstdio> // For SEEK_SET, SEEK_CUR, SEEK_END, BUFSIZ 00048 #include <bits/basic_file.h> 00049 #include <bits/gthr.h> 00050 00051 namespace std 00052 { 00053 // [27.8.1.1] template class basic_filebuf 00054 /** 00055 * @brief The actual work of input and output (for files). 00056 * 00057 * This class associates both its input and output sequence with an 00058 * external disk file, and maintains a joint file position for both 00059 * sequences. Many of its sematics are described in terms of similar 00060 * behavior in the Standard C Library's @c FILE streams. 00061 */ 00062 // Requirements on traits_type, specific to this class: 00063 // traits_type::pos_type must be fpos<traits_type::state_type> 00064 // traits_type::off_type must be streamoff 00065 // traits_type::state_type must be Assignable and DefaultConstructable, 00066 // and traits_type::state_type() must be the initial state for codecvt. 00067 template<typename _CharT, typename _Traits> 00068 class basic_filebuf : public basic_streambuf<_CharT, _Traits> 00069 { 00070 public: 00071 // Types: 00072 typedef _CharT char_type; 00073 typedef _Traits traits_type; 00074 typedef typename traits_type::int_type int_type; 00075 typedef typename traits_type::pos_type pos_type; 00076 typedef typename traits_type::off_type off_type; 00077 00078 typedef basic_streambuf<char_type, traits_type> __streambuf_type; 00079 typedef basic_filebuf<char_type, traits_type> __filebuf_type; 00080 typedef __basic_file<char> __file_type; 00081 typedef typename traits_type::state_type __state_type; 00082 typedef codecvt<char_type, char, __state_type> __codecvt_type; 00083 00084 friend class ios_base; // For sync_with_stdio. 00085 00086 protected: 00087 // Data Members: 00088 // MT lock inherited from libio or other low-level io library. 00089 __c_lock _M_lock; 00090 00091 // External buffer. 00092 __file_type _M_file; 00093 00094 /** 00095 * @if maint 00096 * Place to stash in || out || in | out settings for current filebuf. 00097 * @endif 00098 */ 00099 ios_base::openmode _M_mode; 00100 00101 // Beginning state type for codecvt. 00102 __state_type _M_state_beg; 00103 00104 // During output, the state that corresponds to pptr(), 00105 // during input, the state that corresponds to egptr() and 00106 // _M_ext_next. 00107 __state_type _M_state_cur; 00108 00109 // Not used for output. During input, the state that corresponds 00110 // to eback() and _M_ext_buf. 00111 __state_type _M_state_last; 00112 00113 /** 00114 * @if maint 00115 * Pointer to the beginning of internal buffer. 00116 * @endif 00117 */ 00118 char_type* _M_buf; 00119 00120 /** 00121 * @if maint 00122 * Actual size of internal buffer. This number is equal to the size 00123 * of the put area + 1 position, reserved for the overflow char of 00124 * a full area. 00125 * @endif 00126 */ 00127 size_t _M_buf_size; 00128 00129 // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer. 00130 bool _M_buf_allocated; 00131 00132 /** 00133 * @if maint 00134 * _M_reading == false && _M_writing == false for 'uncommitted' mode; 00135 * _M_reading == true for 'read' mode; 00136 * _M_writing == true for 'write' mode; 00137 * 00138 * NB: _M_reading == true && _M_writing == true is unused. 00139 * @endif 00140 */ 00141 bool _M_reading; 00142 bool _M_writing; 00143 00144 //@{ 00145 /** 00146 * @if maint 00147 * Necessary bits for putback buffer management. 00148 * 00149 * @note pbacks of over one character are not currently supported. 00150 * @endif 00151 */ 00152 char_type _M_pback; 00153 char_type* _M_pback_cur_save; 00154 char_type* _M_pback_end_save; 00155 bool _M_pback_init; 00156 //@} 00157 00158 // Cached codecvt facet. 00159 const __codecvt_type* _M_codecvt; 00160 00161 /** 00162 * @if maint 00163 * Buffer for external characters. Used for input when 00164 * codecvt::always_noconv() == false. When valid, this corresponds 00165 * to eback(). 00166 * @endif 00167 */ 00168 char* _M_ext_buf; 00169 00170 /** 00171 * @if maint 00172 * Size of buffer held by _M_ext_buf. 00173 * @endif 00174 */ 00175 streamsize _M_ext_buf_size; 00176 00177 /** 00178 * @if maint 00179 * Pointers into the buffer held by _M_ext_buf that delimit a 00180 * subsequence of bytes that have been read but not yet converted. 00181 * When valid, _M_ext_next corresponds to egptr(). 00182 * @endif 00183 */ 00184 const char* _M_ext_next; 00185 char* _M_ext_end; 00186 00187 /** 00188 * @if maint 00189 * Initializes pback buffers, and moves normal buffers to safety. 00190 * Assumptions: 00191 * _M_in_cur has already been moved back 00192 * @endif 00193 */ 00194 void 00195 _M_create_pback() 00196 { 00197 if (!_M_pback_init) 00198 { 00199 _M_pback_cur_save = this->gptr(); 00200 _M_pback_end_save = this->egptr(); 00201 this->setg(&_M_pback, &_M_pback, &_M_pback + 1); 00202 _M_pback_init = true; 00203 } 00204 } 00205 00206 /** 00207 * @if maint 00208 * Deactivates pback buffer contents, and restores normal buffer. 00209 * Assumptions: 00210 * The pback buffer has only moved forward. 00211 * @endif 00212 */ 00213 void 00214 _M_destroy_pback() throw() 00215 { 00216 if (_M_pback_init) 00217 { 00218 // Length _M_in_cur moved in the pback buffer. 00219 _M_pback_cur_save += this->gptr() != this->eback(); 00220 this->setg(_M_buf, _M_pback_cur_save, _M_pback_end_save); 00221 _M_pback_init = false; 00222 } 00223 } 00224 00225 public: 00226 // Constructors/destructor: 00227 /** 00228 * @brief Does not open any files. 00229 * 00230 * The default constructor initializes the parent class using its 00231 * own default ctor. 00232 */ 00233 basic_filebuf(); 00234 00235 /** 00236 * @brief The destructor closes the file first. 00237 */ 00238 virtual 00239 ~basic_filebuf() 00240 { this->close(); } 00241 00242 // Members: 00243 /** 00244 * @brief Returns true if the external file is open. 00245 */ 00246 bool 00247 is_open() const throw() 00248 { return _M_file.is_open(); } 00249 00250 /** 00251 * @brief Opens an external file. 00252 * @param s The name of the file. 00253 * @param mode The open mode flags. 00254 * @return @c this on success, NULL on failure 00255 * 00256 * If a file is already open, this function immediately fails. 00257 * Otherwise it tries to open the file named @a s using the flags 00258 * given in @a mode. 00259 * 00260 * [Table 92 gives the relation between openmode combinations and the 00261 * equivalent fopen() flags, but the table has not been copied yet.] 00262 */ 00263 __filebuf_type* 00264 open(const char* __s, ios_base::openmode __mode); 00265 00266 /** 00267 * @brief Closes the currently associated file. 00268 * @return @c this on success, NULL on failure 00269 * 00270 * If no file is currently open, this function immediately fails. 00271 * 00272 * If a "put buffer area" exists, @c overflow(eof) is called to flush 00273 * all the characters. The file is then closed. 00274 * 00275 * If any operations fail, this function also fails. 00276 */ 00277 __filebuf_type* 00278 close() throw(); 00279 00280 protected: 00281 void 00282 _M_allocate_internal_buffer(); 00283 00284 void 00285 _M_destroy_internal_buffer() throw(); 00286 00287 // [27.8.1.4] overridden virtual functions 00288 virtual streamsize 00289 showmanyc(); 00290 00291 // Stroustrup, 1998, p. 628 00292 // underflow() and uflow() functions are called to get the next 00293 // charater from the real input source when the buffer is empty. 00294 // Buffered input uses underflow() 00295 00296 virtual int_type 00297 underflow(); 00298 00299 virtual int_type 00300 pbackfail(int_type __c = _Traits::eof()); 00301 00302 // Stroustrup, 1998, p 648 00303 // The overflow() function is called to transfer characters to the 00304 // real output destination when the buffer is full. A call to 00305 // overflow(c) outputs the contents of the buffer plus the 00306 // character c. 00307 // 27.5.2.4.5 00308 // Consume some sequence of the characters in the pending sequence. 00309 virtual int_type 00310 overflow(int_type __c = _Traits::eof()); 00311 00312 // Convert internal byte sequence to external, char-based 00313 // sequence via codecvt. 00314 bool 00315 _M_convert_to_external(char_type*, streamsize); 00316 00317 /** 00318 * @brief Manipulates the buffer. 00319 * @param s Pointer to a buffer area. 00320 * @param n Size of @a s. 00321 * @return @c this 00322 * 00323 * If no file has been opened, and both @a s and @a n are zero, then 00324 * the stream becomes unbuffered. Otherwise, @c s is used as a 00325 * buffer; see 00326 * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 00327 * for more. 00328 */ 00329 virtual __streambuf_type* 00330 setbuf(char_type* __s, streamsize __n); 00331 00332 virtual pos_type 00333 seekoff(off_type __off, ios_base::seekdir __way, 00334 ios_base::openmode __mode = ios_base::in | ios_base::out); 00335 00336 virtual pos_type 00337 seekpos(pos_type __pos, 00338 ios_base::openmode __mode = ios_base::in | ios_base::out); 00339 00340 // Common code for seekoff and seekpos 00341 pos_type 00342 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state); 00343 00344 virtual int 00345 sync(); 00346 00347 virtual void 00348 imbue(const locale& __loc); 00349 00350 virtual streamsize 00351 xsgetn(char_type* __s, streamsize __n); 00352 00353 virtual streamsize 00354 xsputn(const char_type* __s, streamsize __n); 00355 00356 // Flushes output buffer, then writes unshift sequence. 00357 bool 00358 _M_terminate_output(); 00359 00360 /** 00361 * @if maint 00362 * This function sets the pointers of the internal buffer, both get 00363 * and put areas. Typically: 00364 * 00365 * __off == egptr() - eback() upon underflow/uflow ('read' mode); 00366 * __off == 0 upon overflow ('write' mode); 00367 * __off == -1 upon open, setbuf, seekoff/pos ('uncommitted' mode). 00368 * 00369 * NB: epptr() - pbase() == _M_buf_size - 1, since _M_buf_size 00370 * reflects the actual allocated memory and the last cell is reserved 00371 * for the overflow char of a full put area. 00372 * @endif 00373 */ 00374 void 00375 _M_set_buffer(streamsize __off) 00376 { 00377 const bool __testin = _M_mode & ios_base::in; 00378 const bool __testout = _M_mode & ios_base::out; 00379 00380 if (__testin && __off > 0) 00381 this->setg(_M_buf, _M_buf, _M_buf + __off); 00382 else 00383 this->setg(_M_buf, _M_buf, _M_buf); 00384 00385 if (__testout && __off == 0 && _M_buf_size > 1 ) 00386 this->setp(_M_buf, _M_buf + _M_buf_size - 1); 00387 else 00388 this->setp(NULL, NULL); 00389 } 00390 }; 00391 00392 // [27.8.1.5] Template class basic_ifstream 00393 /** 00394 * @brief Controlling input for files. 00395 * 00396 * This class supports reading from named files, using the inherited 00397 * functions from std::basic_istream. To control the associated 00398 * sequence, an instance of std::basic_filebuf is used, which this page 00399 * refers to as @c sb. 00400 */ 00401 template<typename _CharT, typename _Traits> 00402 class basic_ifstream : public basic_istream<_CharT, _Traits> 00403 { 00404 public: 00405 // Types: 00406 typedef _CharT char_type; 00407 typedef _Traits traits_type; 00408 typedef typename traits_type::int_type int_type; 00409 typedef typename traits_type::pos_type pos_type; 00410 typedef typename traits_type::off_type off_type; 00411 00412 // Non-standard types: 00413 typedef basic_filebuf<char_type, traits_type> __filebuf_type; 00414 typedef basic_istream<char_type, traits_type> __istream_type; 00415 00416 private: 00417 __filebuf_type _M_filebuf; 00418 00419 public: 00420 // Constructors/Destructors: 00421 /** 00422 * @brief Default constructor. 00423 * 00424 * Initializes @c sb using its default constructor, and passes 00425 * @c &sb to the base class initializer. Does not open any files 00426 * (you haven't given it a filename to open). 00427 */ 00428 basic_ifstream() : __istream_type(), _M_filebuf() 00429 { this->init(&_M_filebuf); } 00430 00431 /** 00432 * @brief Create an input file stream. 00433 * @param s Null terminated string specifying the filename. 00434 * @param mode Open file in specified mode (see std::ios_base). 00435 * 00436 * @c ios_base::in is automatically included in @a mode. 00437 * 00438 * Tip: When using std::string to hold the filename, you must use 00439 * .c_str() before passing it to this constructor. 00440 */ 00441 explicit 00442 basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in) 00443 : __istream_type(), _M_filebuf() 00444 { 00445 this->init(&_M_filebuf); 00446 this->open(__s, __mode); 00447 } 00448 00449 /** 00450 * @brief The destructor does nothing. 00451 * 00452 * The file is closed by the filebuf object, not the formatting 00453 * stream. 00454 */ 00455 ~basic_ifstream() 00456 { } 00457 00458 // Members: 00459 /** 00460 * @brief Accessing the underlying buffer. 00461 * @return The current basic_filebuf buffer. 00462 * 00463 * This hides both signatures of std::basic_ios::rdbuf(). 00464 */ 00465 __filebuf_type* 00466 rdbuf() const 00467 { return const_cast<__filebuf_type*>(&_M_filebuf); } 00468 00469 /** 00470 * @brief Wrapper to test for an open file. 00471 * @return @c rdbuf()->is_open() 00472 */ 00473 bool 00474 is_open() 00475 { return _M_filebuf.is_open(); } 00476 00477 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00478 // 365. Lack of const-qualification in clause 27 00479 bool 00480 is_open() const 00481 { return _M_filebuf.is_open(); } 00482 00483 /** 00484 * @brief Opens an external file. 00485 * @param s The name of the file. 00486 * @param mode The open mode flags. 00487 * 00488 * Calls @c std::basic_filebuf::open(s,mode|in). If that function 00489 * fails, @c failbit is set in the stream's error state. 00490 * 00491 * Tip: When using std::string to hold the filename, you must use 00492 * .c_str() before passing it to this constructor. 00493 */ 00494 void 00495 open(const char* __s, ios_base::openmode __mode = ios_base::in) 00496 { 00497 if (!_M_filebuf.open(__s, __mode | ios_base::in)) 00498 this->setstate(ios_base::failbit); 00499 } 00500 00501 /** 00502 * @brief Close the file. 00503 * 00504 * Calls @c std::basic_filebuf::close(). If that function 00505 * fails, @c failbit is set in the stream's error state. 00506 */ 00507 void 00508 close() 00509 { 00510 if (!_M_filebuf.close()) 00511 this->setstate(ios_base::failbit); 00512 } 00513 }; 00514 00515 00516 // [27.8.1.8] Template class basic_ofstream 00517 /** 00518 * @brief Controlling output for files. 00519 * 00520 * This class supports reading from named files, using the inherited 00521 * functions from std::basic_ostream. To control the associated 00522 * sequence, an instance of std::basic_filebuf is used, which this page 00523 * refers to as @c sb. 00524 */ 00525 template<typename _CharT, typename _Traits> 00526 class basic_ofstream : public basic_ostream<_CharT,_Traits> 00527 { 00528 public: 00529 // Types: 00530 typedef _CharT char_type; 00531 typedef _Traits traits_type; 00532 typedef typename traits_type::int_type int_type; 00533 typedef typename traits_type::pos_type pos_type; 00534 typedef typename traits_type::off_type off_type; 00535 00536 // Non-standard types: 00537 typedef basic_filebuf<char_type, traits_type> __filebuf_type; 00538 typedef basic_ostream<char_type, traits_type> __ostream_type; 00539 00540 private: 00541 __filebuf_type _M_filebuf; 00542 00543 public: 00544 // Constructors: 00545 /** 00546 * @brief Default constructor. 00547 * 00548 * Initializes @c sb using its default constructor, and passes 00549 * @c &sb to the base class initializer. Does not open any files 00550 * (you haven't given it a filename to open). 00551 */ 00552 basic_ofstream(): __ostream_type(), _M_filebuf() 00553 { this->init(&_M_filebuf); } 00554 00555 /** 00556 * @brief Create an output file stream. 00557 * @param s Null terminated string specifying the filename. 00558 * @param mode Open file in specified mode (see std::ios_base). 00559 * 00560 * @c ios_base::out|ios_base::trunc is automatically included in 00561 * @a mode. 00562 * 00563 * Tip: When using std::string to hold the filename, you must use 00564 * .c_str() before passing it to this constructor. 00565 */ 00566 explicit 00567 basic_ofstream(const char* __s, 00568 ios_base::openmode __mode = ios_base::out|ios_base::trunc) 00569 : __ostream_type(), _M_filebuf() 00570 { 00571 this->init(&_M_filebuf); 00572 this->open(__s, __mode); 00573 } 00574 00575 /** 00576 * @brief The destructor does nothing. 00577 * 00578 * The file is closed by the filebuf object, not the formatting 00579 * stream. 00580 */ 00581 ~basic_ofstream() 00582 { } 00583 00584 // Members: 00585 /** 00586 * @brief Accessing the underlying buffer. 00587 * @return The current basic_filebuf buffer. 00588 * 00589 * This hides both signatures of std::basic_ios::rdbuf(). 00590 */ 00591 __filebuf_type* 00592 rdbuf() const 00593 { return const_cast<__filebuf_type*>(&_M_filebuf); } 00594 00595 /** 00596 * @brief Wrapper to test for an open file. 00597 * @return @c rdbuf()->is_open() 00598 */ 00599 bool 00600 is_open() 00601 { return _M_filebuf.is_open(); } 00602 00603 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00604 // 365. Lack of const-qualification in clause 27 00605 bool 00606 is_open() const 00607 { return _M_filebuf.is_open(); } 00608 00609 /** 00610 * @brief Opens an external file. 00611 * @param s The name of the file. 00612 * @param mode The open mode flags. 00613 * 00614 * Calls @c std::basic_filebuf::open(s,mode|out|trunc). If that 00615 * function fails, @c failbit is set in the stream's error state. 00616 * 00617 * Tip: When using std::string to hold the filename, you must use 00618 * .c_str() before passing it to this constructor. 00619 */ 00620 void 00621 open(const char* __s, 00622 ios_base::openmode __mode = ios_base::out | ios_base::trunc) 00623 { 00624 if (!_M_filebuf.open(__s, __mode | ios_base::out)) 00625 this->setstate(ios_base::failbit); 00626 } 00627 00628 /** 00629 * @brief Close the file. 00630 * 00631 * Calls @c std::basic_filebuf::close(). If that function 00632 * fails, @c failbit is set in the stream's error state. 00633 */ 00634 void 00635 close() 00636 { 00637 if (!_M_filebuf.close()) 00638 this->setstate(ios_base::failbit); 00639 } 00640 }; 00641 00642 00643 // [27.8.1.11] Template class basic_fstream 00644 /** 00645 * @brief Controlling intput and output for files. 00646 * 00647 * This class supports reading from and writing to named files, using 00648 * the inherited functions from std::basic_iostream. To control the 00649 * associated sequence, an instance of std::basic_filebuf is used, which 00650 * this page refers to as @c sb. 00651 */ 00652 template<typename _CharT, typename _Traits> 00653 class basic_fstream : public basic_iostream<_CharT, _Traits> 00654 { 00655 public: 00656 // Types: 00657 typedef _CharT char_type; 00658 typedef _Traits traits_type; 00659 typedef typename traits_type::int_type int_type; 00660 typedef typename traits_type::pos_type pos_type; 00661 typedef typename traits_type::off_type off_type; 00662 00663 // Non-standard types: 00664 typedef basic_filebuf<char_type, traits_type> __filebuf_type; 00665 typedef basic_ios<char_type, traits_type> __ios_type; 00666 typedef basic_iostream<char_type, traits_type> __iostream_type; 00667 00668 private: 00669 __filebuf_type _M_filebuf; 00670 00671 public: 00672 // Constructors/destructor: 00673 /** 00674 * @brief Default constructor. 00675 * 00676 * Initializes @c sb using its default constructor, and passes 00677 * @c &sb to the base class initializer. Does not open any files 00678 * (you haven't given it a filename to open). 00679 */ 00680 basic_fstream() 00681 : __iostream_type(), _M_filebuf() 00682 { this->init(&_M_filebuf); } 00683 00684 /** 00685 * @brief Create an input/output file stream. 00686 * @param s Null terminated string specifying the filename. 00687 * @param mode Open file in specified mode (see std::ios_base). 00688 * 00689 * Tip: When using std::string to hold the filename, you must use 00690 * .c_str() before passing it to this constructor. 00691 */ 00692 explicit 00693 basic_fstream(const char* __s, 00694 ios_base::openmode __mode = ios_base::in | ios_base::out) 00695 : __iostream_type(NULL), _M_filebuf() 00696 { 00697 this->init(&_M_filebuf); 00698 this->open(__s, __mode); 00699 } 00700 00701 /** 00702 * @brief The destructor does nothing. 00703 * 00704 * The file is closed by the filebuf object, not the formatting 00705 * stream. 00706 */ 00707 ~basic_fstream() 00708 { } 00709 00710 // Members: 00711 /** 00712 * @brief Accessing the underlying buffer. 00713 * @return The current basic_filebuf buffer. 00714 * 00715 * This hides both signatures of std::basic_ios::rdbuf(). 00716 */ 00717 __filebuf_type* 00718 rdbuf() const 00719 { return const_cast<__filebuf_type*>(&_M_filebuf); } 00720 00721 /** 00722 * @brief Wrapper to test for an open file. 00723 * @return @c rdbuf()->is_open() 00724 */ 00725 bool 00726 is_open() 00727 { return _M_filebuf.is_open(); } 00728 00729 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00730 // 365. Lack of const-qualification in clause 27 00731 bool 00732 is_open() const 00733 { return _M_filebuf.is_open(); } 00734 00735 /** 00736 * @brief Opens an external file. 00737 * @param s The name of the file. 00738 * @param mode The open mode flags. 00739 * 00740 * Calls @c std::basic_filebuf::open(s,mode). If that 00741 * function fails, @c failbit is set in the stream's error state. 00742 * 00743 * Tip: When using std::string to hold the filename, you must use 00744 * .c_str() before passing it to this constructor. 00745 */ 00746 void 00747 open(const char* __s, 00748 ios_base::openmode __mode = ios_base::in | ios_base::out) 00749 { 00750 if (!_M_filebuf.open(__s, __mode)) 00751 this->setstate(ios_base::failbit); 00752 } 00753 00754 /** 00755 * @brief Close the file. 00756 * 00757 * Calls @c std::basic_filebuf::close(). If that function 00758 * fails, @c failbit is set in the stream's error state. 00759 */ 00760 void 00761 close() 00762 { 00763 if (!_M_filebuf.close()) 00764 this->setstate(ios_base::failbit); 00765 } 00766 }; 00767 } // namespace std 00768 00769 #ifndef _GLIBCXX_EXPORT_TEMPLATE 00770 # include <bits/fstream.tcc> 00771 #endif 00772 00773 #endif /* _GLIBCXX_FSTREAM */