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