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