_fstream.h
来自「stl的源码」· C头文件 代码 · 共 715 行 · 第 1/2 页
H
715 行
ptrdiff_t __n = __last - __first; return (__buf->_M_write(__first, __n)); }};//----------------------------------------------------------------------// basic_filebuf<> helper functions.//----------------------------------------// Helper functions for switching between modes.//// This class had to be designed very carefully to work// with Visual C++.//template <class _Traits>class _Noconv_input {public: typedef typename _Traits::int_type int_type; typedef typename _Traits::char_type char_type; static inline int_type _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits>*) { return _Traits::eof(); }};_STLP_TEMPLATE_NULLclass _Noconv_input<char_traits<char> > {public: static inline int _STLP_CALL _M_doit(basic_filebuf<char, char_traits<char> >* __buf) { return __buf->_M_do_noconv_input(); }};// underflow() may be called for one of two reasons. (1) We've// been going through the special putback buffer, and we need to move back// to the regular internal buffer. (2) We've exhausted the internal buffer,// and we need to replentish it.template <class _CharT, class _Traits>class _Underflow {public: typedef typename _Traits::int_type int_type; typedef _Traits traits_type; // There is a specialized version of underflow, for basic_filebuf<char>, // in fstream.cpp. static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this) { if (!__this->_M_in_input_mode) { if (!__this->_M_switch_to_input_mode()) return traits_type::eof(); } else if (__this->_M_in_putback_mode) { __this->_M_exit_putback_mode(); if (__this->gptr() != __this->egptr()) { int_type __c = traits_type::to_int_type(*__this->gptr()); return __c; } } return __this->_M_underflow_aux(); }};// Specialization of underflow: if the character type is char, maybe// we can use mmap instead of read._STLP_TEMPLATE_NULLclass _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> >{ public: typedef char_traits<char>::int_type int_type; typedef char_traits<char> traits_type; static int_type _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);};#if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_NO_WCHAR_T)_STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;#endif//----------------------------------------------------------------------// Class basic_ifstream<>template <class _CharT, class _Traits>class basic_ifstream : public basic_istream<_CharT, _Traits> {public: // Types typedef _CharT char_type; typedef typename _Traits::int_type int_type; typedef typename _Traits::pos_type pos_type; typedef typename _Traits::off_type off_type; typedef _Traits traits_type; typedef basic_ios<_CharT, _Traits> _Basic_ios; typedef basic_istream<_CharT, _Traits> _Base; typedef basic_filebuf<_CharT, _Traits> _Buf;public: // Constructors, destructor. basic_ifstream() : basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); } explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) : basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__s, __mod | ios_base::in)) this->setstate(ios_base::failbit); }#if !defined (_STLP_NO_EXTENSIONS) explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) : basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__id, __mod | ios_base::in)) this->setstate(ios_base::failbit); } basic_ifstream(const char* __s, ios_base::openmode __m, long __protection) : basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__s, __m | ios_base::in, __protection)) this->setstate(ios_base::failbit); }# if defined (_STLP_USE_WIN32_IO) explicit basic_ifstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::in) : basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__id, __mod | ios_base::in)) this->setstate(ios_base::failbit); }# endif /* _STLP_USE_WIN32_IO */#endif ~basic_ifstream() {}public: // File and buffer operations. basic_filebuf<_CharT, _Traits>* rdbuf() const { return __CONST_CAST(_Buf*,&_M_buf); } bool is_open() { return this->rdbuf()->is_open(); } void open(const char* __s, ios_base::openmode __mod = ios_base::in) { if (!this->rdbuf()->open(__s, __mod | ios_base::in)) this->setstate(ios_base::failbit); } void close() { if (!this->rdbuf()->close()) this->setstate(ios_base::failbit); }private: basic_filebuf<_CharT, _Traits> _M_buf;};//----------------------------------------------------------------------// Class basic_ofstream<>template <class _CharT, class _Traits>class basic_ofstream : public basic_ostream<_CharT, _Traits> {public: // Types typedef _CharT char_type; typedef typename _Traits::int_type int_type; typedef typename _Traits::pos_type pos_type; typedef typename _Traits::off_type off_type; typedef _Traits traits_type; typedef basic_ios<_CharT, _Traits> _Basic_ios; typedef basic_ostream<_CharT, _Traits> _Base; typedef basic_filebuf<_CharT, _Traits> _Buf;public: // Constructors, destructor. basic_ofstream() : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); } explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out) : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__s, __mod | ios_base::out)) this->setstate(ios_base::failbit); }#if !defined (_STLP_NO_EXTENSIONS) explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out) : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__id, __mod | ios_base::out)) this->setstate(ios_base::failbit); } basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__s, __m | ios_base::out, __protection)) this->setstate(ios_base::failbit); }# if defined (_STLP_USE_WIN32_IO) explicit basic_ofstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::out) : basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__id, __mod | ios_base::out)) this->setstate(ios_base::failbit); }# endif /* _STLP_USE_WIN32_IO */#endif ~basic_ofstream() {}public: // File and buffer operations. basic_filebuf<_CharT, _Traits>* rdbuf() const { return __CONST_CAST(_Buf*,&_M_buf); } bool is_open() { return this->rdbuf()->is_open(); } void open(const char* __s, ios_base::openmode __mod= ios_base::out) { if (!this->rdbuf()->open(__s, __mod | ios_base::out)) this->setstate(ios_base::failbit); } void close() { if (!this->rdbuf()->close()) this->setstate(ios_base::failbit); }private: basic_filebuf<_CharT, _Traits> _M_buf;};//----------------------------------------------------------------------// Class basic_fstream<>template <class _CharT, class _Traits>class basic_fstream : public basic_iostream<_CharT, _Traits> {public: // Types typedef _CharT char_type; typedef typename _Traits::int_type int_type; typedef typename _Traits::pos_type pos_type; typedef typename _Traits::off_type off_type; typedef _Traits traits_type; typedef basic_ios<_CharT, _Traits> _Basic_ios; typedef basic_iostream<_CharT, _Traits> _Base; typedef basic_filebuf<_CharT, _Traits> _Buf;public: // Constructors, destructor. basic_fstream() : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); } explicit basic_fstream(const char* __s, ios_base::openmode __mod = ios_base::in | ios_base::out) : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__s, __mod)) this->setstate(ios_base::failbit); }#if !defined (_STLP_NO_EXTENSIONS) explicit basic_fstream(int __id, ios_base::openmode __mod = ios_base::in | ios_base::out) : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__id, __mod)) this->setstate(ios_base::failbit); } basic_fstream(const char* __s, ios_base::openmode __m, long __protection) : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__s, __m, __protection)) this->setstate(ios_base::failbit); }# if defined (_STLP_USE_WIN32_IO) explicit basic_fstream(_STLP_fd __id, ios_base::openmode __mod = ios_base::in | ios_base::out) : basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() { this->init(&_M_buf); if (!_M_buf.open(__id, __mod)) this->setstate(ios_base::failbit); }# endif /* _STLP_USE_WIN32_IO */#endif ~basic_fstream() {}public: // File and buffer operations. basic_filebuf<_CharT, _Traits>* rdbuf() const { return __CONST_CAST(_Buf*,&_M_buf); } bool is_open() { return this->rdbuf()->is_open(); } void open(const char* __s, ios_base::openmode __mod = ios_base::in | ios_base::out) { if (!this->rdbuf()->open(__s, __mod)) this->setstate(ios_base::failbit); } void close() { if (!this->rdbuf()->close()) this->setstate(ios_base::failbit); }private: basic_filebuf<_CharT, _Traits> _M_buf;#if defined (_STLP_MSVC) && (_STLP_MSVC >= 1300 && _STLP_MSVC <= 1310) typedef basic_fstream<_CharT, _Traits> _Self; //explicitely defined as private to avoid warnings: basic_fstream(_Self const&); _Self& operator = (_Self const&);#endif};_STLP_END_NAMESPACE#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)# include <stl/_fstream.c>#endif_STLP_BEGIN_NAMESPACE#if defined (_STLP_USE_TEMPLATE_EXPORT)_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;# if ! defined (_STLP_NO_WCHAR_T)_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;# endif#endif /* _STLP_USE_TEMPLATE_EXPORT */_STLP_END_NAMESPACE#endif /* _STLP_FSTREAM */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?