epoc32/include/tools/stlport/stl/_fstream.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * Copyright (c) 1999
     3  * Silicon Graphics Computer Systems, Inc.
     4  *
     5  * Copyright (c) 1999
     6  * Boris Fomitchev
     7  *
     8  * This material is provided "as is", with absolutely no warranty expressed
     9  * or implied. Any use is at your own risk.
    10  *
    11  * Permission to use or copy this software for any purpose is hereby granted
    12  * without fee, provided the above notices are retained on all copies.
    13  * Permission to modify the code and to distribute modified code is granted,
    14  * provided the above notices are retained, and a notice that the code was
    15  * modified is included with the above copyright notice.
    16  *
    17  */
    18 // This header defines classes basic_filebuf, basic_ifstream,
    19 // basic_ofstream, and basic_fstream.  These classes represent
    20 // streambufs and streams whose sources or destinations are files.
    21 
    22 #ifndef _STLP_INTERNAL_FSTREAM_H
    23 #define _STLP_INTERNAL_FSTREAM_H
    24 
    25 #if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
    26 #  error This header file requires the -LANG:std option
    27 #endif
    28 
    29 #ifndef _STLP_INTERNAL_STREAMBUF
    30 #  include <stl/_streambuf.h>
    31 #endif
    32 
    33 #ifndef _STLP_INTERNAL_ISTREAM
    34 #  include <stl/_istream.h>
    35 #endif
    36 
    37 #ifndef _STLP_INTERNAL_CODECVT_H
    38 #  include <stl/_codecvt.h>
    39 #endif
    40 
    41 #if !defined (_STLP_USE_UNIX_IO) && !defined(_STLP_USE_WIN32_IO) && \
    42     !defined (_STLP_USE_UNIX_EMULATION_IO) && !defined (_STLP_USE_STDIO_IO)
    43 
    44 #  if defined (_STLP_UNIX)  || defined (__CYGWIN__) || defined (__amigaos__) || defined (__EMX__)
    45 // open/close/read/write
    46 #    define _STLP_USE_UNIX_IO
    47 #  elif defined (_STLP_WIN32)
    48 // CreateFile/ReadFile/WriteFile
    49 #    define _STLP_USE_WIN32_IO
    50 #  elif defined (_STLP_WIN16) || defined (_STLP_MAC)
    51 // _open/_read/_write
    52 #    define _STLP_USE_UNIX_EMULATION_IO
    53 #  else
    54 // fopen/fread/fwrite
    55 #    define _STLP_USE_STDIO_IO
    56 #  endif /* _STLP_UNIX */
    57 #endif /* mode selection */
    58 
    59 #if defined (_STLP_USE_WIN32_IO)
    60 typedef void* _STLP_fd;
    61 #elif defined (_STLP_USE_UNIX_EMULATION_IO) || defined (_STLP_USE_STDIO_IO) || defined (_STLP_USE_UNIX_IO)
    62 typedef int _STLP_fd;
    63 #else
    64 #  error "Configure i/o !"
    65 #endif
    66 
    67 _STLP_BEGIN_NAMESPACE
    68 
    69 //----------------------------------------------------------------------
    70 // Class _Filebuf_base, a private base class to factor out the system-
    71 // dependent code from basic_filebuf<>.
    72 
    73 class _STLP_CLASS_DECLSPEC _Filebuf_base {
    74 public:                      // Opening and closing files.
    75   _Filebuf_base();
    76 
    77   bool _M_open(const char*, ios_base::openmode, long __protection);
    78   bool _M_open(const char*, ios_base::openmode);
    79   bool _M_open(int __id, ios_base::openmode = ios_base::__default_mode);
    80 #if defined (_STLP_USE_WIN32_IO)
    81   bool _M_open(_STLP_fd __id, ios_base::openmode = ios_base::__default_mode);
    82 #endif /* _STLP_USE_WIN32_IO */
    83   bool _M_close();
    84 
    85 public:                      // Low-level I/O, like Unix read/write
    86   ptrdiff_t _M_read(char* __buf,  ptrdiff_t __n);
    87   streamoff _M_seek(streamoff __offset, ios_base::seekdir __dir);
    88   streamoff _M_file_size();
    89   bool _M_write(char* __buf,  ptrdiff_t __n);
    90 
    91 public:                      // Memory-mapped I/O.
    92   void* _M_mmap(streamoff __offset, streamoff __len);
    93   void _M_unmap(void* __mmap_base, streamoff __len);
    94 
    95 public:
    96   // Returns a value n such that, if pos is the file pointer at the
    97   // beginning of the range [first, last), pos + n is the file pointer at
    98   // the end.  On many operating systems n == __last - __first.
    99   // In Unix, writing n characters always bumps the file position by n.
   100   // In Windows text mode, however, it bumps the file position by n + m,
   101   // where m is the number of newlines in the range.  That's because an
   102   // internal \n corresponds to an external two-character sequence.
   103   streamoff _M_get_offset(char* __first, char* __last) {
   104 #if defined (_STLP_UNIX) || defined (_STLP_MAC)
   105     return __last - __first;
   106 #else // defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS) || defined(N_PLAT_NLM)
   107     return ( (_M_openmode & ios_base::binary) != 0 )
   108       ? (__last - __first)
   109       : count(__first, __last, '\n') + (__last - __first);
   110 #endif
   111   }
   112 
   113   // Returns true if we're in binary mode or if we're using an OS or file
   114   // system where there is no distinction between text and binary mode.
   115   bool _M_in_binary_mode() const {
   116 #if defined (_STLP_UNIX) || defined (_STLP_MAC)  || defined(__BEOS__) || defined (__amigaos__)
   117     return true;
   118 #elif defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS) || defined (_STLP_VM) || defined (__EMX__) || defined(N_PLAT_NLM)
   119     return (_M_openmode & ios_base::binary) != 0;
   120 #else
   121 #  error "Port!"
   122 #endif
   123   }
   124 
   125 protected:                      // Static data members.
   126   static size_t _M_page_size;
   127 
   128 protected:                      // Data members.
   129   _STLP_fd _M_file_id;
   130 #if defined (_STLP_USE_STDIO_IO)
   131   // for stdio, the whole FILE* is being kept here
   132   FILE* _M_file;
   133 #endif
   134 #if defined (_STLP_USE_WIN32_IO)
   135   _STLP_fd _M_view_id;
   136 #endif
   137 
   138   ios_base::openmode _M_openmode     ;
   139   unsigned char      _M_is_open      ;
   140   unsigned char      _M_should_close ;
   141   unsigned char      _M_regular_file ;
   142 
   143 public :
   144   static size_t  _STLP_CALL __page_size() { return _M_page_size; }
   145   int  __o_mode() const { return (int)_M_openmode; }
   146   bool __is_open()      const { return (_M_is_open !=0 ); }
   147   bool __should_close() const { return (_M_should_close != 0); }
   148   bool __regular_file() const { return (_M_regular_file != 0); }
   149   _STLP_fd __get_fd() const { return _M_file_id; }
   150 };
   151 
   152 //----------------------------------------------------------------------
   153 // Class basic_filebuf<>.
   154 
   155 // Forward declaration of two helper classes.
   156 template <class _Traits> class _Noconv_input;
   157 _STLP_TEMPLATE_NULL
   158 class _Noconv_input<char_traits<char> >;
   159 
   160 template <class _Traits> class _Noconv_output;
   161 _STLP_TEMPLATE_NULL
   162 class _Noconv_output< char_traits<char> >;
   163 
   164 // There is a specialized version of underflow, for basic_filebuf<char>,
   165 // in fstream.cxx.
   166 
   167 template <class _CharT, class _Traits>
   168 class _Underflow;
   169 
   170 _STLP_TEMPLATE_NULL class _Underflow< char, char_traits<char> >;
   171 
   172 template <class _CharT, class _Traits>
   173 class basic_filebuf : public basic_streambuf<_CharT, _Traits> {
   174 public:                         // Types.
   175   typedef _CharT                     char_type;
   176   typedef typename _Traits::int_type int_type;
   177   typedef typename _Traits::pos_type pos_type;
   178   typedef typename _Traits::off_type off_type;
   179   typedef _Traits                    traits_type;
   180 
   181   typedef typename _Traits::state_type _State_type;
   182   typedef basic_streambuf<_CharT, _Traits> _Base;
   183   typedef basic_filebuf<_CharT, _Traits> _Self;
   184 
   185 public:                         // Constructors, destructor.
   186   basic_filebuf();
   187   ~basic_filebuf();
   188 
   189 public:                         // Opening and closing files.
   190   bool is_open() const { return _M_base.__is_open(); }
   191 
   192   _Self* open(const char* __s, ios_base::openmode __m) {
   193     return _M_base._M_open(__s, __m) ? this : 0;
   194   }
   195 
   196 #if !defined (_STLP_NO_EXTENSIONS)
   197   // These two version of open() and file descriptor getter are extensions.
   198   _Self* open(const char* __s, ios_base::openmode __m,
   199               long __protection) {
   200     return _M_base._M_open(__s, __m, __protection) ? this : 0;
   201   }
   202 
   203   _STLP_fd fd() const { return _M_base.__get_fd(); }
   204 
   205   _Self* open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
   206     return this->_M_open(__id, _Init_mode);
   207   }
   208 
   209 #  if defined (_STLP_USE_WIN32_IO)
   210   _Self* open(_STLP_fd __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
   211     return _M_base._M_open(__id, _Init_mode) ? this : 0;
   212   }
   213 #  endif /* _STLP_USE_WIN32_IO */
   214 
   215 #endif
   216 
   217   _Self* _M_open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
   218     return _M_base._M_open(__id, _Init_mode) ? this : 0;
   219   }
   220 
   221   _Self* close();
   222 
   223 protected:                      // Virtual functions from basic_streambuf.
   224   virtual streamsize showmanyc();
   225   virtual int_type underflow();
   226 
   227   virtual int_type pbackfail(int_type = traits_type::eof());
   228   virtual int_type overflow(int_type = traits_type::eof());
   229 
   230   virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
   231   virtual pos_type seekoff(off_type, ios_base::seekdir,
   232                            ios_base::openmode = ios_base::in | ios_base::out);
   233   virtual pos_type seekpos(pos_type,
   234                            ios_base::openmode = ios_base::in | ios_base::out);
   235 
   236   virtual int sync();
   237   virtual void imbue(const locale&);
   238 
   239 private:                        // Helper functions.
   240 
   241   // Precondition: we are currently in putback input mode.  Effect:
   242   // switches back to ordinary input mode.
   243   void _M_exit_putback_mode() {
   244     this->setg(_M_saved_eback, _M_saved_gptr, _M_saved_egptr);
   245     _M_in_putback_mode = false;
   246   }
   247   bool _M_switch_to_input_mode();
   248   void _M_exit_input_mode();
   249   bool _M_switch_to_output_mode();
   250 
   251   int_type _M_input_error();
   252   int_type _M_underflow_aux();
   253   //  friend class _Noconv_input<_Traits>;
   254   //  friend class _Noconv_output<_Traits>;
   255   friend class _Underflow<_CharT, _Traits>;
   256 
   257   int_type _M_output_error();
   258   bool _M_unshift();
   259 
   260   bool _M_allocate_buffers(_CharT* __buf, streamsize __n);
   261   bool _M_allocate_buffers();
   262   void _M_deallocate_buffers();
   263 
   264   pos_type _M_seek_return(off_type __off, _State_type __state) {
   265     if (__off != -1) {
   266       if (_M_in_input_mode)
   267         _M_exit_input_mode();
   268       _M_in_input_mode = false;
   269       _M_in_output_mode = false;
   270       _M_in_putback_mode = false;
   271       _M_in_error_mode = false;
   272       this->setg(0, 0, 0);
   273       this->setp(0, 0);
   274     }
   275 
   276     pos_type __result(__off);
   277     __result.state(__state);
   278     return __result;
   279   }
   280 
   281   bool _M_seek_init(bool __do_unshift);
   282 
   283   void _M_setup_codecvt(const locale&, bool __on_imbue = true);
   284 
   285 private:                        // Data members used in all modes.
   286 
   287   _Filebuf_base _M_base;
   288 
   289 private:                        // Locale-related information.
   290 
   291   unsigned char _M_constant_width;
   292   unsigned char _M_always_noconv;
   293 
   294   // private:                        // Mode flags.
   295   unsigned char _M_int_buf_dynamic;  // True if internal buffer is heap allocated,
   296   // false if it was supplied by the user.
   297   unsigned char _M_in_input_mode;
   298   unsigned char _M_in_output_mode;
   299   unsigned char _M_in_error_mode;
   300   unsigned char _M_in_putback_mode;
   301 
   302   // Internal buffer: characters seen by the filebuf's clients.
   303   _CharT* _M_int_buf;
   304   _CharT* _M_int_buf_EOS;
   305 
   306   // External buffer: characters corresponding to the external file.
   307   char* _M_ext_buf;
   308   char* _M_ext_buf_EOS;
   309 
   310   // The range [_M_ext_buf, _M_ext_buf_converted) contains the external
   311   // characters corresponding to the sequence in the internal buffer.  The
   312   // range [_M_ext_buf_converted, _M_ext_buf_end) contains characters that
   313   // have been read into the external buffer but have not been converted
   314   // to an internal sequence.
   315   char* _M_ext_buf_converted;
   316   char* _M_ext_buf_end;
   317 
   318   // State corresponding to beginning of internal buffer.
   319   _State_type _M_state;
   320 
   321 private:                        // Data members used only in input mode.
   322 
   323   // Similar to _M_state except that it corresponds to
   324   // the end of the internal buffer instead of the beginning.
   325   _State_type _M_end_state;
   326 
   327   // This is a null pointer unless we are in mmap input mode.
   328   void*     _M_mmap_base;
   329   streamoff _M_mmap_len;
   330 
   331 private:                        // Data members used only in putback mode.
   332   _CharT* _M_saved_eback;
   333   _CharT* _M_saved_gptr;
   334   _CharT* _M_saved_egptr;
   335 
   336   typedef codecvt<_CharT, char, _State_type> _Codecvt;
   337   const _Codecvt* _M_codecvt;
   338 
   339   int _M_width;                 // Width of the encoding (if constant), else 1
   340   int _M_max_width;             // Largest possible width of single character.
   341 
   342 
   343   enum { _S_pback_buf_size = 8 };
   344   _CharT _M_pback_buf[_S_pback_buf_size];
   345 
   346   // for _Noconv_output
   347 public:
   348   bool _M_write(char* __buf,  ptrdiff_t __n) {return _M_base._M_write(__buf, __n); }
   349 
   350 public:
   351   int_type
   352   _M_do_noconv_input() {
   353     _M_ext_buf_converted = _M_ext_buf_end;
   354     /* this-> */ _Base::setg((char_type*)_M_ext_buf, (char_type*)_M_ext_buf, (char_type*)_M_ext_buf_end);
   355     return traits_type::to_int_type(*_M_ext_buf);
   356   }
   357 };
   358 
   359 #if defined (_STLP_USE_TEMPLATE_EXPORT)
   360 _STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<char, char_traits<char> >;
   361 #  if ! defined (_STLP_NO_WCHAR_T)
   362 _STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<wchar_t, char_traits<wchar_t> >;
   363 #  endif
   364 #endif /* _STLP_USE_TEMPLATE_EXPORT */
   365 
   366 // public:
   367 // helper class.
   368 template <class _CharT>
   369 struct _Filebuf_Tmp_Buf {
   370   _CharT* _M_ptr;
   371   _Filebuf_Tmp_Buf(ptrdiff_t __n) : _M_ptr(0) { _M_ptr = new _CharT[__n]; }
   372   ~_Filebuf_Tmp_Buf() { delete[] _M_ptr; }
   373 };
   374 
   375 
   376 //
   377 // This class had to be designed very carefully to work
   378 // with Visual C++.
   379 //
   380 template <class _Traits>
   381 class _Noconv_output {
   382 public:
   383   typedef typename _Traits::char_type char_type;
   384   static bool  _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits >*,
   385                                   char_type*, char_type*)
   386   { return false; }
   387 };
   388 
   389 _STLP_TEMPLATE_NULL
   390 class _STLP_CLASS_DECLSPEC _Noconv_output< char_traits<char> > {
   391 public:
   392   static bool  _STLP_CALL
   393   _M_doit(basic_filebuf<char, char_traits<char> >* __buf,
   394           char* __first, char* __last) {
   395     ptrdiff_t __n = __last - __first;
   396     return (__buf->_M_write(__first, __n));
   397   }
   398 };
   399 
   400 //----------------------------------------------------------------------
   401 // basic_filebuf<> helper functions.
   402 
   403 
   404 //----------------------------------------
   405 // Helper functions for switching between modes.
   406 
   407 //
   408 // This class had to be designed very carefully to work
   409 // with Visual C++.
   410 //
   411 template <class _Traits>
   412 class _Noconv_input {
   413 public:
   414   typedef typename _Traits::int_type int_type;
   415   typedef typename _Traits::char_type char_type;
   416 
   417   static inline int_type _STLP_CALL
   418   _M_doit(basic_filebuf<char_type, _Traits>*)
   419   { return _Traits::eof(); }
   420 };
   421 
   422 _STLP_TEMPLATE_NULL
   423 class _Noconv_input<char_traits<char> > {
   424 public:
   425   static inline int _STLP_CALL
   426   _M_doit(basic_filebuf<char, char_traits<char> >* __buf) {
   427     return __buf->_M_do_noconv_input();
   428   }
   429 };
   430 
   431 // underflow() may be called for one of two reasons.  (1) We've
   432 // been going through the special putback buffer, and we need to move back
   433 // to the regular internal buffer.  (2) We've exhausted the internal buffer,
   434 // and we need to replentish it.
   435 template <class _CharT, class _Traits>
   436 class _Underflow {
   437 public:
   438   typedef typename _Traits::int_type int_type;
   439   typedef _Traits                    traits_type;
   440 
   441   static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this);
   442 };
   443 
   444 
   445 // Specialization of underflow: if the character type is char, maybe
   446 // we can use mmap instead of read.
   447 _STLP_TEMPLATE_NULL
   448 class _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> > {
   449 public:
   450   typedef char_traits<char>::int_type int_type;
   451   typedef char_traits<char> traits_type;
   452   static  int _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);
   453 };
   454 
   455 // There is a specialized version of underflow, for basic_filebuf<char>,
   456 // in fstream.cxx.
   457 
   458 template <class _CharT, class _Traits>
   459 _STLP_TYPENAME_ON_RETURN_TYPE _Underflow<_CharT, _Traits>::int_type // _STLP_CALL
   460  _Underflow<_CharT, _Traits>::_M_doit(basic_filebuf<_CharT, _Traits>* __this) {
   461   if (!__this->_M_in_input_mode) {
   462     if (!__this->_M_switch_to_input_mode())
   463       return traits_type::eof();
   464   }
   465   else if (__this->_M_in_putback_mode) {
   466     __this->_M_exit_putback_mode();
   467     if (__this->gptr() != __this->egptr()) {
   468       int_type __c = traits_type::to_int_type(*__this->gptr());
   469       return __c;
   470     }
   471   }
   472 
   473   return __this->_M_underflow_aux();
   474 }
   475 
   476 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_NO_WCHAR_T)
   477 _STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;
   478 #endif
   479 
   480 //----------------------------------------------------------------------
   481 // Class basic_ifstream<>
   482 
   483 template <class _CharT, class _Traits>
   484 class basic_ifstream : public basic_istream<_CharT, _Traits> {
   485 public:                         // Types
   486   typedef _CharT                     char_type;
   487   typedef typename _Traits::int_type int_type;
   488   typedef typename _Traits::pos_type pos_type;
   489   typedef typename _Traits::off_type off_type;
   490   typedef _Traits                    traits_type;
   491 
   492   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
   493   typedef basic_istream<_CharT, _Traits>            _Base;
   494   typedef basic_filebuf<_CharT, _Traits>            _Buf;
   495 
   496 public:                         // Constructors, destructor.
   497 
   498   basic_ifstream() :
   499     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   500       this->init(&_M_buf);
   501   }
   502 
   503   explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) :
   504     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0),
   505     _M_buf() {
   506       this->init(&_M_buf);
   507       if (!_M_buf.open(__s, __mod | ios_base::in))
   508         this->setstate(ios_base::failbit);
   509   }
   510 
   511 #if !defined (_STLP_NO_EXTENSIONS)
   512   explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) :
   513     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   514     this->init(&_M_buf);
   515     if (!_M_buf.open(__id, __mod | ios_base::in))
   516       this->setstate(ios_base::failbit);
   517   }
   518   basic_ifstream(const char* __s, ios_base::openmode __m,
   519      long __protection) :
   520     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   521     this->init(&_M_buf);
   522     if (!_M_buf.open(__s, __m | ios_base::in, __protection))
   523       this->setstate(ios_base::failbit);
   524   }
   525 
   526 #  if defined (_STLP_USE_WIN32_IO)
   527   explicit basic_ifstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::in) :
   528     basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   529     this->init(&_M_buf);
   530     if (!_M_buf.open(__id, __mod | ios_base::in))
   531       this->setstate(ios_base::failbit);
   532   }
   533 #  endif /* _STLP_USE_WIN32_IO */
   534 #endif
   535 
   536   ~basic_ifstream() {}
   537 
   538 public:                         // File and buffer operations.
   539   basic_filebuf<_CharT, _Traits>* rdbuf() const
   540     { return __CONST_CAST(_Buf*,&_M_buf); }
   541 
   542   bool is_open() {
   543     return this->rdbuf()->is_open();
   544   }
   545 
   546   void open(const char* __s, ios_base::openmode __mod = ios_base::in) {
   547     if (!this->rdbuf()->open(__s, __mod | ios_base::in))
   548       this->setstate(ios_base::failbit);
   549   }
   550 
   551   void close() {
   552     if (!this->rdbuf()->close())
   553       this->setstate(ios_base::failbit);
   554   }
   555 
   556 private:
   557   basic_filebuf<_CharT, _Traits> _M_buf;
   558 };
   559 
   560 
   561 //----------------------------------------------------------------------
   562 // Class basic_ofstream<>
   563 
   564 template <class _CharT, class _Traits>
   565 class basic_ofstream : public basic_ostream<_CharT, _Traits> {
   566 public:                         // Types
   567   typedef _CharT                     char_type;
   568   typedef typename _Traits::int_type int_type;
   569   typedef typename _Traits::pos_type pos_type;
   570   typedef typename _Traits::off_type off_type;
   571   typedef _Traits                    traits_type;
   572 
   573   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
   574   typedef basic_ostream<_CharT, _Traits>            _Base;
   575   typedef basic_filebuf<_CharT, _Traits>            _Buf;
   576 
   577 public:                         // Constructors, destructor.
   578   basic_ofstream() :
   579     basic_ios<_CharT, _Traits>(),
   580     basic_ostream<_CharT, _Traits>(0), _M_buf() {
   581       this->init(&_M_buf);
   582   }
   583   explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out)
   584     : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() {
   585     this->init(&_M_buf);
   586     if (!_M_buf.open(__s, __mod | ios_base::out))
   587       this->setstate(ios_base::failbit);
   588   }
   589 
   590 #if !defined (_STLP_NO_EXTENSIONS)
   591   explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out)
   592     : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
   593     _M_buf() {
   594    this->init(&_M_buf);
   595    if (!_M_buf.open(__id, __mod | ios_base::out))
   596      this->setstate(ios_base::failbit);
   597   }
   598   basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) :
   599     basic_ios<_CharT, _Traits>(),  basic_ostream<_CharT, _Traits>(0), _M_buf() {
   600     this->init(&_M_buf);
   601     if (!_M_buf.open(__s, __m | ios_base::out, __protection))
   602       this->setstate(ios_base::failbit);
   603   }
   604 #  if defined (_STLP_USE_WIN32_IO)
   605   explicit basic_ofstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::out)
   606     : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
   607     _M_buf() {
   608    this->init(&_M_buf);
   609    if (!_M_buf.open(__id, __mod | ios_base::out))
   610      this->setstate(ios_base::failbit);
   611   }
   612 #  endif /* _STLP_USE_WIN32_IO */
   613 #endif
   614 
   615   ~basic_ofstream() {}
   616 
   617 public:                         // File and buffer operations.
   618   basic_filebuf<_CharT, _Traits>* rdbuf() const
   619     { return __CONST_CAST(_Buf*,&_M_buf); }
   620 
   621   bool is_open() {
   622     return this->rdbuf()->is_open();
   623   }
   624 
   625   void open(const char* __s, ios_base::openmode __mod= ios_base::out) {
   626     if (!this->rdbuf()->open(__s, __mod | ios_base::out))
   627       this->setstate(ios_base::failbit);
   628   }
   629 
   630   void close() {
   631     if (!this->rdbuf()->close())
   632       this->setstate(ios_base::failbit);
   633   }
   634 
   635 private:
   636   basic_filebuf<_CharT, _Traits> _M_buf;
   637 };
   638 
   639 
   640 //----------------------------------------------------------------------
   641 // Class basic_fstream<>
   642 
   643 template <class _CharT, class _Traits>
   644 class basic_fstream : public basic_iostream<_CharT, _Traits> {
   645 public:                         // Types
   646   typedef _CharT                     char_type;
   647   typedef typename _Traits::int_type int_type;
   648   typedef typename _Traits::pos_type pos_type;
   649   typedef typename _Traits::off_type off_type;
   650   typedef _Traits                    traits_type;
   651 
   652   typedef basic_ios<_CharT, _Traits>                _Basic_ios;
   653   typedef basic_iostream<_CharT, _Traits>           _Base;
   654   typedef basic_filebuf<_CharT, _Traits>            _Buf;
   655 
   656 public:                         // Constructors, destructor.
   657 
   658   basic_fstream()
   659     : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
   660       this->init(&_M_buf);
   661   }
   662 
   663   explicit basic_fstream(const char* __s,
   664                          ios_base::openmode __mod = ios_base::in | ios_base::out) :
   665     basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
   666       this->init(&_M_buf);
   667       if (!_M_buf.open(__s, __mod))
   668         this->setstate(ios_base::failbit);
   669   }
   670 
   671 #if !defined (_STLP_NO_EXTENSIONS)
   672   explicit basic_fstream(int __id,
   673                          ios_base::openmode __mod = ios_base::in | ios_base::out) :
   674     basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
   675     this->init(&_M_buf);
   676     if (!_M_buf.open(__id, __mod))
   677       this->setstate(ios_base::failbit);
   678   }
   679   basic_fstream(const char* __s, ios_base::openmode __m, long __protection) :
   680     basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
   681     this->init(&_M_buf);
   682     if (!_M_buf.open(__s, __m, __protection))
   683       this->setstate(ios_base::failbit);
   684   }
   685 #  if defined (_STLP_USE_WIN32_IO)
   686   explicit basic_fstream(_STLP_fd __id,
   687     ios_base::openmode __mod = ios_base::in | ios_base::out) :
   688     basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
   689     this->init(&_M_buf);
   690     if (!_M_buf.open(__id, __mod))
   691       this->setstate(ios_base::failbit);
   692   }
   693 #  endif /* _STLP_USE_WIN32_IO */
   694 #endif
   695   ~basic_fstream() {}
   696 
   697 public:                         // File and buffer operations.
   698 
   699   basic_filebuf<_CharT, _Traits>* rdbuf() const
   700     { return __CONST_CAST(_Buf*,&_M_buf); }
   701 
   702   bool is_open() {
   703     return this->rdbuf()->is_open();
   704   }
   705 
   706   void open(const char* __s,
   707       ios_base::openmode __mod =
   708       ios_base::in | ios_base::out) {
   709     if (!this->rdbuf()->open(__s, __mod))
   710       this->setstate(ios_base::failbit);
   711   }
   712 
   713   void close() {
   714     if (!this->rdbuf()->close())
   715       this->setstate(ios_base::failbit);
   716   }
   717 
   718 private:
   719   basic_filebuf<_CharT, _Traits> _M_buf;
   720 
   721 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
   722   typedef basic_fstream<_CharT, _Traits> _Self;
   723   //explicitely defined as private to avoid warnings:
   724   basic_fstream(_Self const&);
   725   _Self& operator = (_Self const&);
   726 #endif
   727 };
   728 
   729 _STLP_END_NAMESPACE
   730 
   731 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   732 #  include <stl/_fstream.c>
   733 #endif
   734 
   735 _STLP_BEGIN_NAMESPACE
   736 
   737 #if defined (_STLP_USE_TEMPLATE_EXPORT)
   738 _STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;
   739 _STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;
   740 _STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;
   741 #  if ! defined (_STLP_NO_WCHAR_T)
   742 _STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;
   743 _STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;
   744 _STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;
   745 #  endif
   746 #endif /* _STLP_USE_TEMPLATE_EXPORT */
   747 
   748 _STLP_END_NAMESPACE
   749 
   750 #endif /* _STLP_FSTREAM */
   751 
   752 
   753 // Local Variables:
   754 // mode:C++
   755 // End: