PageRenderTime 60ms CodeModel.GetById 12ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 1ms

/project/jni/stlport/stlport/stl/_fstream.h

https://github.com/aichunyu/FFPlayer
C Header | 757 lines | 525 code | 139 blank | 93 comment | 62 complexity | 80bcf8dc705035817fff3d97b0b4be1e MD5 | raw file
  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)
 60typedef void* _STLP_fd;
 61#elif defined (_STLP_USE_UNIX_EMULATION_IO) || defined (_STLP_USE_STDIO_IO) || defined (_STLP_USE_UNIX_IO)
 62typedef 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
 73class _STLP_CLASS_DECLSPEC _Filebuf_base {
 74public:                      // 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
 85public:                      // 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
 91public:                      // Memory-mapped I/O.
 92  void* _M_mmap(streamoff __offset, streamoff __len);
 93  void _M_unmap(void* __mmap_base, streamoff __len);
 94
 95public:
 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  static void _S_initialize();
126
127protected:                      // Static data members.
128  static size_t _M_page_size;
129
130protected:                      // Data members.
131  _STLP_fd _M_file_id;
132#if defined (_STLP_USE_STDIO_IO)
133  // for stdio, the whole FILE* is being kept here
134  FILE* _M_file;
135#endif
136#if defined (_STLP_USE_WIN32_IO)
137  _STLP_fd _M_view_id;
138#endif
139
140  ios_base::openmode _M_openmode     ;
141  unsigned char      _M_is_open      ;
142  unsigned char      _M_should_close ;
143  unsigned char      _M_regular_file ;
144
145public :
146  static size_t  _STLP_CALL __page_size() { return _M_page_size; }
147  int  __o_mode() const { return (int)_M_openmode; }
148  bool __is_open()      const { return (_M_is_open !=0 ); }
149  bool __should_close() const { return (_M_should_close != 0); }
150  bool __regular_file() const { return (_M_regular_file != 0); }
151  _STLP_fd __get_fd() const { return _M_file_id; }
152};
153
154//----------------------------------------------------------------------
155// Class basic_filebuf<>.
156
157// Forward declaration of two helper classes.
158template <class _Traits> class _Noconv_input;
159_STLP_TEMPLATE_NULL
160class _Noconv_input<char_traits<char> >;
161
162template <class _Traits> class _Noconv_output;
163_STLP_TEMPLATE_NULL
164class _Noconv_output< char_traits<char> >;
165
166// There is a specialized version of underflow, for basic_filebuf<char>,
167// in fstream.cxx.
168
169template <class _CharT, class _Traits>
170class _Underflow;
171
172_STLP_TEMPLATE_NULL class _Underflow< char, char_traits<char> >;
173
174template <class _CharT, class _Traits>
175class basic_filebuf : public basic_streambuf<_CharT, _Traits> {
176public:                         // Types.
177  typedef _CharT                     char_type;
178  typedef typename _Traits::int_type int_type;
179  typedef typename _Traits::pos_type pos_type;
180  typedef typename _Traits::off_type off_type;
181  typedef _Traits                    traits_type;
182
183  typedef typename _Traits::state_type _State_type;
184  typedef basic_streambuf<_CharT, _Traits> _Base;
185  typedef basic_filebuf<_CharT, _Traits> _Self;
186
187public:                         // Constructors, destructor.
188  basic_filebuf();
189  ~basic_filebuf();
190
191public:                         // Opening and closing files.
192  bool is_open() const { return _M_base.__is_open(); }
193
194  _Self* open(const char* __s, ios_base::openmode __m) {
195    return _M_base._M_open(__s, __m) ? this : 0;
196  }
197
198#if !defined (_STLP_NO_EXTENSIONS)
199  // These two version of open() and file descriptor getter are extensions.
200  _Self* open(const char* __s, ios_base::openmode __m,
201              long __protection) {
202    return _M_base._M_open(__s, __m, __protection) ? this : 0;
203  }
204
205  _STLP_fd fd() const { return _M_base.__get_fd(); }
206
207  _Self* open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
208    return this->_M_open(__id, _Init_mode);
209  }
210
211#  if defined (_STLP_USE_WIN32_IO)
212  _Self* open(_STLP_fd __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
213    return _M_base._M_open(__id, _Init_mode) ? this : 0;
214  }
215#  endif /* _STLP_USE_WIN32_IO */
216
217#endif
218
219  _Self* _M_open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
220    return _M_base._M_open(__id, _Init_mode) ? this : 0;
221  }
222
223  _Self* close();
224
225protected:                      // Virtual functions from basic_streambuf.
226  virtual streamsize showmanyc();
227  virtual int_type underflow();
228
229  virtual int_type pbackfail(int_type = traits_type::eof());
230  virtual int_type overflow(int_type = traits_type::eof());
231
232  virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
233  virtual pos_type seekoff(off_type, ios_base::seekdir,
234                           ios_base::openmode = ios_base::in | ios_base::out);
235  virtual pos_type seekpos(pos_type,
236                           ios_base::openmode = ios_base::in | ios_base::out);
237
238  virtual int sync();
239  virtual void imbue(const locale&);
240
241private:                        // Helper functions.
242
243  // Precondition: we are currently in putback input mode.  Effect:
244  // switches back to ordinary input mode.
245  void _M_exit_putback_mode() {
246    this->setg(_M_saved_eback, _M_saved_gptr, _M_saved_egptr);
247    _M_in_putback_mode = false;
248  }
249  bool _M_switch_to_input_mode();
250  void _M_exit_input_mode();
251  bool _M_switch_to_output_mode();
252
253  int_type _M_input_error();
254  int_type _M_underflow_aux();
255  //  friend class _Noconv_input<_Traits>;
256  //  friend class _Noconv_output<_Traits>;
257  friend class _Underflow<_CharT, _Traits>;
258
259  int_type _M_output_error();
260  bool _M_unshift();
261
262  bool _M_allocate_buffers(_CharT* __buf, streamsize __n);
263  bool _M_allocate_buffers();
264  void _M_deallocate_buffers();
265
266  pos_type _M_seek_return(off_type __off, _State_type __state) {
267    if (__off != -1) {
268      if (_M_in_input_mode)
269        _M_exit_input_mode();
270      _M_in_input_mode = false;
271      _M_in_output_mode = false;
272      _M_in_putback_mode = false;
273      _M_in_error_mode = false;
274      this->setg(0, 0, 0);
275      this->setp(0, 0);
276    }
277
278    pos_type __result(__off);
279    __result.state(__state);
280    return __result;
281  }
282
283  bool _M_seek_init(bool __do_unshift);
284
285  void _M_setup_codecvt(const locale&, bool __on_imbue = true);
286
287private:                        // Data members used in all modes.
288
289  _Filebuf_base _M_base;
290
291private:                        // Locale-related information.
292
293  unsigned char _M_constant_width;
294  unsigned char _M_always_noconv;
295
296  // private:                        // Mode flags.
297  unsigned char _M_int_buf_dynamic;  // True if internal buffer is heap allocated,
298  // false if it was supplied by the user.
299  unsigned char _M_in_input_mode;
300  unsigned char _M_in_output_mode;
301  unsigned char _M_in_error_mode;
302  unsigned char _M_in_putback_mode;
303
304  // Internal buffer: characters seen by the filebuf's clients.
305  _CharT* _M_int_buf;
306  _CharT* _M_int_buf_EOS;
307
308  // External buffer: characters corresponding to the external file.
309  char* _M_ext_buf;
310  char* _M_ext_buf_EOS;
311
312  // The range [_M_ext_buf, _M_ext_buf_converted) contains the external
313  // characters corresponding to the sequence in the internal buffer.  The
314  // range [_M_ext_buf_converted, _M_ext_buf_end) contains characters that
315  // have been read into the external buffer but have not been converted
316  // to an internal sequence.
317  char* _M_ext_buf_converted;
318  char* _M_ext_buf_end;
319
320  // State corresponding to beginning of internal buffer.
321  _State_type _M_state;
322
323private:                        // Data members used only in input mode.
324
325  // Similar to _M_state except that it corresponds to
326  // the end of the internal buffer instead of the beginning.
327  _State_type _M_end_state;
328
329  // This is a null pointer unless we are in mmap input mode.
330  void*     _M_mmap_base;
331  streamoff _M_mmap_len;
332
333private:                        // Data members used only in putback mode.
334  _CharT* _M_saved_eback;
335  _CharT* _M_saved_gptr;
336  _CharT* _M_saved_egptr;
337
338  typedef codecvt<_CharT, char, _State_type> _Codecvt;
339  const _Codecvt* _M_codecvt;
340
341  int _M_width;                 // Width of the encoding (if constant), else 1
342  int _M_max_width;             // Largest possible width of single character.
343
344
345  enum { _S_pback_buf_size = 8 };
346  _CharT _M_pback_buf[_S_pback_buf_size];
347
348  // for _Noconv_output
349public:
350  bool _M_write(char* __buf,  ptrdiff_t __n) {return _M_base._M_write(__buf, __n); }
351
352public:
353  int_type
354  _M_do_noconv_input() {
355    _M_ext_buf_converted = _M_ext_buf_end;
356    /* this-> */ _Base::setg((char_type*)_M_ext_buf, (char_type*)_M_ext_buf, (char_type*)_M_ext_buf_end);
357    return traits_type::to_int_type(*_M_ext_buf);
358  }
359};
360
361#if defined (_STLP_USE_TEMPLATE_EXPORT)
362_STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<char, char_traits<char> >;
363#  if ! defined (_STLP_NO_WCHAR_T)
364_STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<wchar_t, char_traits<wchar_t> >;
365#  endif
366#endif /* _STLP_USE_TEMPLATE_EXPORT */
367
368// public:
369// helper class.
370template <class _CharT>
371struct _Filebuf_Tmp_Buf {
372  _CharT* _M_ptr;
373  _Filebuf_Tmp_Buf(ptrdiff_t __n) : _M_ptr(0) { _M_ptr = new _CharT[__n]; }
374  ~_Filebuf_Tmp_Buf() { delete[] _M_ptr; }
375};
376
377
378//
379// This class had to be designed very carefully to work
380// with Visual C++.
381//
382template <class _Traits>
383class _Noconv_output {
384public:
385  typedef typename _Traits::char_type char_type;
386  static bool  _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits >*,
387                                  char_type*, char_type*)
388  { return false; }
389};
390
391_STLP_TEMPLATE_NULL
392class _STLP_CLASS_DECLSPEC _Noconv_output< char_traits<char> > {
393public:
394  static bool  _STLP_CALL
395  _M_doit(basic_filebuf<char, char_traits<char> >* __buf,
396          char* __first, char* __last) {
397    ptrdiff_t __n = __last - __first;
398    return (__buf->_M_write(__first, __n));
399  }
400};
401
402//----------------------------------------------------------------------
403// basic_filebuf<> helper functions.
404
405
406//----------------------------------------
407// Helper functions for switching between modes.
408
409//
410// This class had to be designed very carefully to work
411// with Visual C++.
412//
413template <class _Traits>
414class _Noconv_input {
415public:
416  typedef typename _Traits::int_type int_type;
417  typedef typename _Traits::char_type char_type;
418
419  static inline int_type _STLP_CALL
420  _M_doit(basic_filebuf<char_type, _Traits>*)
421  { return _Traits::eof(); }
422};
423
424_STLP_TEMPLATE_NULL
425class _Noconv_input<char_traits<char> > {
426public:
427  static inline int _STLP_CALL
428  _M_doit(basic_filebuf<char, char_traits<char> >* __buf) {
429    return __buf->_M_do_noconv_input();
430  }
431};
432
433// underflow() may be called for one of two reasons.  (1) We've
434// been going through the special putback buffer, and we need to move back
435// to the regular internal buffer.  (2) We've exhausted the internal buffer,
436// and we need to replentish it.
437template <class _CharT, class _Traits>
438class _Underflow {
439public:
440  typedef typename _Traits::int_type int_type;
441  typedef _Traits                    traits_type;
442
443  static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this);
444};
445
446
447// Specialization of underflow: if the character type is char, maybe
448// we can use mmap instead of read.
449_STLP_TEMPLATE_NULL
450class _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> > {
451public:
452  typedef char_traits<char>::int_type int_type;
453  typedef char_traits<char> traits_type;
454  static  int _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);
455};
456
457// There is a specialized version of underflow, for basic_filebuf<char>,
458// in fstream.cxx.
459
460template <class _CharT, class _Traits>
461_STLP_TYPENAME_ON_RETURN_TYPE _Underflow<_CharT, _Traits>::int_type // _STLP_CALL
462 _Underflow<_CharT, _Traits>::_M_doit(basic_filebuf<_CharT, _Traits>* __this) {
463  if (!__this->_M_in_input_mode) {
464    if (!__this->_M_switch_to_input_mode())
465      return traits_type::eof();
466  }
467  else if (__this->_M_in_putback_mode) {
468    __this->_M_exit_putback_mode();
469    if (__this->gptr() != __this->egptr()) {
470      int_type __c = traits_type::to_int_type(*__this->gptr());
471      return __c;
472    }
473  }
474
475  return __this->_M_underflow_aux();
476}
477
478#if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_NO_WCHAR_T)
479_STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;
480#endif
481
482//----------------------------------------------------------------------
483// Class basic_ifstream<>
484
485template <class _CharT, class _Traits>
486class basic_ifstream : public basic_istream<_CharT, _Traits> {
487public:                         // Types
488  typedef _CharT                     char_type;
489  typedef typename _Traits::int_type int_type;
490  typedef typename _Traits::pos_type pos_type;
491  typedef typename _Traits::off_type off_type;
492  typedef _Traits                    traits_type;
493
494  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
495  typedef basic_istream<_CharT, _Traits>            _Base;
496  typedef basic_filebuf<_CharT, _Traits>            _Buf;
497
498public:                         // Constructors, destructor.
499
500  basic_ifstream() :
501    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
502      this->init(&_M_buf);
503  }
504
505  explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) :
506    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0),
507    _M_buf() {
508      this->init(&_M_buf);
509      if (!_M_buf.open(__s, __mod | ios_base::in))
510        this->setstate(ios_base::failbit);
511  }
512
513#if !defined (_STLP_NO_EXTENSIONS)
514  explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) :
515    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
516    this->init(&_M_buf);
517    if (!_M_buf.open(__id, __mod | ios_base::in))
518      this->setstate(ios_base::failbit);
519  }
520  basic_ifstream(const char* __s, ios_base::openmode __m,
521     long __protection) :
522    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
523    this->init(&_M_buf);
524    if (!_M_buf.open(__s, __m | ios_base::in, __protection))
525      this->setstate(ios_base::failbit);
526  }
527
528#  if defined (_STLP_USE_WIN32_IO)
529  explicit basic_ifstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::in) :
530    basic_ios<_CharT, _Traits>(),  basic_istream<_CharT, _Traits>(0), _M_buf() {
531    this->init(&_M_buf);
532    if (!_M_buf.open(__id, __mod | ios_base::in))
533      this->setstate(ios_base::failbit);
534  }
535#  endif /* _STLP_USE_WIN32_IO */
536#endif
537
538  ~basic_ifstream() {}
539
540public:                         // File and buffer operations.
541  basic_filebuf<_CharT, _Traits>* rdbuf() const
542    { return __CONST_CAST(_Buf*,&_M_buf); }
543
544  bool is_open() {
545    return this->rdbuf()->is_open();
546  }
547
548  void open(const char* __s, ios_base::openmode __mod = ios_base::in) {
549    if (!this->rdbuf()->open(__s, __mod | ios_base::in))
550      this->setstate(ios_base::failbit);
551  }
552
553  void close() {
554    if (!this->rdbuf()->close())
555      this->setstate(ios_base::failbit);
556  }
557
558private:
559  basic_filebuf<_CharT, _Traits> _M_buf;
560};
561
562
563//----------------------------------------------------------------------
564// Class basic_ofstream<>
565
566template <class _CharT, class _Traits>
567class basic_ofstream : public basic_ostream<_CharT, _Traits> {
568public:                         // Types
569  typedef _CharT                     char_type;
570  typedef typename _Traits::int_type int_type;
571  typedef typename _Traits::pos_type pos_type;
572  typedef typename _Traits::off_type off_type;
573  typedef _Traits                    traits_type;
574
575  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
576  typedef basic_ostream<_CharT, _Traits>            _Base;
577  typedef basic_filebuf<_CharT, _Traits>            _Buf;
578
579public:                         // Constructors, destructor.
580  basic_ofstream() :
581    basic_ios<_CharT, _Traits>(),
582    basic_ostream<_CharT, _Traits>(0), _M_buf() {
583      this->init(&_M_buf);
584  }
585  explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out)
586    : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() {
587    this->init(&_M_buf);
588    if (!_M_buf.open(__s, __mod | ios_base::out))
589      this->setstate(ios_base::failbit);
590  }
591
592#if !defined (_STLP_NO_EXTENSIONS)
593  explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out)
594    : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
595    _M_buf() {
596   this->init(&_M_buf);
597   if (!_M_buf.open(__id, __mod | ios_base::out))
598     this->setstate(ios_base::failbit);
599  }
600  basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) :
601    basic_ios<_CharT, _Traits>(),  basic_ostream<_CharT, _Traits>(0), _M_buf() {
602    this->init(&_M_buf);
603    if (!_M_buf.open(__s, __m | ios_base::out, __protection))
604      this->setstate(ios_base::failbit);
605  }
606#  if defined (_STLP_USE_WIN32_IO)
607  explicit basic_ofstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::out)
608    : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
609    _M_buf() {
610   this->init(&_M_buf);
611   if (!_M_buf.open(__id, __mod | ios_base::out))
612     this->setstate(ios_base::failbit);
613  }
614#  endif /* _STLP_USE_WIN32_IO */
615#endif
616
617  ~basic_ofstream() {}
618
619public:                         // File and buffer operations.
620  basic_filebuf<_CharT, _Traits>* rdbuf() const
621    { return __CONST_CAST(_Buf*,&_M_buf); }
622
623  bool is_open() {
624    return this->rdbuf()->is_open();
625  }
626
627  void open(const char* __s, ios_base::openmode __mod= ios_base::out) {
628    if (!this->rdbuf()->open(__s, __mod | ios_base::out))
629      this->setstate(ios_base::failbit);
630  }
631
632  void close() {
633    if (!this->rdbuf()->close())
634      this->setstate(ios_base::failbit);
635  }
636
637private:
638  basic_filebuf<_CharT, _Traits> _M_buf;
639};
640
641
642//----------------------------------------------------------------------
643// Class basic_fstream<>
644
645template <class _CharT, class _Traits>
646class basic_fstream : public basic_iostream<_CharT, _Traits> {
647public:                         // Types
648  typedef _CharT                     char_type;
649  typedef typename _Traits::int_type int_type;
650  typedef typename _Traits::pos_type pos_type;
651  typedef typename _Traits::off_type off_type;
652  typedef _Traits                    traits_type;
653
654  typedef basic_ios<_CharT, _Traits>                _Basic_ios;
655  typedef basic_iostream<_CharT, _Traits>           _Base;
656  typedef basic_filebuf<_CharT, _Traits>            _Buf;
657
658public:                         // Constructors, destructor.
659
660  basic_fstream()
661    : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
662      this->init(&_M_buf);
663  }
664
665  explicit basic_fstream(const char* __s,
666                         ios_base::openmode __mod = ios_base::in | ios_base::out) :
667    basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
668      this->init(&_M_buf);
669      if (!_M_buf.open(__s, __mod))
670        this->setstate(ios_base::failbit);
671  }
672
673#if !defined (_STLP_NO_EXTENSIONS)
674  explicit basic_fstream(int __id,
675                         ios_base::openmode __mod = ios_base::in | ios_base::out) :
676    basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
677    this->init(&_M_buf);
678    if (!_M_buf.open(__id, __mod))
679      this->setstate(ios_base::failbit);
680  }
681  basic_fstream(const char* __s, ios_base::openmode __m, long __protection) :
682    basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
683    this->init(&_M_buf);
684    if (!_M_buf.open(__s, __m, __protection))
685      this->setstate(ios_base::failbit);
686  }
687#  if defined (_STLP_USE_WIN32_IO)
688  explicit basic_fstream(_STLP_fd __id,
689    ios_base::openmode __mod = ios_base::in | ios_base::out) :
690    basic_ios<_CharT, _Traits>(),  basic_iostream<_CharT, _Traits>(0), _M_buf() {
691    this->init(&_M_buf);
692    if (!_M_buf.open(__id, __mod))
693      this->setstate(ios_base::failbit);
694  }
695#  endif /* _STLP_USE_WIN32_IO */
696#endif
697  ~basic_fstream() {}
698
699public:                         // File and buffer operations.
700
701  basic_filebuf<_CharT, _Traits>* rdbuf() const
702    { return __CONST_CAST(_Buf*,&_M_buf); }
703
704  bool is_open() {
705    return this->rdbuf()->is_open();
706  }
707
708  void open(const char* __s,
709      ios_base::openmode __mod =
710      ios_base::in | ios_base::out) {
711    if (!this->rdbuf()->open(__s, __mod))
712      this->setstate(ios_base::failbit);
713  }
714
715  void close() {
716    if (!this->rdbuf()->close())
717      this->setstate(ios_base::failbit);
718  }
719
720private:
721  basic_filebuf<_CharT, _Traits> _M_buf;
722
723#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
724  typedef basic_fstream<_CharT, _Traits> _Self;
725  //explicitely defined as private to avoid warnings:
726  basic_fstream(_Self const&);
727  _Self& operator = (_Self const&);
728#endif
729};
730
731_STLP_END_NAMESPACE
732
733#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
734#  include <stl/_fstream.c>
735#endif
736
737_STLP_BEGIN_NAMESPACE
738
739#if defined (_STLP_USE_TEMPLATE_EXPORT)
740_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;
741_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;
742_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;
743#  if ! defined (_STLP_NO_WCHAR_T)
744_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;
745_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;
746_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;
747#  endif
748#endif /* _STLP_USE_TEMPLATE_EXPORT */
749
750_STLP_END_NAMESPACE
751
752#endif /* _STLP_FSTREAM */
753
754
755// Local Variables:
756// mode:C++
757// End: