2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
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.
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.
24 #ifndef _STLP_INTERNAL_FSTREAM_H
25 #define _STLP_INTERNAL_FSTREAM_H
27 #if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
28 # error This header file requires the -LANG:std option
31 #ifndef _STLP_INTERNAL_STREAMBUF
32 # include <stl/_streambuf.h>
35 #ifndef _STLP_INTERNAL_ISTREAM
36 # include <stl/_istream.h>
39 #ifndef _STLP_INTERNAL_CODECVT_H
40 # include <stl/_codecvt.h>
43 #if !defined (_STLP_USE_UNIX_IO) && !defined(_STLP_USE_WIN32_IO) && \
44 !defined (_STLP_USE_UNIX_EMULATION_IO) && !defined (_STLP_USE_STDIO_IO)
46 # if defined (_STLP_UNIX) || defined (__CYGWIN__) || defined (__amigaos__) || defined (__EMX__)
47 // open/close/read/write
48 # define _STLP_USE_UNIX_IO
49 # elif defined (_STLP_WIN32) && !defined (__SYMBIAN32__)
50 // CreateFile/ReadFile/WriteFile
51 # define _STLP_USE_WIN32_IO
52 # elif defined (_STLP_WIN16) || defined (_STLP_MAC)
54 # define _STLP_USE_UNIX_EMULATION_IO
57 # define _STLP_USE_STDIO_IO
58 # endif /* _STLP_UNIX */
59 #endif /* mode selection */
61 #if defined (_STLP_USE_WIN32_IO)
62 typedef void* _STLP_fd;
63 #elif defined (_STLP_USE_UNIX_EMULATION_IO) || defined (_STLP_USE_STDIO_IO) || defined (_STLP_USE_UNIX_IO)
66 # error "Configure i/o !"
69 #if defined(__SYMBIAN32__WSD__)
70 size_t& get_fstream_Filebuf_Base_GetPageSize();
71 #define _M_page_size get_fstream_Filebuf_Base_GetPageSize()
72 #endif //__SYMBIAN32__WSD__
76 //----------------------------------------------------------------------
77 // Class _Filebuf_base, a private base class to factor out the system-
78 // dependent code from basic_filebuf<>.
80 class _STLP_CLASS_DECLSPEC _Filebuf_base {
81 public: // Opening and closing files.
82 _STLP_DECLSPEC _Filebuf_base();
84 _STLP_DECLSPEC bool _M_open(const char*, ios_base::openmode, long __protection);
85 _STLP_DECLSPEC bool _M_open(const char*, ios_base::openmode);
86 _STLP_DECLSPEC bool _M_open(int __id, ios_base::openmode = ios_base::__default_mode);
87 #if defined (_STLP_USE_WIN32_IO)
88 bool _M_open(_STLP_fd __id, ios_base::openmode = ios_base::__default_mode);
89 #endif /* _STLP_USE_WIN32_IO */
90 _STLP_DECLSPEC bool _M_close();
92 public: // Low-level I/O, like Unix read/write
93 _STLP_DECLSPEC ptrdiff_t _M_read(char* __buf, ptrdiff_t __n);
94 _STLP_DECLSPEC streamoff _M_seek(streamoff __offset, ios_base::seekdir __dir);
95 _STLP_DECLSPEC streamoff _M_file_size();
96 _STLP_DECLSPEC bool _M_write(char* __buf, ptrdiff_t __n);
98 public: // Memory-mapped I/O.
99 _STLP_DECLSPEC void* _M_mmap(streamoff __offset, streamoff __len);
100 _STLP_DECLSPEC void _M_unmap(void* __mmap_base, streamoff __len);
103 // Returns a value n such that, if pos is the file pointer at the
104 // beginning of the range [first, last), pos + n is the file pointer at
105 // the end. On many operating systems n == __last - __first.
106 // In Unix, writing n characters always bumps the file position by n.
107 // In Windows text mode, however, it bumps the file position by n + m,
108 // where m is the number of newlines in the range. That's because an
109 // internal \n corresponds to an external two-character sequence.
110 streamoff _M_get_offset(char* __first, char* __last) {
111 #if defined (_STLP_UNIX) || defined (_STLP_MAC)
112 return __last - __first;
113 #else // defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS) || defined(N_PLAT_NLM)
114 return ( (_M_openmode & ios_base::binary) != 0 )
116 : count(__first, __last, '\n') + (__last - __first);
120 // Returns true if we're in binary mode or if we're using an OS or file
121 // system where there is no distinction between text and binary mode.
122 bool _M_in_binary_mode() const {
123 #if defined (_STLP_UNIX) || defined (_STLP_MAC) || defined(__BEOS__) || defined (__amigaos__) || defined (__SYMBIAN32__)
125 #elif defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS) || defined (_STLP_VM) || defined (__EMX__) || defined(N_PLAT_NLM)
126 return (_M_openmode & ios_base::binary) != 0;
132 static void _S_initialize();
134 protected: // Static data members.
135 # if !defined(__SYMBIAN32__WSD__)
136 static size_t _M_page_size;
137 #endif //__SYMBIAN32__
139 protected: // Data members.
141 #if defined (_STLP_USE_STDIO_IO)
142 // for stdio, the whole FILE* is being kept here
145 #if defined (_STLP_USE_WIN32_IO)
149 ios_base::openmode _M_openmode ;
150 unsigned char _M_is_open ;
151 unsigned char _M_should_close ;
152 unsigned char _M_regular_file ;
155 #if defined(__SYMBIAN32__) && defined (__EPOC32__)
156 /* On Symbian,we can't make this inline. It violates one address rule */
157 _STLP_DECLSPEC static size_t __page_size();
159 static size_t _STLP_CALL __page_size() { return _M_page_size; }
161 int __o_mode() const { return (int)_M_openmode; }
162 bool __is_open() const { return (_M_is_open !=0 ); }
163 bool __should_close() const { return (_M_should_close != 0); }
164 bool __regular_file() const { return (_M_regular_file != 0); }
165 _STLP_fd __get_fd() const { return _M_file_id; }
168 //----------------------------------------------------------------------
169 // Class basic_filebuf<>.
171 // Forward declaration of two helper classes.
172 template <class _Traits> class _Noconv_input;
174 class _Noconv_input<char_traits<char> >;
176 template <class _Traits> class _Noconv_output;
178 class _Noconv_output< char_traits<char> >;
180 // There is a specialized version of underflow, for basic_filebuf<char>,
183 template <class _CharT, class _Traits>
186 _STLP_TEMPLATE_NULL class _Underflow< char, char_traits<char> >;
188 template <class _CharT, class _Traits>
189 class basic_filebuf : public basic_streambuf<_CharT, _Traits> {
191 typedef _CharT char_type;
192 typedef typename _Traits::int_type int_type;
193 typedef typename _Traits::pos_type pos_type;
194 typedef typename _Traits::off_type off_type;
195 typedef _Traits traits_type;
197 typedef typename _Traits::state_type _State_type;
198 typedef basic_streambuf<_CharT, _Traits> _Base;
199 typedef basic_filebuf<_CharT, _Traits> _Self;
201 public: // Constructors, destructor.
205 public: // Opening and closing files.
206 bool is_open() const { return _M_base.__is_open(); }
208 _Self* open(const char* __s, ios_base::openmode __m) {
209 return _M_base._M_open(__s, __m) ? this : 0;
212 #if !defined (_STLP_NO_EXTENSIONS)
213 // These two version of open() and file descriptor getter are extensions.
214 _Self* open(const char* __s, ios_base::openmode __m,
216 return _M_base._M_open(__s, __m, __protection) ? this : 0;
219 _STLP_fd fd() const { return _M_base.__get_fd(); }
221 _Self* open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
222 return this->_M_open(__id, _Init_mode);
225 # if defined (_STLP_USE_WIN32_IO)
226 _Self* open(_STLP_fd __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
227 return _M_base._M_open(__id, _Init_mode) ? this : 0;
229 # endif /* _STLP_USE_WIN32_IO */
233 _Self* _M_open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
234 return _M_base._M_open(__id, _Init_mode) ? this : 0;
239 protected: // Virtual functions from basic_streambuf.
240 virtual streamsize showmanyc();
241 virtual int_type underflow();
243 virtual int_type pbackfail(int_type = traits_type::eof());
244 virtual int_type overflow(int_type = traits_type::eof());
246 virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
247 virtual pos_type seekoff(off_type, ios_base::seekdir,
248 ios_base::openmode = ios_base::in | ios_base::out);
249 virtual pos_type seekpos(pos_type,
250 ios_base::openmode = ios_base::in | ios_base::out);
253 virtual void imbue(const locale&);
255 private: // Helper functions.
257 // Precondition: we are currently in putback input mode. Effect:
258 // switches back to ordinary input mode.
259 void _M_exit_putback_mode() {
260 this->setg(_M_saved_eback, _M_saved_gptr, _M_saved_egptr);
261 _M_in_putback_mode = false;
263 bool _M_switch_to_input_mode();
264 void _M_exit_input_mode();
265 bool _M_switch_to_output_mode();
267 int_type _M_input_error();
268 int_type _M_underflow_aux();
269 // friend class _Noconv_input<_Traits>;
270 // friend class _Noconv_output<_Traits>;
271 friend class _Underflow<_CharT, _Traits>;
273 int_type _M_output_error();
276 bool _M_allocate_buffers(_CharT* __buf, streamsize __n);
277 bool _M_allocate_buffers();
278 void _M_deallocate_buffers();
280 pos_type _M_seek_return(off_type __off, _State_type __state) {
282 if (_M_in_input_mode)
283 _M_exit_input_mode();
284 _M_in_input_mode = false;
285 _M_in_output_mode = false;
286 _M_in_putback_mode = false;
287 _M_in_error_mode = false;
292 pos_type __result(__off);
293 __result.state(__state);
297 bool _M_seek_init(bool __do_unshift);
299 void _M_setup_codecvt(const locale&, bool __on_imbue = true);
301 private: // Data members used in all modes.
303 _Filebuf_base _M_base;
305 private: // Locale-related information.
307 unsigned char _M_constant_width;
308 unsigned char _M_always_noconv;
310 // private: // Mode flags.
311 unsigned char _M_int_buf_dynamic; // True if internal buffer is heap allocated,
312 // false if it was supplied by the user.
313 unsigned char _M_in_input_mode;
314 unsigned char _M_in_output_mode;
315 unsigned char _M_in_error_mode;
316 unsigned char _M_in_putback_mode;
318 // Internal buffer: characters seen by the filebuf's clients.
320 _CharT* _M_int_buf_EOS;
322 // External buffer: characters corresponding to the external file.
324 char* _M_ext_buf_EOS;
326 // The range [_M_ext_buf, _M_ext_buf_converted) contains the external
327 // characters corresponding to the sequence in the internal buffer. The
328 // range [_M_ext_buf_converted, _M_ext_buf_end) contains characters that
329 // have been read into the external buffer but have not been converted
330 // to an internal sequence.
331 char* _M_ext_buf_converted;
332 char* _M_ext_buf_end;
334 // State corresponding to beginning of internal buffer.
335 _State_type _M_state;
337 private: // Data members used only in input mode.
339 // Similar to _M_state except that it corresponds to
340 // the end of the internal buffer instead of the beginning.
341 _State_type _M_end_state;
343 // This is a null pointer unless we are in mmap input mode.
345 streamoff _M_mmap_len;
347 private: // Data members used only in putback mode.
348 _CharT* _M_saved_eback;
349 _CharT* _M_saved_gptr;
350 _CharT* _M_saved_egptr;
352 typedef codecvt<_CharT, char, _State_type> _Codecvt;
353 const _Codecvt* _M_codecvt;
355 int _M_width; // Width of the encoding (if constant), else 1
356 int _M_max_width; // Largest possible width of single character.
359 enum { _S_pback_buf_size = 8 };
360 _CharT _M_pback_buf[_S_pback_buf_size];
362 // for _Noconv_output
364 bool _M_write(char* __buf, ptrdiff_t __n) {return _M_base._M_write(__buf, __n); }
368 _M_do_noconv_input() {
369 _M_ext_buf_converted = _M_ext_buf_end;
370 /* this-> */ _Base::setg((char_type*)_M_ext_buf, (char_type*)_M_ext_buf, (char_type*)_M_ext_buf_end);
371 return traits_type::to_int_type(*_M_ext_buf);
375 #if defined (_STLP_USE_TEMPLATE_EXPORT)
376 _STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<char, char_traits<char> >;
377 # if ! defined (_STLP_NO_WCHAR_T)
378 _STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<wchar_t, char_traits<wchar_t> >;
380 #endif /* _STLP_USE_TEMPLATE_EXPORT */
384 template <class _CharT>
385 struct _Filebuf_Tmp_Buf {
387 _Filebuf_Tmp_Buf(ptrdiff_t __n) : _M_ptr(0) { _M_ptr = new _CharT[__n]; }
388 ~_Filebuf_Tmp_Buf() { delete[] _M_ptr; }
393 // This class had to be designed very carefully to work
396 template <class _Traits>
397 class _Noconv_output {
399 typedef typename _Traits::char_type char_type;
400 static bool _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits >*,
401 char_type*, char_type*)
406 class _STLP_CLASS_DECLSPEC _Noconv_output< char_traits<char> > {
408 static bool _STLP_CALL
409 _M_doit(basic_filebuf<char, char_traits<char> >* __buf,
410 char* __first, char* __last) {
411 ptrdiff_t __n = __last - __first;
412 return (__buf->_M_write(__first, __n));
416 //----------------------------------------------------------------------
417 // basic_filebuf<> helper functions.
420 //----------------------------------------
421 // Helper functions for switching between modes.
424 // This class had to be designed very carefully to work
427 template <class _Traits>
428 class _Noconv_input {
430 typedef typename _Traits::int_type int_type;
431 typedef typename _Traits::char_type char_type;
433 static inline int_type _STLP_CALL
434 _M_doit(basic_filebuf<char_type, _Traits>*)
435 { return _Traits::eof(); }
439 class _Noconv_input<char_traits<char> > {
441 static inline int _STLP_CALL
442 _M_doit(basic_filebuf<char, char_traits<char> >* __buf) {
443 return __buf->_M_do_noconv_input();
447 // underflow() may be called for one of two reasons. (1) We've
448 // been going through the special putback buffer, and we need to move back
449 // to the regular internal buffer. (2) We've exhausted the internal buffer,
450 // and we need to replentish it.
451 template <class _CharT, class _Traits>
454 typedef typename _Traits::int_type int_type;
455 typedef _Traits traits_type;
457 static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this);
461 // Specialization of underflow: if the character type is char, maybe
462 // we can use mmap instead of read.
464 class _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> > {
466 typedef char_traits<char>::int_type int_type;
467 typedef char_traits<char> traits_type;
468 _STLP_DECLSPEC static int _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);
471 // There is a specialized version of underflow, for basic_filebuf<char>,
474 template <class _CharT, class _Traits>
475 _STLP_TYPENAME_ON_RETURN_TYPE _Underflow<_CharT, _Traits>::int_type // _STLP_CALL
476 _Underflow<_CharT, _Traits>::_M_doit(basic_filebuf<_CharT, _Traits>* __this) {
477 if (!__this->_M_in_input_mode) {
478 if (!__this->_M_switch_to_input_mode())
479 return traits_type::eof();
481 else if (__this->_M_in_putback_mode) {
482 __this->_M_exit_putback_mode();
483 if (__this->gptr() != __this->egptr()) {
484 int_type __c = traits_type::to_int_type(*__this->gptr());
489 return __this->_M_underflow_aux();
492 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_NO_WCHAR_T)
493 _STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;
496 //----------------------------------------------------------------------
497 // Class basic_ifstream<>
499 template <class _CharT, class _Traits>
500 class basic_ifstream : public basic_istream<_CharT, _Traits> {
502 typedef _CharT char_type;
503 typedef typename _Traits::int_type int_type;
504 typedef typename _Traits::pos_type pos_type;
505 typedef typename _Traits::off_type off_type;
506 typedef _Traits traits_type;
508 typedef basic_ios<_CharT, _Traits> _Basic_ios;
509 typedef basic_istream<_CharT, _Traits> _Base;
510 typedef basic_filebuf<_CharT, _Traits> _Buf;
512 public: // Constructors, destructor.
515 basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
519 explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) :
520 basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0),
523 if (!_M_buf.open(__s, __mod | ios_base::in))
524 this->setstate(ios_base::failbit);
527 #if !defined (_STLP_NO_EXTENSIONS)
528 explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) :
529 basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
531 if (!_M_buf.open(__id, __mod | ios_base::in))
532 this->setstate(ios_base::failbit);
534 basic_ifstream(const char* __s, ios_base::openmode __m,
536 basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
538 if (!_M_buf.open(__s, __m | ios_base::in, __protection))
539 this->setstate(ios_base::failbit);
542 # if defined (_STLP_USE_WIN32_IO)
543 explicit basic_ifstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::in) :
544 basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
546 if (!_M_buf.open(__id, __mod | ios_base::in))
547 this->setstate(ios_base::failbit);
549 # endif /* _STLP_USE_WIN32_IO */
554 public: // File and buffer operations.
555 basic_filebuf<_CharT, _Traits>* rdbuf() const
556 { return __CONST_CAST(_Buf*,&_M_buf); }
559 return this->rdbuf()->is_open();
562 void open(const char* __s, ios_base::openmode __mod = ios_base::in) {
563 if (!this->rdbuf()->open(__s, __mod | ios_base::in))
564 this->setstate(ios_base::failbit);
568 if (!this->rdbuf()->close())
569 this->setstate(ios_base::failbit);
573 basic_filebuf<_CharT, _Traits> _M_buf;
577 //----------------------------------------------------------------------
578 // Class basic_ofstream<>
580 template <class _CharT, class _Traits>
581 class basic_ofstream : public basic_ostream<_CharT, _Traits> {
583 typedef _CharT char_type;
584 typedef typename _Traits::int_type int_type;
585 typedef typename _Traits::pos_type pos_type;
586 typedef typename _Traits::off_type off_type;
587 typedef _Traits traits_type;
589 typedef basic_ios<_CharT, _Traits> _Basic_ios;
590 typedef basic_ostream<_CharT, _Traits> _Base;
591 typedef basic_filebuf<_CharT, _Traits> _Buf;
593 public: // Constructors, destructor.
595 basic_ios<_CharT, _Traits>(),
596 basic_ostream<_CharT, _Traits>(0), _M_buf() {
599 explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out)
600 : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() {
602 if (!_M_buf.open(__s, __mod | ios_base::out))
603 this->setstate(ios_base::failbit);
606 #if !defined (_STLP_NO_EXTENSIONS)
607 explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out)
608 : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
611 if (!_M_buf.open(__id, __mod | ios_base::out))
612 this->setstate(ios_base::failbit);
614 basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) :
615 basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() {
617 if (!_M_buf.open(__s, __m | ios_base::out, __protection))
618 this->setstate(ios_base::failbit);
620 # if defined (_STLP_USE_WIN32_IO)
621 explicit basic_ofstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::out)
622 : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
625 if (!_M_buf.open(__id, __mod | ios_base::out))
626 this->setstate(ios_base::failbit);
628 # endif /* _STLP_USE_WIN32_IO */
633 public: // File and buffer operations.
634 basic_filebuf<_CharT, _Traits>* rdbuf() const
635 { return __CONST_CAST(_Buf*,&_M_buf); }
638 return this->rdbuf()->is_open();
641 void open(const char* __s, ios_base::openmode __mod= ios_base::out) {
642 if (!this->rdbuf()->open(__s, __mod | ios_base::out))
643 this->setstate(ios_base::failbit);
647 if (!this->rdbuf()->close())
648 this->setstate(ios_base::failbit);
652 basic_filebuf<_CharT, _Traits> _M_buf;
656 //----------------------------------------------------------------------
657 // Class basic_fstream<>
659 template <class _CharT, class _Traits>
660 class basic_fstream : public basic_iostream<_CharT, _Traits> {
662 typedef _CharT char_type;
663 typedef typename _Traits::int_type int_type;
664 typedef typename _Traits::pos_type pos_type;
665 typedef typename _Traits::off_type off_type;
666 typedef _Traits traits_type;
668 typedef basic_ios<_CharT, _Traits> _Basic_ios;
669 typedef basic_iostream<_CharT, _Traits> _Base;
670 typedef basic_filebuf<_CharT, _Traits> _Buf;
672 public: // Constructors, destructor.
675 : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
679 explicit basic_fstream(const char* __s,
680 ios_base::openmode __mod = ios_base::in | ios_base::out) :
681 basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
683 if (!_M_buf.open(__s, __mod))
684 this->setstate(ios_base::failbit);
687 #if !defined (_STLP_NO_EXTENSIONS)
688 explicit basic_fstream(int __id,
689 ios_base::openmode __mod = ios_base::in | ios_base::out) :
690 basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
692 if (!_M_buf.open(__id, __mod))
693 this->setstate(ios_base::failbit);
695 basic_fstream(const char* __s, ios_base::openmode __m, long __protection) :
696 basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
698 if (!_M_buf.open(__s, __m, __protection))
699 this->setstate(ios_base::failbit);
701 # if defined (_STLP_USE_WIN32_IO)
702 explicit basic_fstream(_STLP_fd __id,
703 ios_base::openmode __mod = ios_base::in | ios_base::out) :
704 basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
706 if (!_M_buf.open(__id, __mod))
707 this->setstate(ios_base::failbit);
709 # endif /* _STLP_USE_WIN32_IO */
713 public: // File and buffer operations.
715 basic_filebuf<_CharT, _Traits>* rdbuf() const
716 { return __CONST_CAST(_Buf*,&_M_buf); }
719 return this->rdbuf()->is_open();
722 void open(const char* __s,
723 ios_base::openmode __mod =
724 ios_base::in | ios_base::out) {
725 if (!this->rdbuf()->open(__s, __mod))
726 this->setstate(ios_base::failbit);
730 if (!this->rdbuf()->close())
731 this->setstate(ios_base::failbit);
735 basic_filebuf<_CharT, _Traits> _M_buf;
737 #if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310)
738 typedef basic_fstream<_CharT, _Traits> _Self;
739 //explicitely defined as private to avoid warnings:
740 basic_fstream(_Self const&);
741 _Self& operator = (_Self const&);
747 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
748 # include <stl/_fstream.c>
751 _STLP_BEGIN_NAMESPACE
753 #if defined (_STLP_USE_TEMPLATE_EXPORT)
754 _STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;
755 _STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;
756 _STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;
757 # if ! defined (_STLP_NO_WCHAR_T)
758 _STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;
759 _STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;
760 _STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;
762 #endif /* _STLP_USE_TEMPLATE_EXPORT */
766 #endif /* _STLP_FSTREAM */