epoc32/include/stdapis/stlportv5/stl/_fstream.h
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_fstream.h	Wed Mar 31 12:27:01 2010 +0100
     1.3 @@ -0,0 +1,767 @@
     1.4 +/*
     1.5 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     1.6 + *
     1.7 + * Copyright (c) 1999
     1.8 + * Silicon Graphics Computer Systems, Inc.
     1.9 + *
    1.10 + * Copyright (c) 1999 
    1.11 + * Boris Fomitchev
    1.12 + *
    1.13 + * This material is provided "as is", with absolutely no warranty expressed
    1.14 + * or implied. Any use is at your own risk.
    1.15 + *
    1.16 + * Permission to use or copy this software for any purpose is hereby granted 
    1.17 + * without fee, provided the above notices are retained on all copies.
    1.18 + * Permission to modify the code and to distribute modified code is granted,
    1.19 + * provided the above notices are retained, and a notice that the code was
    1.20 + * modified is included with the above copyright notice.
    1.21 + *
    1.22 + */ 
    1.23 +// This header defines classes basic_filebuf, basic_ifstream,
    1.24 +// basic_ofstream, and basic_fstream.  These classes represent
    1.25 +// streambufs and streams whose sources or destinations are files.
    1.26 +
    1.27 +#ifndef _STLP_INTERNAL_FSTREAM_H
    1.28 +#define _STLP_INTERNAL_FSTREAM_H
    1.29 +
    1.30 +#if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
    1.31 +#error This header file requires the -LANG:std option
    1.32 +#endif
    1.33 +
    1.34 +#ifndef _STLP_INTERNAL_STREAMBUF
    1.35 +# include <stl/_streambuf.h>
    1.36 +#endif
    1.37 +
    1.38 +#ifndef _STLP_INTERNAL_ISTREAM_H
    1.39 +#include <stl/_istream.h>
    1.40 +#endif
    1.41 +
    1.42 +#ifndef _STLP_INTERNAL_CODECVT_H
    1.43 +#include <stl/_codecvt.h>
    1.44 +#endif
    1.45 +
    1.46 +#ifndef _STLP_STDIO_FILE_H
    1.47 +#include <stl/_stdio_file.h>
    1.48 +#endif
    1.49 +
    1.50 +// fbp : let us map 1 MB maximum, just be sure not to trash VM
    1.51 +//for hardware defining 8kb of mmap chunk
    1.52 +# ifdef __SYMBIAN32__
    1.53 +# define MMAP_CHUNK 0x2000UL
    1.54 +# else
    1.55 +# define MMAP_CHUNK 0x100000UL
    1.56 +# endif
    1.57 +
    1.58 +#if !defined (_STLP_USE_UNIX_IO) && !defined(_STLP_USE_WIN32_IO) \
    1.59 +    && ! defined (_STLP_USE_UNIX_EMULATION_IO) && !defined (_STLP_USE_STDIO_IO)
    1.60 +
    1.61 +# if defined (_STLP_UNIX)  || defined (__CYGWIN__) || defined (__amigaos__) || defined (__EMX__) || defined (__SYMBIAN32__)
    1.62 +// open/close/read/write
    1.63 +#  define _STLP_USE_UNIX_IO
    1.64 +# elif defined (_STLP_WIN32)  && ! defined (__CYGWIN__)
    1.65 +// CreateFile/ReadFile/WriteFile
    1.66 +#  define _STLP_USE_WIN32_IO
    1.67 +# elif defined (_STLP_WIN16) || defined (_STLP_WIN32) || defined (_STLP_MAC)
    1.68 +// _open/_read/_write
    1.69 +#  define _STLP_USE_UNIX_EMULATION_IO
    1.70 +# else
    1.71 +// fopen/fread/fwrite
    1.72 +#  define _STLP_USE_STDIO_IO
    1.73 +# endif /* _STLP_UNIX */
    1.74 +
    1.75 +#endif /* mode selection */
    1.76 +
    1.77 +
    1.78 +#if defined (_STLP_USE_WIN32_IO)
    1.79 +typedef void* _STLP_fd;
    1.80 +#elif defined (_STLP_USE_UNIX_EMULATION_IO) || defined (_STLP_USE_STDIO_IO) || defined (_STLP_USE_UNIX_IO)
    1.81 +typedef int _STLP_fd;
    1.82 +#else
    1.83 +#error "Configure i/o !"
    1.84 +#endif
    1.85 +
    1.86 +
    1.87 +_STLP_BEGIN_NAMESPACE
    1.88 +
    1.89 +#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
    1.90 +_STLP_DECLSPEC size_t& get_fstream_Filebuf_Base_GetPageSize();
    1.91 +#endif //__LIBSTD_CPP_SYMBIAN32_WSD__
    1.92 +//----------------------------------------------------------------------
    1.93 +// Class _Filebuf_base, a private base class to factor out the system-
    1.94 +// dependent code from basic_filebuf<>.
    1.95 +
    1.96 +class _STLP_CLASS_DECLSPEC _Filebuf_base {
    1.97 +public:                      // Opening and closing files.
    1.98 +  _STLP_DECLSPEC _Filebuf_base();
    1.99 +
   1.100 +  _STLP_DECLSPEC bool _M_open(const char*, ios_base::openmode, long __protection);
   1.101 +  _STLP_DECLSPEC bool _M_open(const char*, ios_base::openmode);
   1.102 +  _STLP_DECLSPEC bool _M_open(int __id, ios_base::openmode = ios_base::__default_mode);
   1.103 +  _STLP_DECLSPEC bool _M_close();
   1.104 +
   1.105 +public:                      // Low-level I/O, like Unix read/write
   1.106 +  _STLP_DECLSPEC ptrdiff_t _M_read(char* __buf,  ptrdiff_t __n);
   1.107 +  _STLP_DECLSPEC streamoff _M_seek(streamoff __offset, ios_base::seekdir __dir);
   1.108 +  _STLP_DECLSPEC streamoff _M_file_size();
   1.109 +  _STLP_DECLSPEC bool _M_write(char* __buf,  ptrdiff_t __n);
   1.110 +
   1.111 +public:                      // Memory-mapped I/O.
   1.112 +  _STLP_DECLSPEC void* _M_mmap(streamoff __offset, streamoff __len);
   1.113 +  _STLP_DECLSPEC void _M_unmap(void* __mmap_base, streamoff __len);
   1.114 +
   1.115 +public:
   1.116 +  // Returns a value n such that, if pos is the file pointer at the
   1.117 +  // beginning of the range [first, last), pos + n is the file pointer at
   1.118 +  // the end.  On many operating systems n == __last - __first.
   1.119 +  // In Unix, writing n characters always bumps the file position by n.
   1.120 +  // In Windows text mode, however, it bumps the file position by n + m,
   1.121 +  // where m is the number of newlines in the range.  That's because an
   1.122 +  // internal \n corresponds to an external two-character sequence.
   1.123 +  streamoff _M_get_offset(char* __first, char* __last) {
   1.124 +#if defined (_STLP_UNIX) || defined (_STLP_MAC)
   1.125 +    return __last - __first;
   1.126 +#else // defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS)
   1.127 +    return ( (_M_openmode & ios_base::binary) != 0 )
   1.128 +      ? (__last - __first)
   1.129 +      : count(__first, __last, '\n') + (__last - __first);
   1.130 +#endif
   1.131 +  }
   1.132 +
   1.133 +  // Returns true if we're in binary mode or if we're using an OS or file 
   1.134 +  // system where there is no distinction between text and binary mode.
   1.135 +  bool _M_in_binary_mode() const {
   1.136 +# if defined (_STLP_UNIX) || defined (_STLP_MAC)  || defined(__BEOS__) || defined (__amigaos__) || defined (_STLP_VXWORKS_TORNADO)
   1.137 +    return true;
   1.138 +# elif defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS) || defined (_STLP_VM) || defined (__EMX__)
   1.139 +    return (_M_openmode & ios_base::binary) != 0;
   1.140 +# else 
   1.141 +//#   error "Port!"
   1.142 +#pragma message(" Symbian I/O stream support on progress."__FILE__)
   1.143 +# endif
   1.144 +  }
   1.145 +
   1.146 +protected:                      // Static data members.
   1.147 +# if !defined(__LIBSTD_CPP_SYMBIAN32_WSD__) && !defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
   1.148 +  static size_t _M_page_size;
   1.149 +#endif //__SYMBIAN32__
   1.150 +
   1.151 +protected:                      // Data members.
   1.152 +  _STLP_fd _M_file_id;
   1.153 +# ifdef _STLP_USE_STDIO_IO
   1.154 +  // for stdio, the whole FILE* is being kept here
   1.155 +  FILE* _M_file;
   1.156 +# endif
   1.157 +# ifdef _STLP_USE_WIN32_IO
   1.158 +  void* _M_view_id; 
   1.159 +# endif
   1.160 +
   1.161 +  ios_base::openmode _M_openmode     ;
   1.162 +  unsigned char      _M_is_open      ;
   1.163 +  unsigned char      _M_should_close ;
   1.164 +  unsigned char      _M_regular_file ;
   1.165 +
   1.166 +public :
   1.167 +#if defined(__LIBSTD_CPP_SYMBIAN32_WSD__) || defined(_STLP_LIBSTD_CPP_NO_STATIC_VAR_)
   1.168 +  static size_t  _STLP_CALL __page_size() { return get_fstream_Filebuf_Base_GetPageSize(); }
   1.169 +#else
   1.170 +  static size_t  _STLP_CALL __page_size() { return _M_page_size; } 
   1.171 +#endif  
   1.172 +  int  __o_mode() const { return (int)_M_openmode; } 
   1.173 +  bool __is_open()      const { return (_M_is_open !=0 ); } 
   1.174 +  bool __should_close() const { return (_M_should_close != 0); } 
   1.175 +  bool __regular_file() const { return (_M_regular_file != 0); }
   1.176 +  _STLP_fd __get_fd() const { return _M_file_id; }
   1.177 +};
   1.178 +
   1.179 +
   1.180 +
   1.181 +
   1.182 +//----------------------------------------------------------------------
   1.183 +// Class basic_filebuf<>.
   1.184 +
   1.185 +// Forward declaration of two helper classes.
   1.186 +template <class _Traits> class _Noconv_input;
   1.187 +_STLP_TEMPLATE_NULL
   1.188 +class _Noconv_input<char_traits<char> >;
   1.189 +
   1.190 +template <class _Traits> class _Noconv_output;
   1.191 +_STLP_TEMPLATE_NULL
   1.192 +class _Noconv_output< char_traits<char> >;
   1.193 +
   1.194 +// There is a specialized version of underflow, for basic_filebuf<char>,
   1.195 +// in fstream.cxx.
   1.196 +
   1.197 +template <class _CharT, class _Traits>
   1.198 +class _Underflow;
   1.199 +
   1.200 + _STLP_TEMPLATE_NULL class _Underflow< char, char_traits<char> >;
   1.201 +
   1.202 +template <class _CharT, class _Traits>
   1.203 +class basic_filebuf : public basic_streambuf<_CharT, _Traits>
   1.204 +{
   1.205 +public:                         // Types.
   1.206 +  typedef _CharT                     char_type;
   1.207 +  typedef typename _Traits::int_type int_type;
   1.208 +  typedef typename _Traits::pos_type pos_type;
   1.209 +  typedef typename _Traits::off_type off_type;
   1.210 +  typedef _Traits                    traits_type;
   1.211 +
   1.212 +  typedef typename _Traits::state_type _State_type;
   1.213 +  typedef basic_streambuf<_CharT, _Traits> _Base;
   1.214 +  typedef basic_filebuf<_CharT, _Traits> _Self;
   1.215 +
   1.216 +public:                         // Constructors, destructor.
   1.217 +  basic_filebuf();  
   1.218 +  ~basic_filebuf();
   1.219 +  
   1.220 +public:                         // Opening and closing files.
   1.221 +  bool is_open() const { return _M_base.__is_open(); }
   1.222 +
   1.223 +  _Self* open(const char* __s, ios_base::openmode __m) {
   1.224 +    return _M_base._M_open(__s, __m) ? this : 0;
   1.225 +  }
   1.226 +
   1.227 +# ifndef _STLP_NO_EXTENSIONS
   1.228 +  // These two version of open() and file descriptor getter are extensions.
   1.229 +  _Self* open(const char* __s, ios_base::openmode __m,
   1.230 +		      long __protection) {
   1.231 +    return _M_base._M_open(__s, __m, __protection) ? this : 0;
   1.232 +  }
   1.233 +  
   1.234 +  _STLP_fd fd() const { return _M_base.__get_fd(); }
   1.235 +
   1.236 +  _Self* open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
   1.237 +    return this->_M_open(__id, _Init_mode);
   1.238 +  }
   1.239 +# endif
   1.240 +
   1.241 +  _Self* _M_open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
   1.242 +    return _M_base._M_open(__id, _Init_mode) ? this : 0;
   1.243 +  }
   1.244 +
   1.245 +  _Self* close();
   1.246 +
   1.247 +protected:                      // Virtual functions from basic_streambuf.
   1.248 +  virtual streamsize showmanyc();
   1.249 +  virtual int_type underflow();
   1.250 +
   1.251 +  virtual int_type pbackfail(int_type = traits_type::eof());
   1.252 +  virtual int_type overflow(int_type = traits_type::eof());
   1.253 +
   1.254 +  virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
   1.255 +  virtual pos_type seekoff(off_type, ios_base::seekdir,
   1.256 +                           ios_base::openmode = ios_base::in | ios_base::out);
   1.257 +  virtual pos_type seekpos(pos_type,
   1.258 +                           ios_base::openmode = ios_base::in | ios_base::out);
   1.259 +
   1.260 +  virtual int sync();
   1.261 +  virtual void imbue(const locale&);
   1.262 +
   1.263 +#ifdef __SYMBIAN32__  
   1.264 +  virtual int save_read_buffer ();
   1.265 +  virtual void _change_input_mode();
   1.266 +#endif
   1.267 +
   1.268 +private:                        // Helper functions.
   1.269 +
   1.270 +  // Precondition: we are currently in putback input mode.  Effect:
   1.271 +  // switches back to ordinary input mode.
   1.272 +  void _M_exit_putback_mode() {
   1.273 +    this->setg(_M_saved_eback, _M_saved_gptr, _M_saved_egptr);
   1.274 +    _M_in_putback_mode = false;
   1.275 +  }
   1.276 +  bool _M_switch_to_input_mode();
   1.277 +  void _M_exit_input_mode();
   1.278 +  bool _M_switch_to_output_mode();
   1.279 +
   1.280 +  int_type _M_input_error();
   1.281 +  int_type _M_underflow_aux();
   1.282 +  //  friend class _Noconv_input<_Traits>;
   1.283 +  //  friend class _Noconv_output<_Traits>;
   1.284 +  friend class _Underflow<_CharT, _Traits>;
   1.285 +
   1.286 +  int_type _M_output_error();
   1.287 +  bool _M_unshift();
   1.288 +
   1.289 +  bool _M_allocate_buffers(_CharT* __buf, streamsize __n);
   1.290 +  bool _M_allocate_buffers();
   1.291 +  void _M_deallocate_buffers();
   1.292 +
   1.293 +  pos_type _M_seek_return(off_type __off, _State_type __state) {
   1.294 +    if (__off != -1) {
   1.295 +      if (_M_in_input_mode)
   1.296 +        _M_exit_input_mode();
   1.297 +#ifndef __SYMBIAN32__	  
   1.298 +      _M_in_input_mode = false; //moved down, because setg again sets  input mode
   1.299 +#endif
   1.300 +      _M_in_output_mode = false;
   1.301 +      _M_in_putback_mode = false;
   1.302 +      _M_in_error_mode = false;
   1.303 +      this->setg(0, 0, 0);
   1.304 +      this->setp(0, 0);
   1.305 +#ifdef __SYMBIAN32__	  
   1.306 +			_M_in_input_mode = false; 
   1.307 +#endif
   1.308 +    }
   1.309 +    
   1.310 +    pos_type __result(__off);
   1.311 +    __result.state(__state);
   1.312 +    return __result;
   1.313 +  }
   1.314 +  
   1.315 +  bool _M_seek_init(bool __do_unshift);
   1.316 +
   1.317 +  void _M_setup_codecvt(const locale&);
   1.318 +
   1.319 +private:                        // Data members used in all modes.
   1.320 +
   1.321 +  _Filebuf_base _M_base;
   1.322 +
   1.323 +private:                        // Locale-related information.
   1.324 +
   1.325 +  unsigned char _M_constant_width;
   1.326 +  unsigned char _M_always_noconv;
   1.327 +  
   1.328 +  // private:                        // Mode flags.
   1.329 +  unsigned char _M_int_buf_dynamic;  // True if internal buffer is heap allocated,
   1.330 +  // false if it was supplied by the user.
   1.331 +  unsigned char _M_in_input_mode;
   1.332 +  unsigned char _M_in_output_mode;
   1.333 +  unsigned char _M_in_error_mode;
   1.334 +  unsigned char _M_in_putback_mode;
   1.335 +  
   1.336 +  // Internal buffer: characters seen by the filebuf's clients.
   1.337 +  _CharT* _M_int_buf;
   1.338 +  _CharT* _M_int_buf_EOS;
   1.339 +  
   1.340 +  // External buffer: characters corresponding to the external file.
   1.341 +  char* _M_ext_buf;
   1.342 +  char* _M_ext_buf_EOS;
   1.343 +
   1.344 +  // The range [_M_ext_buf, _M_ext_buf_converted) contains the external
   1.345 +  // characters corresponding to the sequence in the internal buffer.  The
   1.346 +  // range [_M_ext_buf_converted, _M_ext_buf_end) contains characters that
   1.347 +  // have been read into the external buffer but have not been converted
   1.348 +  // to an internal sequence.
   1.349 +  char* _M_ext_buf_converted;
   1.350 +  char* _M_ext_buf_end;
   1.351 +
   1.352 +  // State corresponding to beginning of internal buffer.
   1.353 +  _State_type _M_state;
   1.354 +
   1.355 +private:                        // Data members used only in input mode.
   1.356 +
   1.357 +  // Similar to _M_state except that it corresponds to
   1.358 +  // the end of the internal buffer instead of the beginning.
   1.359 +  _State_type _M_end_state;
   1.360 +
   1.361 +  // This is a null pointer unless we are in mmap input mode.
   1.362 +  void*     _M_mmap_base;
   1.363 +  streamoff _M_mmap_len;
   1.364 +
   1.365 +private:                        // Data members used only in putback mode.
   1.366 +  _CharT* _M_saved_eback;
   1.367 +  _CharT* _M_saved_gptr;
   1.368 +  _CharT* _M_saved_egptr;
   1.369 +
   1.370 +  typedef codecvt<_CharT, char, _State_type> _Codecvt;
   1.371 +  const _Codecvt* _M_codecvt;
   1.372 +
   1.373 +  int _M_width;                 // Width of the encoding (if constant), else 1
   1.374 +  int _M_max_width;             // Largest possible width of single character.
   1.375 +
   1.376 +
   1.377 +  enum { _S_pback_buf_size = 8 };
   1.378 +  _CharT _M_pback_buf[_S_pback_buf_size];
   1.379 +
   1.380 +  // for _Noconv_output
   1.381 +public:
   1.382 +  bool _M_write(char* __buf,  ptrdiff_t __n) {return _M_base._M_write(__buf, __n); }
   1.383 +
   1.384 +public:
   1.385 +  int_type
   1.386 +  _M_do_noconv_input() {
   1.387 +    _M_ext_buf_converted = _M_ext_buf_end;
   1.388 +    this->setg((char_type*)_M_ext_buf, (char_type*)_M_ext_buf, (char_type*)_M_ext_buf_end);
   1.389 +    return traits_type::to_int_type(*_M_ext_buf);
   1.390 +  }
   1.391 +};
   1.392 +
   1.393 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.394 +_STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<char, char_traits<char> >;
   1.395 +#  if ! defined (_STLP_NO_WCHAR_T)
   1.396 +_STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<wchar_t, char_traits<wchar_t> >;
   1.397 +#  endif
   1.398 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.399 +
   1.400 +// public:
   1.401 +// helper class.
   1.402 +template <class _CharT>
   1.403 +struct _Filebuf_Tmp_Buf
   1.404 +{
   1.405 +  _CharT* _M_ptr;
   1.406 +  _Filebuf_Tmp_Buf(ptrdiff_t __n) : _M_ptr(0) { _M_ptr = new _CharT[__n]; }
   1.407 +  ~_Filebuf_Tmp_Buf() { delete[] _M_ptr; }
   1.408 +};
   1.409 +
   1.410 +
   1.411 +//
   1.412 +// This class had to be designed very carefully to work
   1.413 +// with Visual C++.
   1.414 +//
   1.415 +template <class _Traits>
   1.416 +class _Noconv_output {
   1.417 +public:
   1.418 +  typedef typename _Traits::char_type char_type;
   1.419 +  static bool  _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits >*, 
   1.420 +                                  char_type*, char_type*)
   1.421 +  {
   1.422 +      return false; 
   1.423 +  }
   1.424 +};
   1.425 +
   1.426 +_STLP_TEMPLATE_NULL
   1.427 +class _STLP_CLASS_DECLSPEC _Noconv_output< char_traits<char> > {
   1.428 +public:
   1.429 +  static bool  _STLP_CALL
   1.430 +  _M_doit(basic_filebuf<char, char_traits<char> >* __buf, 
   1.431 +          char* __first, char* __last)
   1.432 +  {
   1.433 +    ptrdiff_t __n = __last - __first;
   1.434 +    if (__buf->_M_write(__first, __n)) {
   1.435 +      return true;
   1.436 +    }
   1.437 +    else
   1.438 +      return false; 
   1.439 +  }
   1.440 +};
   1.441 +
   1.442 +//----------------------------------------------------------------------
   1.443 +// basic_filebuf<> helper functions.
   1.444 +
   1.445 +
   1.446 +//----------------------------------------
   1.447 +// Helper functions for switching between modes.
   1.448 +
   1.449 +//
   1.450 +// This class had to be designed very carefully to work
   1.451 +// with Visual C++.
   1.452 +//
   1.453 +template <class _Traits>
   1.454 +class _Noconv_input {
   1.455 +public:
   1.456 +  typedef typename _Traits::int_type int_type;
   1.457 +  typedef typename _Traits::char_type char_type;
   1.458 +
   1.459 +  static inline int_type _STLP_CALL
   1.460 +  _M_doit(basic_filebuf<char_type, _Traits>*) 
   1.461 +  {
   1.462 +    return 0;
   1.463 +  }
   1.464 +};
   1.465 +
   1.466 +_STLP_TEMPLATE_NULL
   1.467 +class _Noconv_input<char_traits<char> > {
   1.468 +public:
   1.469 +  static inline int _STLP_CALL
   1.470 +  _M_doit(basic_filebuf<char, char_traits<char> >* __buf)  {
   1.471 +    return __buf->_M_do_noconv_input();
   1.472 +  }
   1.473 +};
   1.474 +
   1.475 +// underflow() may be called for one of two reasons.  (1) We've
   1.476 +// been going through the special putback buffer, and we need to move back
   1.477 +// to the regular internal buffer.  (2) We've exhausted the internal buffer,
   1.478 +// and we need to replentish it.  
   1.479 +template <class _CharT, class _Traits>
   1.480 +class _Underflow {
   1.481 +public:
   1.482 +  typedef typename _Traits::int_type int_type;
   1.483 +  typedef _Traits                    traits_type;
   1.484 +  
   1.485 +  static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this);
   1.486 +};
   1.487 +
   1.488 +
   1.489 +// Specialization of underflow: if the character type is char, maybe
   1.490 +// we can use mmap instead of read.
   1.491 +_STLP_TEMPLATE_NULL
   1.492 +class _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> > {
   1.493 +public:
   1.494 +  typedef char_traits<char>::int_type int_type;
   1.495 +  typedef char_traits<char> traits_type;
   1.496 +  _STLP_DECLSPEC static  int _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);
   1.497 +};
   1.498 +
   1.499 +// There is a specialized version of underflow, for basic_filebuf<char>,
   1.500 +// in fstream.cxx.
   1.501 +
   1.502 +template <class _CharT, class _Traits>
   1.503 +_STLP_TYPENAME_ON_RETURN_TYPE _Underflow<_CharT, _Traits>::int_type // _STLP_CALL
   1.504 + _Underflow<_CharT, _Traits>::_M_doit(basic_filebuf<_CharT, _Traits>* __this)
   1.505 +{
   1.506 +  if (!__this->_M_in_input_mode) {
   1.507 +    if (!__this->_M_switch_to_input_mode())
   1.508 +      return traits_type::eof();
   1.509 +  }
   1.510 +  
   1.511 +  else if (__this->_M_in_putback_mode) {
   1.512 +    __this->_M_exit_putback_mode();
   1.513 +    if (__this->gptr() != __this->egptr()) {
   1.514 +      int_type __c = traits_type::to_int_type(*__this->gptr());
   1.515 +      return __c;
   1.516 +    }
   1.517 +  }
   1.518 +  
   1.519 +  return __this->_M_underflow_aux();
   1.520 +}
   1.521 +
   1.522 +#if defined( _STLP_USE_TEMPLATE_EXPORT ) && ! defined (_STLP_NO_WCHAR_T)
   1.523 +_STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;
   1.524 +#endif
   1.525 +
   1.526 +
   1.527 +//----------------------------------------------------------------------
   1.528 +// Class basic_ifstream<>
   1.529 +
   1.530 +template <class _CharT, class _Traits>
   1.531 +class basic_ifstream : public basic_istream<_CharT, _Traits>
   1.532 +{
   1.533 +public:                         // Types
   1.534 +  typedef _CharT                     char_type;
   1.535 +  typedef typename _Traits::int_type int_type;
   1.536 +  typedef typename _Traits::pos_type pos_type;
   1.537 +  typedef typename _Traits::off_type off_type;
   1.538 +  typedef _Traits                    traits_type;
   1.539 +
   1.540 +  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
   1.541 +  typedef basic_istream<_CharT, _Traits>            _Base;
   1.542 +  typedef basic_filebuf<_CharT, _Traits>            _Buf;
   1.543 +
   1.544 +public:                         // Constructors, destructor.
   1.545 +
   1.546 +  basic_ifstream() : 
   1.547 +    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   1.548 +      this->init(&_M_buf);
   1.549 +  }
   1.550 +
   1.551 +  explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) : 
   1.552 +    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0),
   1.553 +    _M_buf() {
   1.554 +      this->init(&_M_buf);
   1.555 +      if (!_M_buf.open(__s, __mod | ios_base::in))
   1.556 +	this->setstate(ios_base::failbit);
   1.557 +  }
   1.558 +
   1.559 +# ifndef _STLP_NO_EXTENSIONS
   1.560 +  explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) : 
   1.561 +    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   1.562 +    this->init(&_M_buf);
   1.563 +    if (!_M_buf.open(__id, __mod | ios_base::in))
   1.564 +      this->setstate(ios_base::failbit);
   1.565 +  }
   1.566 +  basic_ifstream(const char* __s, ios_base::openmode __m,
   1.567 +		 long __protection) : 
   1.568 +    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
   1.569 +    this->init(&_M_buf);
   1.570 +    if (!_M_buf.open(__s, __m | ios_base::in, __protection))
   1.571 +      this->setstate(ios_base::failbit);  
   1.572 +  }
   1.573 +  
   1.574 +# endif
   1.575 +
   1.576 +  ~basic_ifstream() {}
   1.577 +
   1.578 +public:                         // File and buffer operations.
   1.579 +  basic_filebuf<_CharT, _Traits>* rdbuf() const
   1.580 +    { return __CONST_CAST(_Buf*,&_M_buf); }
   1.581 +
   1.582 +  bool is_open() {
   1.583 +    return this->rdbuf()->is_open();
   1.584 +  }
   1.585 +
   1.586 +  void open(const char* __s, ios_base::openmode __mod = ios_base::in) {
   1.587 +    if (!this->rdbuf()->open(__s, __mod | ios_base::in))
   1.588 +      this->setstate(ios_base::failbit);
   1.589 +  }
   1.590 +
   1.591 +  void close() {
   1.592 +    if (!this->rdbuf()->close())
   1.593 +      this->setstate(ios_base::failbit);
   1.594 +  }
   1.595 +
   1.596 +
   1.597 +private:
   1.598 +  basic_filebuf<_CharT, _Traits> _M_buf;
   1.599 +};
   1.600 +
   1.601 +
   1.602 +//----------------------------------------------------------------------
   1.603 +// Class basic_ofstream<>
   1.604 +
   1.605 +template <class _CharT, class _Traits>
   1.606 +class basic_ofstream : public basic_ostream<_CharT, _Traits>
   1.607 +{
   1.608 +public:                         // Types
   1.609 +  typedef _CharT                     char_type;
   1.610 +  typedef typename _Traits::int_type int_type;
   1.611 +  typedef typename _Traits::pos_type pos_type;
   1.612 +  typedef typename _Traits::off_type off_type;
   1.613 +  typedef _Traits                    traits_type;
   1.614 +
   1.615 +  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
   1.616 +  typedef basic_ostream<_CharT, _Traits>            _Base;
   1.617 +  typedef basic_filebuf<_CharT, _Traits>            _Buf;
   1.618 +
   1.619 +public:                         // Constructors, destructor.
   1.620 +  basic_ofstream() : 
   1.621 +    basic_ios<_CharT, _Traits>(), 
   1.622 +    basic_ostream<_CharT, _Traits>(0), _M_buf() {
   1.623 +      this->init(&_M_buf);
   1.624 +  }
   1.625 +  explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out) 
   1.626 +    : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
   1.627 +      _M_buf() {
   1.628 +	this->init(&_M_buf);
   1.629 +	if (!_M_buf.open(__s, __mod | ios_base::out))
   1.630 +	  this->setstate(ios_base::failbit);
   1.631 +  }
   1.632 +
   1.633 +# ifndef _STLP_NO_EXTENSIONS
   1.634 +  explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out) 
   1.635 +    : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
   1.636 +    _M_buf() {
   1.637 + 	this->init(&_M_buf);
   1.638 + 	if (!_M_buf.open(__id, __mod | ios_base::out))
   1.639 + 	  this->setstate(ios_base::failbit);
   1.640 +  }
   1.641 +  basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) : 
   1.642 +    basic_ios<_CharT, _Traits>(),  basic_ostream<_CharT, _Traits>(0), _M_buf() {
   1.643 +    this->init(&_M_buf);
   1.644 +    if (!_M_buf.open(__s, __m | ios_base::out, __protection))
   1.645 +      this->setstate(ios_base::failbit);  
   1.646 +  }
   1.647 +# endif
   1.648 +  
   1.649 +  ~basic_ofstream() {}
   1.650 +
   1.651 +public:                         // File and buffer operations.
   1.652 +  basic_filebuf<_CharT, _Traits>* rdbuf() const
   1.653 +    { return __CONST_CAST(_Buf*,&_M_buf); } 
   1.654 +
   1.655 +  bool is_open() {
   1.656 +    return this->rdbuf()->is_open();
   1.657 +  }
   1.658 +
   1.659 +  void open(const char* __s, ios_base::openmode __mod= ios_base::out) {
   1.660 +    if (!this->rdbuf()->open(__s, __mod | ios_base::out))
   1.661 +      this->setstate(ios_base::failbit);
   1.662 +  }
   1.663 +
   1.664 +  void close() {
   1.665 +    if (!this->rdbuf()->close())
   1.666 +      this->setstate(ios_base::failbit);
   1.667 +  }
   1.668 +
   1.669 +private:
   1.670 +  basic_filebuf<_CharT, _Traits> _M_buf;
   1.671 +};
   1.672 +
   1.673 +
   1.674 +//----------------------------------------------------------------------
   1.675 +// Class basic_fstream<>
   1.676 +
   1.677 +template <class _CharT, class _Traits>
   1.678 +class basic_fstream : public basic_iostream<_CharT, _Traits>
   1.679 +{
   1.680 +public:                         // Types
   1.681 +  typedef _CharT                     char_type;
   1.682 +  typedef typename _Traits::int_type int_type;
   1.683 +  typedef typename _Traits::pos_type pos_type;
   1.684 +  typedef typename _Traits::off_type off_type;
   1.685 +  typedef _Traits                    traits_type;
   1.686 +
   1.687 +  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
   1.688 +  typedef basic_iostream<_CharT, _Traits>           _Base;
   1.689 +  typedef basic_filebuf<_CharT, _Traits>            _Buf;
   1.690 +
   1.691 +public:                         // Constructors, destructor.
   1.692 +  
   1.693 +  _STLP_DECLSPEC basic_fstream();
   1.694 +  explicit basic_fstream(const char* __s,
   1.695 +                         ios_base::openmode __mod = ios_base::in | ios_base::out) :
   1.696 +    basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
   1.697 +      this->init(&_M_buf);
   1.698 +      if (!_M_buf.open(__s, __mod))
   1.699 +	this->setstate(ios_base::failbit);
   1.700 +  }
   1.701 +
   1.702 +# ifndef _STLP_NO_EXTENSIONS
   1.703 +  explicit basic_fstream(int __id,
   1.704 +                         ios_base::openmode __mod = ios_base::in | ios_base::out) :
   1.705 +    basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
   1.706 +    this->init(&_M_buf);
   1.707 +    if (!_M_buf.open(__id, __mod))
   1.708 +      this->setstate(ios_base::failbit);
   1.709 +  }
   1.710 +  basic_fstream(const char* __s, ios_base::openmode __m, long __protection) : 
   1.711 +    basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
   1.712 +    this->init(&_M_buf);
   1.713 +    if (!_M_buf.open(__s, __m, __protection))
   1.714 +      this->setstate(ios_base::failbit);  
   1.715 +  }
   1.716 +# endif    
   1.717 +  _STLP_DECLSPEC ~basic_fstream();
   1.718 +
   1.719 +public:                         // File and buffer operations.
   1.720 +
   1.721 +  basic_filebuf<_CharT, _Traits>* rdbuf() const
   1.722 +    { return __CONST_CAST(_Buf*,&_M_buf); } 
   1.723 +
   1.724 +  bool is_open() {
   1.725 +    return this->rdbuf()->is_open();
   1.726 +  }
   1.727 +
   1.728 +  void open(const char* __s, 
   1.729 +	    ios_base::openmode __mod = 
   1.730 +	    ios_base::in | ios_base::out) {
   1.731 +    if (!this->rdbuf()->open(__s, __mod))
   1.732 +      this->setstate(ios_base::failbit);
   1.733 +  }
   1.734 +
   1.735 +  void close() {
   1.736 +    if (!this->rdbuf()->close())
   1.737 +      this->setstate(ios_base::failbit);
   1.738 +  }
   1.739 +
   1.740 +private:
   1.741 +  basic_filebuf<_CharT, _Traits> _M_buf;
   1.742 +};
   1.743 +
   1.744 +_STLP_END_NAMESPACE
   1.745 +
   1.746 +# if !defined (_STLP_LINK_TIME_INSTANTIATION)
   1.747 +#  include <stl/_fstream.c>
   1.748 +# endif
   1.749 +
   1.750 +_STLP_BEGIN_NAMESPACE
   1.751 +
   1.752 +# if defined (_STLP_USE_TEMPLATE_EXPORT)
   1.753 +_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;
   1.754 +_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;
   1.755 +_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;
   1.756 +#  if ! defined (_STLP_NO_WCHAR_T)
   1.757 +_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;
   1.758 +_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;
   1.759 +_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;
   1.760 +#  endif
   1.761 +# endif /* _STLP_USE_TEMPLATE_EXPORT */
   1.762 +
   1.763 +_STLP_END_NAMESPACE
   1.764 +
   1.765 +#endif /* _STLP_FSTREAM */
   1.766 +
   1.767 +
   1.768 +// Local Variables:
   1.769 +// mode:C++
   1.770 +// End: