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