ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

_fstream.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 // This header defines classes basic_filebuf, basic_ifstream,
00019 // basic_ofstream, and basic_fstream.  These classes represent
00020 // streambufs and streams whose sources or destinations are files.
00021 
00022 #ifndef _STLP_INTERNAL_FSTREAM_H
00023 #define _STLP_INTERNAL_FSTREAM_H
00024 
00025 #if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
00026 #  error This header file requires the -LANG:std option
00027 #endif
00028 
00029 #ifndef _STLP_INTERNAL_STREAMBUF
00030 #  include <stl/_streambuf.h>
00031 #endif
00032 
00033 #ifndef _STLP_INTERNAL_ISTREAM
00034 #  include <stl/_istream.h>
00035 #endif
00036 
00037 #ifndef _STLP_INTERNAL_CODECVT_H
00038 #  include <stl/_codecvt.h>
00039 #endif
00040 
00041 #if defined (_STLP_USE_WIN32_IO)
00042 typedef void* _STLP_fd;
00043 #elif defined (_STLP_USE_UNIX_EMULATION_IO) || defined (_STLP_USE_STDIO_IO) || defined (_STLP_USE_UNIX_IO)
00044 typedef int _STLP_fd;
00045 #else
00046 #  error "Configure i/o !"
00047 #endif
00048 
00049 _STLP_BEGIN_NAMESPACE
00050 
00051 //----------------------------------------------------------------------
00052 // Class _Filebuf_base, a private base class to factor out the system-
00053 // dependent code from basic_filebuf<>.
00054 
00055 class _STLP_CLASS_DECLSPEC _Filebuf_base {
00056 public:                      // Opening and closing files.
00057   _Filebuf_base();
00058 
00059   bool _M_open(const char*, ios_base::openmode, long __protection);
00060   bool _M_open(const char*, ios_base::openmode);
00061   bool _M_open(int __id, ios_base::openmode = ios_base::__default_mode);
00062 #if defined (_STLP_USE_WIN32_IO)
00063   bool _M_open(_STLP_fd __id, ios_base::openmode = ios_base::__default_mode);
00064 #endif /* _STLP_USE_WIN32_IO */
00065   bool _M_close();
00066 
00067 public:                      // Low-level I/O, like Unix read/write
00068   ptrdiff_t _M_read(char* __buf,  ptrdiff_t __n);
00069   streamoff _M_seek(streamoff __offset, ios_base::seekdir __dir);
00070   streamoff _M_file_size();
00071   bool _M_write(char* __buf,  ptrdiff_t __n);
00072 
00073 public:                      // Memory-mapped I/O.
00074   void* _M_mmap(streamoff __offset, streamoff __len);
00075   void _M_unmap(void* __mmap_base, streamoff __len);
00076 
00077 public:
00078   // Returns a value n such that, if pos is the file pointer at the
00079   // beginning of the range [first, last), pos + n is the file pointer at
00080   // the end.  On many operating systems n == __last - __first.
00081   // In Unix, writing n characters always bumps the file position by n.
00082   // In Windows text mode, however, it bumps the file position by n + m,
00083   // where m is the number of newlines in the range.  That's because an
00084   // internal \n corresponds to an external two-character sequence.
00085   streamoff _M_get_offset(char* __first, char* __last) {
00086 #if defined (_STLP_UNIX) || defined (_STLP_MAC)
00087     return __last - __first;
00088 #else // defined (_STLP_WIN32)
00089     return ( (_M_openmode & ios_base::binary) != 0 )
00090       ? (__last - __first)
00091       : count(__first, __last, '\n') + (__last - __first);
00092 #endif
00093   }
00094 
00095   // Returns true if we're in binary mode or if we're using an OS or file
00096   // system where there is no distinction between text and binary mode.
00097   bool _M_in_binary_mode() const {
00098 #if defined (_STLP_UNIX) || defined (_STLP_MAC) || defined(__BEOS__) || defined (__amigaos__)
00099     return true;
00100 #elif defined (_STLP_WIN32) || defined (_STLP_VM)
00101     return (_M_openmode & ios_base::binary) != 0;
00102 #else
00103 #  error "Port!"
00104 #endif
00105   }
00106 
00107   static void _S_initialize();
00108 
00109 protected:                      // Static data members.
00110   static size_t _M_page_size;
00111 
00112 protected:                      // Data members.
00113   _STLP_fd _M_file_id;
00114 #if defined (_STLP_USE_STDIO_IO)
00115   // for stdio, the whole FILE* is being kept here
00116   FILE* _M_file;
00117 #endif
00118   ios_base::openmode _M_openmode     ;
00119   unsigned char      _M_is_open      ;
00120   unsigned char      _M_should_close ;
00121   unsigned char      _M_regular_file ;
00122 
00123 #if defined (_STLP_USE_WIN32_IO)
00124   _STLP_fd _M_view_id;
00125 #endif
00126 
00127 public :
00128   static size_t  _STLP_CALL __page_size() { return _M_page_size; }
00129   int  __o_mode() const { return (int)_M_openmode; }
00130   bool __is_open()      const { return (_M_is_open !=0 ); }
00131   bool __should_close() const { return (_M_should_close != 0); }
00132   bool __regular_file() const { return (_M_regular_file != 0); }
00133   _STLP_fd __get_fd() const { return _M_file_id; }
00134 };
00135 
00136 //----------------------------------------------------------------------
00137 // Class basic_filebuf<>.
00138 
00139 // Forward declaration of two helper classes.
00140 template <class _Traits> class _Noconv_input;
00141 template <class _Traits> class _Noconv_output;
00142 
00143 // There is a specialized version of underflow, for basic_filebuf<char>,
00144 // in fstream.cpp.
00145 template <class _CharT, class _Traits>
00146 class _Underflow;
00147 
00148 template <class _CharT, class _Traits>
00149 class basic_filebuf : public basic_streambuf<_CharT, _Traits> {
00150 public:                         // Types.
00151   typedef _CharT                     char_type;
00152   typedef typename _Traits::int_type int_type;
00153   typedef typename _Traits::pos_type pos_type;
00154   typedef typename _Traits::off_type off_type;
00155   typedef _Traits                    traits_type;
00156 
00157   typedef typename _Traits::state_type _State_type;
00158   typedef basic_streambuf<_CharT, _Traits> _Base;
00159   typedef basic_filebuf<_CharT, _Traits> _Self;
00160 
00161 public:                         // Constructors, destructor.
00162   basic_filebuf();
00163   ~basic_filebuf();
00164 
00165 public:                         // Opening and closing files.
00166   bool is_open() const { return _M_base.__is_open(); }
00167 
00168   _Self* open(const char* __s, ios_base::openmode __m) {
00169     return _M_base._M_open(__s, __m) ? this : 0;
00170   }
00171 
00172 #if !defined (_STLP_NO_EXTENSIONS)
00173   // These two version of open() and file descriptor getter are extensions.
00174   _Self* open(const char* __s, ios_base::openmode __m,
00175               long __protection) {
00176     return _M_base._M_open(__s, __m, __protection) ? this : 0;
00177   }
00178 
00179   _STLP_fd fd() const { return _M_base.__get_fd(); }
00180 
00181   _Self* open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
00182     return this->_M_open(__id, _Init_mode);
00183   }
00184 
00185 #  if defined (_STLP_USE_WIN32_IO)
00186   _Self* open(_STLP_fd __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
00187     return _M_base._M_open(__id, _Init_mode) ? this : 0;
00188   }
00189 #  endif /* _STLP_USE_WIN32_IO */
00190 
00191 #endif
00192 
00193   _Self* _M_open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
00194     return _M_base._M_open(__id, _Init_mode) ? this : 0;
00195   }
00196 
00197   _Self* close();
00198 
00199 protected:                      // Virtual functions from basic_streambuf.
00200   virtual streamsize showmanyc();
00201   virtual int_type underflow();
00202 
00203   virtual int_type pbackfail(int_type = traits_type::eof());
00204   virtual int_type overflow(int_type = traits_type::eof());
00205 
00206   virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
00207   virtual pos_type seekoff(off_type, ios_base::seekdir,
00208                            ios_base::openmode = ios_base::in | ios_base::out);
00209   virtual pos_type seekpos(pos_type,
00210                            ios_base::openmode = ios_base::in | ios_base::out);
00211 
00212   virtual int sync();
00213   virtual void imbue(const locale&);
00214 
00215 private:                        // Helper functions.
00216 
00217   // Precondition: we are currently in putback input mode.  Effect:
00218   // switches back to ordinary input mode.
00219   void _M_exit_putback_mode() {
00220     this->setg(_M_saved_eback, _M_saved_gptr, _M_saved_egptr);
00221     _M_in_putback_mode = false;
00222   }
00223   bool _M_switch_to_input_mode();
00224   void _M_exit_input_mode();
00225   bool _M_switch_to_output_mode();
00226 
00227   int_type _M_input_error();
00228   int_type _M_underflow_aux();
00229   friend class _Underflow<_CharT, _Traits>;
00230 
00231   int_type _M_output_error();
00232   bool _M_unshift();
00233 
00234   bool _M_allocate_buffers(_CharT* __buf, streamsize __n);
00235   bool _M_allocate_buffers();
00236   void _M_deallocate_buffers();
00237 
00238   pos_type _M_seek_return(off_type __off, _State_type __state) {
00239     if (__off != -1) {
00240       if (_M_in_input_mode)
00241         _M_exit_input_mode();
00242       _M_in_input_mode = false;
00243       _M_in_output_mode = false;
00244       _M_in_putback_mode = false;
00245       _M_in_error_mode = false;
00246       this->setg(0, 0, 0);
00247       this->setp(0, 0);
00248     }
00249 
00250     pos_type __result(__off);
00251     __result.state(__state);
00252     return __result;
00253   }
00254 
00255   bool _M_seek_init(bool __do_unshift);
00256 
00257   void _M_setup_codecvt(const locale&, bool __on_imbue = true);
00258 
00259 private:                        // Data members used in all modes.
00260 
00261   _Filebuf_base _M_base;
00262 
00263 private:                        // Locale-related information.
00264 
00265   unsigned char _M_constant_width;
00266   unsigned char _M_always_noconv;
00267 
00268   // private:                        // Mode flags.
00269   unsigned char _M_int_buf_dynamic;  // True if internal buffer is heap allocated,
00270   // false if it was supplied by the user.
00271   unsigned char _M_in_input_mode;
00272   unsigned char _M_in_output_mode;
00273   unsigned char _M_in_error_mode;
00274   unsigned char _M_in_putback_mode;
00275 
00276   // Internal buffer: characters seen by the filebuf's clients.
00277   _CharT* _M_int_buf;
00278   _CharT* _M_int_buf_EOS;
00279 
00280   // External buffer: characters corresponding to the external file.
00281   char* _M_ext_buf;
00282   char* _M_ext_buf_EOS;
00283 
00284   // The range [_M_ext_buf, _M_ext_buf_converted) contains the external
00285   // characters corresponding to the sequence in the internal buffer.  The
00286   // range [_M_ext_buf_converted, _M_ext_buf_end) contains characters that
00287   // have been read into the external buffer but have not been converted
00288   // to an internal sequence.
00289   char* _M_ext_buf_converted;
00290   char* _M_ext_buf_end;
00291 
00292   // State corresponding to beginning of internal buffer.
00293   _State_type _M_state;
00294 
00295 private:                        // Data members used only in input mode.
00296 
00297   // Similar to _M_state except that it corresponds to
00298   // the end of the internal buffer instead of the beginning.
00299   _State_type _M_end_state;
00300 
00301   // This is a null pointer unless we are in mmap input mode.
00302   void*     _M_mmap_base;
00303   streamoff _M_mmap_len;
00304 
00305 private:                        // Data members used only in putback mode.
00306   _CharT* _M_saved_eback;
00307   _CharT* _M_saved_gptr;
00308   _CharT* _M_saved_egptr;
00309 
00310   typedef codecvt<_CharT, char, _State_type> _Codecvt;
00311   const _Codecvt* _M_codecvt;
00312 
00313   int _M_width;                 // Width of the encoding (if constant), else 1
00314   int _M_max_width;             // Largest possible width of single character.
00315 
00316 
00317   enum { _S_pback_buf_size = 8 };
00318   _CharT _M_pback_buf[_S_pback_buf_size];
00319 
00320   // for _Noconv_output
00321 public:
00322   bool _M_write(char* __buf,  ptrdiff_t __n) {return _M_base._M_write(__buf, __n); }
00323 
00324 public:
00325   int_type
00326   _M_do_noconv_input() {
00327     _M_ext_buf_converted = _M_ext_buf_end;
00328     /* this-> */ _Base::setg((char_type*)_M_ext_buf, (char_type*)_M_ext_buf, (char_type*)_M_ext_buf_end);
00329     return traits_type::to_int_type(*_M_ext_buf);
00330   }
00331 };
00332 
00333 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00334 _STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<char, char_traits<char> >;
00335 #  if ! defined (_STLP_NO_WCHAR_T)
00336 _STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<wchar_t, char_traits<wchar_t> >;
00337 #  endif
00338 #endif /* _STLP_USE_TEMPLATE_EXPORT */
00339 
00340 //
00341 // This class had to be designed very carefully to work
00342 // with Visual C++.
00343 //
00344 template <class _Traits>
00345 class _Noconv_output {
00346 public:
00347   typedef typename _Traits::char_type char_type;
00348   static bool  _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits >*,
00349                                   char_type*, char_type*)
00350   { return false; }
00351 };
00352 
00353 _STLP_TEMPLATE_NULL
00354 class _STLP_CLASS_DECLSPEC _Noconv_output< char_traits<char> > {
00355 public:
00356   static bool  _STLP_CALL
00357   _M_doit(basic_filebuf<char, char_traits<char> >* __buf,
00358           char* __first, char* __last) {
00359     ptrdiff_t __n = __last - __first;
00360     return (__buf->_M_write(__first, __n));
00361   }
00362 };
00363 
00364 //----------------------------------------------------------------------
00365 // basic_filebuf<> helper functions.
00366 
00367 
00368 //----------------------------------------
00369 // Helper functions for switching between modes.
00370 
00371 //
00372 // This class had to be designed very carefully to work
00373 // with Visual C++.
00374 //
00375 template <class _Traits>
00376 class _Noconv_input {
00377 public:
00378   typedef typename _Traits::int_type int_type;
00379   typedef typename _Traits::char_type char_type;
00380 
00381   static inline int_type _STLP_CALL
00382   _M_doit(basic_filebuf<char_type, _Traits>*)
00383   { return _Traits::eof(); }
00384 };
00385 
00386 _STLP_TEMPLATE_NULL
00387 class _Noconv_input<char_traits<char> > {
00388 public:
00389   static inline int _STLP_CALL
00390   _M_doit(basic_filebuf<char, char_traits<char> >* __buf) {
00391     return __buf->_M_do_noconv_input();
00392   }
00393 };
00394 
00395 // underflow() may be called for one of two reasons.  (1) We've
00396 // been going through the special putback buffer, and we need to move back
00397 // to the regular internal buffer.  (2) We've exhausted the internal buffer,
00398 // and we need to replentish it.
00399 template <class _CharT, class _Traits>
00400 class _Underflow {
00401 public:
00402   typedef typename _Traits::int_type int_type;
00403   typedef _Traits                    traits_type;
00404 
00405   // There is a specialized version of underflow, for basic_filebuf<char>,
00406   // in fstream.cpp.
00407   static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this) {
00408     if (!__this->_M_in_input_mode) {
00409       if (!__this->_M_switch_to_input_mode())
00410         return traits_type::eof();
00411     }
00412     else if (__this->_M_in_putback_mode) {
00413       __this->_M_exit_putback_mode();
00414       if (__this->gptr() != __this->egptr()) {
00415         int_type __c = traits_type::to_int_type(*__this->gptr());
00416         return __c;
00417       }
00418     }
00419 
00420     return __this->_M_underflow_aux();
00421   }
00422 };
00423 
00424 // Specialization of underflow: if the character type is char, maybe
00425 // we can use mmap instead of read.
00426 _STLP_TEMPLATE_NULL
00427 class _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> >
00428 {
00429   public:
00430     typedef char_traits<char>::int_type int_type;
00431     typedef char_traits<char> traits_type;
00432     static int_type _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);
00433 };
00434 
00435 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_NO_WCHAR_T)
00436 _STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;
00437 #endif
00438 
00439 //----------------------------------------------------------------------
00440 // Class basic_ifstream<>
00441 
00442 template <class _CharT, class _Traits>
00443 class basic_ifstream : public basic_istream<_CharT, _Traits> {
00444 public:                         // Types
00445   typedef _CharT                     char_type;
00446   typedef typename _Traits::int_type int_type;
00447   typedef typename _Traits::pos_type pos_type;
00448   typedef typename _Traits::off_type off_type;
00449   typedef _Traits                    traits_type;
00450 
00451   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
00452   typedef basic_istream<_CharT, _Traits>            _Base;
00453   typedef basic_filebuf<_CharT, _Traits>            _Buf;
00454 
00455 public:                         // Constructors, destructor.
00456 
00457   basic_ifstream() :
00458     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
00459       this->init(&_M_buf);
00460   }
00461 
00462   explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) :
00463     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0),
00464     _M_buf() {
00465       this->init(&_M_buf);
00466       if (!_M_buf.open(__s, __mod | ios_base::in))
00467         this->setstate(ios_base::failbit);
00468   }
00469 
00470 #if !defined (_STLP_NO_EXTENSIONS)
00471   explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) :
00472     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
00473     this->init(&_M_buf);
00474     if (!_M_buf.open(__id, __mod | ios_base::in))
00475       this->setstate(ios_base::failbit);
00476   }
00477   basic_ifstream(const char* __s, ios_base::openmode __m,
00478      long __protection) :
00479     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
00480     this->init(&_M_buf);
00481     if (!_M_buf.open(__s, __m | ios_base::in, __protection))
00482       this->setstate(ios_base::failbit);
00483   }
00484 
00485 #  if defined (_STLP_USE_WIN32_IO)
00486   explicit basic_ifstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::in) :
00487     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
00488     this->init(&_M_buf);
00489     if (!_M_buf.open(__id, __mod | ios_base::in))
00490       this->setstate(ios_base::failbit);
00491   }
00492 #  endif /* _STLP_USE_WIN32_IO */
00493 #endif
00494 
00495   ~basic_ifstream() {}
00496 
00497 public:                         // File and buffer operations.
00498   basic_filebuf<_CharT, _Traits>* rdbuf() const
00499     { return __CONST_CAST(_Buf*,&_M_buf); }
00500 
00501   bool is_open() {
00502     return this->rdbuf()->is_open();
00503   }
00504 
00505   void open(const char* __s, ios_base::openmode __mod = ios_base::in) {
00506     if (!this->rdbuf()->open(__s, __mod | ios_base::in))
00507       this->setstate(ios_base::failbit);
00508   }
00509 
00510   void close() {
00511     if (!this->rdbuf()->close())
00512       this->setstate(ios_base::failbit);
00513   }
00514 
00515 private:
00516   basic_filebuf<_CharT, _Traits> _M_buf;
00517 };
00518 
00519 
00520 //----------------------------------------------------------------------
00521 // Class basic_ofstream<>
00522 
00523 template <class _CharT, class _Traits>
00524 class basic_ofstream : public basic_ostream<_CharT, _Traits> {
00525 public:                         // Types
00526   typedef _CharT                     char_type;
00527   typedef typename _Traits::int_type int_type;
00528   typedef typename _Traits::pos_type pos_type;
00529   typedef typename _Traits::off_type off_type;
00530   typedef _Traits                    traits_type;
00531 
00532   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
00533   typedef basic_ostream<_CharT, _Traits>            _Base;
00534   typedef basic_filebuf<_CharT, _Traits>            _Buf;
00535 
00536 public:                         // Constructors, destructor.
00537   basic_ofstream() :
00538     basic_ios<_CharT, _Traits>(),
00539     basic_ostream<_CharT, _Traits>(0), _M_buf() {
00540       this->init(&_M_buf);
00541   }
00542   explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out)
00543     : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() {
00544     this->init(&_M_buf);
00545     if (!_M_buf.open(__s, __mod | ios_base::out))
00546       this->setstate(ios_base::failbit);
00547   }
00548 
00549 #if !defined (_STLP_NO_EXTENSIONS)
00550   explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out)
00551     : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
00552     _M_buf() {
00553    this->init(&_M_buf);
00554    if (!_M_buf.open(__id, __mod | ios_base::out))
00555      this->setstate(ios_base::failbit);
00556   }
00557   basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) :
00558     basic_ios<_CharT, _Traits>(),  basic_ostream<_CharT, _Traits>(0), _M_buf() {
00559     this->init(&_M_buf);
00560     if (!_M_buf.open(__s, __m | ios_base::out, __protection))
00561       this->setstate(ios_base::failbit);
00562   }
00563 #  if defined (_STLP_USE_WIN32_IO)
00564   explicit basic_ofstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::out)
00565     : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
00566     _M_buf() {
00567    this->init(&_M_buf);
00568    if (!_M_buf.open(__id, __mod | ios_base::out))
00569      this->setstate(ios_base::failbit);
00570   }
00571 #  endif /* _STLP_USE_WIN32_IO */
00572 #endif
00573 
00574   ~basic_ofstream() {}
00575 
00576 public:                         // File and buffer operations.
00577   basic_filebuf<_CharT, _Traits>* rdbuf() const
00578     { return __CONST_CAST(_Buf*,&_M_buf); }
00579 
00580   bool is_open() {
00581     return this->rdbuf()->is_open();
00582   }
00583 
00584   void open(const char* __s, ios_base::openmode __mod= ios_base::out) {
00585     if (!this->rdbuf()->open(__s, __mod | ios_base::out))
00586       this->setstate(ios_base::failbit);
00587   }
00588 
00589   void close() {
00590     if (!this->rdbuf()->close())
00591       this->setstate(ios_base::failbit);
00592   }
00593 
00594 private:
00595   basic_filebuf<_CharT, _Traits> _M_buf;
00596 };
00597 
00598 
00599 //----------------------------------------------------------------------
00600 // Class basic_fstream<>
00601 
00602 template <class _CharT, class _Traits>
00603 class basic_fstream : public basic_iostream<_CharT, _Traits> {
00604 public:                         // Types
00605   typedef _CharT                     char_type;
00606   typedef typename _Traits::int_type int_type;
00607   typedef typename _Traits::pos_type pos_type;
00608   typedef typename _Traits::off_type off_type;
00609   typedef _Traits                    traits_type;
00610 
00611   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
00612   typedef basic_iostream<_CharT, _Traits>           _Base;
00613   typedef basic_filebuf<_CharT, _Traits>            _Buf;
00614 
00615 public:                         // Constructors, destructor.
00616 
00617   basic_fstream()
00618     : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
00619       this->init(&_M_buf);
00620   }
00621 
00622   explicit basic_fstream(const char* __s,
00623                          ios_base::openmode __mod = ios_base::in | ios_base::out) :
00624     basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
00625       this->init(&_M_buf);
00626       if (!_M_buf.open(__s, __mod))
00627         this->setstate(ios_base::failbit);
00628   }
00629 
00630 #if !defined (_STLP_NO_EXTENSIONS)
00631   explicit basic_fstream(int __id,
00632                          ios_base::openmode __mod = ios_base::in | ios_base::out) :
00633     basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
00634     this->init(&_M_buf);
00635     if (!_M_buf.open(__id, __mod))
00636       this->setstate(ios_base::failbit);
00637   }
00638   basic_fstream(const char* __s, ios_base::openmode __m, long __protection) :
00639     basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
00640     this->init(&_M_buf);
00641     if (!_M_buf.open(__s, __m, __protection))
00642       this->setstate(ios_base::failbit);
00643   }
00644 #  if defined (_STLP_USE_WIN32_IO)
00645   explicit basic_fstream(_STLP_fd __id,
00646     ios_base::openmode __mod = ios_base::in | ios_base::out) :
00647     basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
00648     this->init(&_M_buf);
00649     if (!_M_buf.open(__id, __mod))
00650       this->setstate(ios_base::failbit);
00651   }
00652 #  endif /* _STLP_USE_WIN32_IO */
00653 #endif
00654   ~basic_fstream() {}
00655 
00656 public:                         // File and buffer operations.
00657 
00658   basic_filebuf<_CharT, _Traits>* rdbuf() const
00659     { return __CONST_CAST(_Buf*,&_M_buf); }
00660 
00661   bool is_open() {
00662     return this->rdbuf()->is_open();
00663   }
00664 
00665   void open(const char* __s,
00666       ios_base::openmode __mod =
00667       ios_base::in | ios_base::out) {
00668     if (!this->rdbuf()->open(__s, __mod))
00669       this->setstate(ios_base::failbit);
00670   }
00671 
00672   void close() {
00673     if (!this->rdbuf()->close())
00674       this->setstate(ios_base::failbit);
00675   }
00676 
00677 private:
00678   basic_filebuf<_CharT, _Traits> _M_buf;
00679 
00680 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
00681   typedef basic_fstream<_CharT, _Traits> _Self;
00682   //explicitely defined as private to avoid warnings:
00683   basic_fstream(_Self const&);
00684   _Self& operator = (_Self const&);
00685 #endif
00686 };
00687 
00688 _STLP_END_NAMESPACE
00689 
00690 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00691 #  include <stl/_fstream.c>
00692 #endif
00693 
00694 _STLP_BEGIN_NAMESPACE
00695 
00696 #if defined (_STLP_USE_TEMPLATE_EXPORT)
00697 _STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;
00698 _STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;
00699 _STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;
00700 #  if ! defined (_STLP_NO_WCHAR_T)
00701 _STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;
00702 _STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;
00703 _STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;
00704 #  endif
00705 #endif /* _STLP_USE_TEMPLATE_EXPORT */
00706 
00707 _STLP_END_NAMESPACE
00708 
00709 #endif /* _STLP_FSTREAM */
00710 
00711 
00712 // Local Variables:
00713 // mode:C++
00714 // End:

Generated on Sat May 26 2012 04:27:36 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.