Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------- fstream ------------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_FSTREAM |
| 12 | #define _LIBCPP_FSTREAM |
| 13 | |
| 14 | /* |
| 15 | fstream synopsis |
| 16 | |
| 17 | template <class charT, class traits = char_traits<charT> > |
| 18 | class basic_filebuf |
| 19 | : public basic_streambuf<charT, traits> |
| 20 | { |
| 21 | public: |
| 22 | typedef charT char_type; |
| 23 | typedef traits traits_type; |
| 24 | typedef typename traits_type::int_type int_type; |
| 25 | typedef typename traits_type::pos_type pos_type; |
| 26 | typedef typename traits_type::off_type off_type; |
| 27 | |
| 28 | // 27.9.1.2 Constructors/destructor: |
| 29 | basic_filebuf(); |
| 30 | basic_filebuf(basic_filebuf&& rhs); |
| 31 | virtual ~basic_filebuf(); |
| 32 | |
| 33 | // 27.9.1.3 Assign/swap: |
| 34 | basic_filebuf& operator=(basic_filebuf&& rhs); |
| 35 | void swap(basic_filebuf& rhs); |
| 36 | |
| 37 | // 27.9.1.4 Members: |
| 38 | bool is_open() const; |
| 39 | basic_filebuf* open(const char* s, ios_base::openmode mode); |
| 40 | basic_filebuf* open(const string& s, ios_base::openmode mode); |
| 41 | basic_filebuf* close(); |
| 42 | |
| 43 | protected: |
| 44 | // 27.9.1.5 Overridden virtual functions: |
| 45 | virtual streamsize showmanyc(); |
| 46 | virtual int_type underflow(); |
| 47 | virtual int_type uflow(); |
| 48 | virtual int_type pbackfail(int_type c = traits_type::eof()); |
| 49 | virtual int_type overflow (int_type c = traits_type::eof()); |
| 50 | virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n); |
| 51 | virtual pos_type seekoff(off_type off, ios_base::seekdir way, |
| 52 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 53 | virtual pos_type seekpos(pos_type sp, |
| 54 | ios_base::openmode which = ios_base::in | ios_base::out); |
| 55 | virtual int sync(); |
| 56 | virtual void imbue(const locale& loc); |
| 57 | }; |
| 58 | |
| 59 | template <class charT, class traits> |
| 60 | void |
| 61 | swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y); |
| 62 | |
| 63 | typedef basic_filebuf<char> filebuf; |
| 64 | typedef basic_filebuf<wchar_t> wfilebuf; |
| 65 | |
| 66 | template <class charT, class traits = char_traits<charT> > |
| 67 | class basic_ifstream |
| 68 | : public basic_istream<charT,traits> |
| 69 | { |
| 70 | public: |
| 71 | typedef charT char_type; |
| 72 | typedef traits traits_type; |
| 73 | typedef typename traits_type::int_type int_type; |
| 74 | typedef typename traits_type::pos_type pos_type; |
| 75 | typedef typename traits_type::off_type off_type; |
| 76 | |
| 77 | basic_ifstream(); |
| 78 | explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in); |
| 79 | explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in); |
| 80 | basic_ifstream(basic_ifstream&& rhs); |
| 81 | |
| 82 | basic_ifstream& operator=(basic_ifstream&& rhs); |
| 83 | void swap(basic_ifstream& rhs); |
| 84 | |
| 85 | basic_filebuf<char_type, traits_type>* rdbuf() const; |
| 86 | bool is_open() const; |
| 87 | void open(const char* s, ios_base::openmode mode = ios_base::in); |
| 88 | void open(const string& s, ios_base::openmode mode = ios_base::in); |
| 89 | void close(); |
| 90 | }; |
| 91 | |
| 92 | template <class charT, class traits> |
| 93 | void |
| 94 | swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y); |
| 95 | |
| 96 | typedef basic_ifstream<char> ifstream; |
| 97 | typedef basic_ifstream<wchar_t> wifstream; |
| 98 | |
| 99 | template <class charT, class traits = char_traits<charT> > |
| 100 | class basic_ofstream |
| 101 | : public basic_ostream<charT,traits> |
| 102 | { |
| 103 | public: |
| 104 | typedef charT char_type; |
| 105 | typedef traits traits_type; |
| 106 | typedef typename traits_type::int_type int_type; |
| 107 | typedef typename traits_type::pos_type pos_type; |
| 108 | typedef typename traits_type::off_type off_type; |
| 109 | |
| 110 | basic_ofstream(); |
| 111 | explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); |
| 112 | explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); |
| 113 | basic_ofstream(basic_ofstream&& rhs); |
| 114 | |
| 115 | basic_ofstream& operator=(basic_ofstream&& rhs); |
| 116 | void swap(basic_ofstream& rhs); |
| 117 | |
| 118 | basic_filebuf<char_type, traits_type>* rdbuf() const; |
| 119 | bool is_open() const; |
| 120 | void open(const char* s, ios_base::openmode mode = ios_base::out); |
| 121 | void open(const string& s, ios_base::openmode mode = ios_base::out); |
| 122 | void close(); |
| 123 | }; |
| 124 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 125 | template <class charT, class traits> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | void |
| 127 | swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y); |
| 128 | |
| 129 | typedef basic_ofstream<char> ofstream; |
| 130 | typedef basic_ofstream<wchar_t> wofstream; |
| 131 | |
| 132 | template <class charT, class traits=char_traits<charT> > |
| 133 | class basic_fstream |
| 134 | : public basic_iostream<charT,traits> |
| 135 | { |
| 136 | public: |
| 137 | typedef charT char_type; |
| 138 | typedef traits traits_type; |
| 139 | typedef typename traits_type::int_type int_type; |
| 140 | typedef typename traits_type::pos_type pos_type; |
| 141 | typedef typename traits_type::off_type off_type; |
| 142 | |
| 143 | basic_fstream(); |
| 144 | explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); |
| 145 | explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); |
| 146 | basic_fstream(basic_fstream&& rhs); |
| 147 | |
| 148 | basic_fstream& operator=(basic_fstream&& rhs); |
| 149 | void swap(basic_fstream& rhs); |
| 150 | |
| 151 | basic_filebuf<char_type, traits_type>* rdbuf() const; |
| 152 | bool is_open() const; |
| 153 | void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); |
| 154 | void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); |
| 155 | void close(); |
| 156 | }; |
| 157 | |
| 158 | template <class charT, class traits> |
| 159 | void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y); |
| 160 | |
| 161 | typedef basic_fstream<char> fstream; |
| 162 | typedef basic_fstream<wchar_t> wfstream; |
| 163 | |
| 164 | } // std |
| 165 | |
| 166 | */ |
| 167 | |
| 168 | #include <__config> |
| 169 | #include <ostream> |
| 170 | #include <istream> |
| 171 | #include <__locale> |
| 172 | #include <cstdio> |
| 173 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 174 | #include <__undef_min_max> |
| 175 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 176 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 178 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | |
| 180 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 181 | |
| 182 | template <class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 183 | class _LIBCPP_TYPE_VIS_ONLY basic_filebuf |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | : public basic_streambuf<_CharT, _Traits> |
| 185 | { |
| 186 | public: |
| 187 | typedef _CharT char_type; |
| 188 | typedef _Traits traits_type; |
| 189 | typedef typename traits_type::int_type int_type; |
| 190 | typedef typename traits_type::pos_type pos_type; |
| 191 | typedef typename traits_type::off_type off_type; |
| 192 | typedef typename traits_type::state_type state_type; |
| 193 | |
| 194 | // 27.9.1.2 Constructors/destructor: |
| 195 | basic_filebuf(); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 196 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | basic_filebuf(basic_filebuf&& __rhs); |
| 198 | #endif |
| 199 | virtual ~basic_filebuf(); |
| 200 | |
| 201 | // 27.9.1.3 Assign/swap: |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 202 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 203 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | basic_filebuf& operator=(basic_filebuf&& __rhs); |
| 205 | #endif |
| 206 | void swap(basic_filebuf& __rhs); |
| 207 | |
| 208 | // 27.9.1.4 Members: |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 209 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 210 | bool is_open() const; |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 211 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | basic_filebuf* open(const char* __s, ios_base::openmode __mode); |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 213 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 214 | basic_filebuf* open(const string& __s, ios_base::openmode __mode); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 215 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | basic_filebuf* close(); |
| 217 | |
| 218 | protected: |
| 219 | // 27.9.1.5 Overridden virtual functions: |
| 220 | virtual int_type underflow(); |
| 221 | virtual int_type pbackfail(int_type __c = traits_type::eof()); |
| 222 | virtual int_type overflow (int_type __c = traits_type::eof()); |
| 223 | virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n); |
| 224 | virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, |
| 225 | ios_base::openmode __wch = ios_base::in | ios_base::out); |
| 226 | virtual pos_type seekpos(pos_type __sp, |
| 227 | ios_base::openmode __wch = ios_base::in | ios_base::out); |
| 228 | virtual int sync(); |
| 229 | virtual void imbue(const locale& __loc); |
| 230 | |
| 231 | private: |
| 232 | char* __extbuf_; |
| 233 | const char* __extbufnext_; |
| 234 | const char* __extbufend_; |
| 235 | char __extbuf_min_[8]; |
| 236 | size_t __ebs_; |
| 237 | char_type* __intbuf_; |
| 238 | size_t __ibs_; |
| 239 | FILE* __file_; |
| 240 | const codecvt<char_type, char, state_type>* __cv_; |
| 241 | state_type __st_; |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 242 | state_type __st_last_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | ios_base::openmode __om_; |
| 244 | ios_base::openmode __cm_; |
| 245 | bool __owns_eb_; |
| 246 | bool __owns_ib_; |
| 247 | bool __always_noconv_; |
| 248 | |
| 249 | bool __read_mode(); |
| 250 | void __write_mode(); |
| 251 | }; |
| 252 | |
| 253 | template <class _CharT, class _Traits> |
| 254 | basic_filebuf<_CharT, _Traits>::basic_filebuf() |
| 255 | : __extbuf_(0), |
| 256 | __extbufnext_(0), |
| 257 | __extbufend_(0), |
| 258 | __ebs_(0), |
| 259 | __intbuf_(0), |
| 260 | __ibs_(0), |
| 261 | __file_(0), |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 262 | __cv_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | __st_(), |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 264 | __st_last_(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 265 | __om_(0), |
| 266 | __cm_(0), |
| 267 | __owns_eb_(false), |
| 268 | __owns_ib_(false), |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 269 | __always_noconv_(false) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | { |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 271 | if (has_facet<codecvt<char_type, char, state_type> >(this->getloc())) |
| 272 | { |
| 273 | __cv_ = &use_facet<codecvt<char_type, char, state_type> >(this->getloc()); |
| 274 | __always_noconv_ = __cv_->always_noconv(); |
| 275 | } |
Howard Hinnant | e7d59f2 | 2012-08-24 18:06:47 +0000 | [diff] [blame] | 276 | setbuf(0, 4096); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 279 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | |
| 281 | template <class _CharT, class _Traits> |
| 282 | basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) |
| 283 | : basic_streambuf<_CharT, _Traits>(__rhs) |
| 284 | { |
| 285 | if (__rhs.__extbuf_ == __rhs.__extbuf_min_) |
| 286 | { |
| 287 | __extbuf_ = __extbuf_min_; |
| 288 | __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_); |
| 289 | __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_); |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | __extbuf_ = __rhs.__extbuf_; |
| 294 | __extbufnext_ = __rhs.__extbufnext_; |
| 295 | __extbufend_ = __rhs.__extbufend_; |
| 296 | } |
| 297 | __ebs_ = __rhs.__ebs_; |
| 298 | __intbuf_ = __rhs.__intbuf_; |
| 299 | __ibs_ = __rhs.__ibs_; |
| 300 | __file_ = __rhs.__file_; |
| 301 | __cv_ = __rhs.__cv_; |
| 302 | __st_ = __rhs.__st_; |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 303 | __st_last_ = __rhs.__st_last_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 | __om_ = __rhs.__om_; |
| 305 | __cm_ = __rhs.__cm_; |
| 306 | __owns_eb_ = __rhs.__owns_eb_; |
| 307 | __owns_ib_ = __rhs.__owns_ib_; |
| 308 | __always_noconv_ = __rhs.__always_noconv_; |
| 309 | if (__rhs.pbase()) |
| 310 | { |
| 311 | if (__rhs.pbase() == __rhs.__intbuf_) |
| 312 | this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase())); |
| 313 | else |
| 314 | this->setp((char_type*)__extbuf_, |
| 315 | (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); |
| 316 | this->pbump(__rhs. pptr() - __rhs.pbase()); |
| 317 | } |
| 318 | else if (__rhs.eback()) |
| 319 | { |
| 320 | if (__rhs.eback() == __rhs.__intbuf_) |
| 321 | this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), |
| 322 | __intbuf_ + (__rhs.egptr() - __rhs.eback())); |
| 323 | else |
| 324 | this->setg((char_type*)__extbuf_, |
| 325 | (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()), |
| 326 | (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback())); |
| 327 | } |
| 328 | __rhs.__extbuf_ = 0; |
| 329 | __rhs.__extbufnext_ = 0; |
| 330 | __rhs.__extbufend_ = 0; |
| 331 | __rhs.__ebs_ = 0; |
| 332 | __rhs.__intbuf_ = 0; |
| 333 | __rhs.__ibs_ = 0; |
| 334 | __rhs.__file_ = 0; |
| 335 | __rhs.__st_ = state_type(); |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 336 | __rhs.__st_last_ = state_type(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 | __rhs.__om_ = 0; |
| 338 | __rhs.__cm_ = 0; |
| 339 | __rhs.__owns_eb_ = false; |
| 340 | __rhs.__owns_ib_ = false; |
| 341 | __rhs.setg(0, 0, 0); |
| 342 | __rhs.setp(0, 0); |
| 343 | } |
| 344 | |
| 345 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 346 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | basic_filebuf<_CharT, _Traits>& |
| 348 | basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) |
| 349 | { |
| 350 | close(); |
| 351 | swap(__rhs); |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 352 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 353 | } |
| 354 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 355 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | |
| 357 | template <class _CharT, class _Traits> |
| 358 | basic_filebuf<_CharT, _Traits>::~basic_filebuf() |
| 359 | { |
| 360 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 361 | try |
| 362 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 363 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 364 | close(); |
| 365 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 366 | } |
| 367 | catch (...) |
| 368 | { |
| 369 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 370 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | if (__owns_eb_) |
| 372 | delete [] __extbuf_; |
| 373 | if (__owns_ib_) |
| 374 | delete [] __intbuf_; |
| 375 | } |
| 376 | |
| 377 | template <class _CharT, class _Traits> |
| 378 | void |
| 379 | basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) |
| 380 | { |
| 381 | basic_streambuf<char_type, traits_type>::swap(__rhs); |
| 382 | if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) |
| 383 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 384 | _VSTD::swap(__extbuf_, __rhs.__extbuf_); |
| 385 | _VSTD::swap(__extbufnext_, __rhs.__extbufnext_); |
| 386 | _VSTD::swap(__extbufend_, __rhs.__extbufend_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | } |
| 388 | else |
| 389 | { |
| 390 | ptrdiff_t __ln = __extbufnext_ - __extbuf_; |
| 391 | ptrdiff_t __le = __extbufend_ - __extbuf_; |
| 392 | ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_; |
| 393 | ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_; |
| 394 | if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) |
| 395 | { |
| 396 | __extbuf_ = __rhs.__extbuf_; |
| 397 | __rhs.__extbuf_ = __rhs.__extbuf_min_; |
| 398 | } |
| 399 | else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) |
| 400 | { |
| 401 | __rhs.__extbuf_ = __extbuf_; |
| 402 | __extbuf_ = __extbuf_min_; |
| 403 | } |
| 404 | __extbufnext_ = __extbuf_ + __rn; |
| 405 | __extbufend_ = __extbuf_ + __re; |
| 406 | __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln; |
| 407 | __rhs.__extbufend_ = __rhs.__extbuf_ + __le; |
| 408 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 409 | _VSTD::swap(__ebs_, __rhs.__ebs_); |
| 410 | _VSTD::swap(__intbuf_, __rhs.__intbuf_); |
| 411 | _VSTD::swap(__ibs_, __rhs.__ibs_); |
| 412 | _VSTD::swap(__file_, __rhs.__file_); |
| 413 | _VSTD::swap(__cv_, __rhs.__cv_); |
| 414 | _VSTD::swap(__st_, __rhs.__st_); |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 415 | _VSTD::swap(__st_last_, __rhs.__st_last_); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 416 | _VSTD::swap(__om_, __rhs.__om_); |
| 417 | _VSTD::swap(__cm_, __rhs.__cm_); |
| 418 | _VSTD::swap(__owns_eb_, __rhs.__owns_eb_); |
| 419 | _VSTD::swap(__owns_ib_, __rhs.__owns_ib_); |
| 420 | _VSTD::swap(__always_noconv_, __rhs.__always_noconv_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | if (this->eback() == (char_type*)__rhs.__extbuf_min_) |
| 422 | { |
| 423 | ptrdiff_t __n = this->gptr() - this->eback(); |
| 424 | ptrdiff_t __e = this->egptr() - this->eback(); |
| 425 | this->setg((char_type*)__extbuf_min_, |
| 426 | (char_type*)__extbuf_min_ + __n, |
| 427 | (char_type*)__extbuf_min_ + __e); |
| 428 | } |
| 429 | else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) |
| 430 | { |
| 431 | ptrdiff_t __n = this->pptr() - this->pbase(); |
| 432 | ptrdiff_t __e = this->epptr() - this->pbase(); |
| 433 | this->setp((char_type*)__extbuf_min_, |
| 434 | (char_type*)__extbuf_min_ + __e); |
| 435 | this->pbump(__n); |
| 436 | } |
| 437 | if (__rhs.eback() == (char_type*)__extbuf_min_) |
| 438 | { |
| 439 | ptrdiff_t __n = __rhs.gptr() - __rhs.eback(); |
| 440 | ptrdiff_t __e = __rhs.egptr() - __rhs.eback(); |
| 441 | __rhs.setg((char_type*)__rhs.__extbuf_min_, |
| 442 | (char_type*)__rhs.__extbuf_min_ + __n, |
| 443 | (char_type*)__rhs.__extbuf_min_ + __e); |
| 444 | } |
| 445 | else if (__rhs.pbase() == (char_type*)__extbuf_min_) |
| 446 | { |
| 447 | ptrdiff_t __n = __rhs.pptr() - __rhs.pbase(); |
| 448 | ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); |
| 449 | __rhs.setp((char_type*)__rhs.__extbuf_min_, |
| 450 | (char_type*)__rhs.__extbuf_min_ + __e); |
| 451 | __rhs.pbump(__n); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | template <class _CharT, class _Traits> |
| 456 | inline _LIBCPP_INLINE_VISIBILITY |
| 457 | void |
| 458 | swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) |
| 459 | { |
| 460 | __x.swap(__y); |
| 461 | } |
| 462 | |
| 463 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 464 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 465 | bool |
| 466 | basic_filebuf<_CharT, _Traits>::is_open() const |
| 467 | { |
| 468 | return __file_ != 0; |
| 469 | } |
| 470 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 471 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | template <class _CharT, class _Traits> |
| 473 | basic_filebuf<_CharT, _Traits>* |
| 474 | basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) |
| 475 | { |
| 476 | basic_filebuf<_CharT, _Traits>* __rt = 0; |
| 477 | if (__file_ == 0) |
| 478 | { |
| 479 | __rt = this; |
| 480 | const char* __mdstr; |
| 481 | switch (__mode & ~ios_base::ate) |
| 482 | { |
| 483 | case ios_base::out: |
| 484 | case ios_base::out | ios_base::trunc: |
| 485 | __mdstr = "w"; |
| 486 | break; |
| 487 | case ios_base::out | ios_base::app: |
| 488 | case ios_base::app: |
| 489 | __mdstr = "a"; |
| 490 | break; |
| 491 | case ios_base::in: |
| 492 | __mdstr = "r"; |
| 493 | break; |
| 494 | case ios_base::in | ios_base::out: |
| 495 | __mdstr = "r+"; |
| 496 | break; |
| 497 | case ios_base::in | ios_base::out | ios_base::trunc: |
| 498 | __mdstr = "w+"; |
| 499 | break; |
| 500 | case ios_base::in | ios_base::out | ios_base::app: |
| 501 | case ios_base::in | ios_base::app: |
| 502 | __mdstr = "a+"; |
| 503 | break; |
| 504 | case ios_base::out | ios_base::binary: |
| 505 | case ios_base::out | ios_base::trunc | ios_base::binary: |
| 506 | __mdstr = "wb"; |
| 507 | break; |
| 508 | case ios_base::out | ios_base::app | ios_base::binary: |
| 509 | case ios_base::app | ios_base::binary: |
| 510 | __mdstr = "ab"; |
| 511 | break; |
| 512 | case ios_base::in | ios_base::binary: |
| 513 | __mdstr = "rb"; |
| 514 | break; |
| 515 | case ios_base::in | ios_base::out | ios_base::binary: |
| 516 | __mdstr = "r+b"; |
| 517 | break; |
| 518 | case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: |
| 519 | __mdstr = "w+b"; |
| 520 | break; |
| 521 | case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: |
| 522 | case ios_base::in | ios_base::app | ios_base::binary: |
| 523 | __mdstr = "a+b"; |
| 524 | break; |
| 525 | default: |
| 526 | __rt = 0; |
| 527 | break; |
| 528 | } |
| 529 | if (__rt) |
| 530 | { |
| 531 | __file_ = fopen(__s, __mdstr); |
| 532 | if (__file_) |
| 533 | { |
| 534 | __om_ = __mode; |
| 535 | if (__mode & ios_base::ate) |
| 536 | { |
| 537 | if (fseek(__file_, 0, SEEK_END)) |
| 538 | { |
| 539 | fclose(__file_); |
| 540 | __file_ = 0; |
| 541 | __rt = 0; |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | else |
| 546 | __rt = 0; |
| 547 | } |
| 548 | } |
| 549 | return __rt; |
| 550 | } |
| 551 | |
| 552 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 553 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | basic_filebuf<_CharT, _Traits>* |
| 555 | basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) |
| 556 | { |
| 557 | return open(__s.c_str(), __mode); |
| 558 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 559 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 560 | |
| 561 | template <class _CharT, class _Traits> |
| 562 | basic_filebuf<_CharT, _Traits>* |
| 563 | basic_filebuf<_CharT, _Traits>::close() |
| 564 | { |
| 565 | basic_filebuf<_CharT, _Traits>* __rt = 0; |
| 566 | if (__file_) |
| 567 | { |
| 568 | __rt = this; |
| 569 | unique_ptr<FILE, int(*)(FILE*)> __h(__file_, fclose); |
Howard Hinnant | e1a7b04 | 2012-01-12 23:37:51 +0000 | [diff] [blame] | 570 | if (sync()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 | __rt = 0; |
| 572 | if (fclose(__h.release()) == 0) |
| 573 | __file_ = 0; |
| 574 | else |
| 575 | __rt = 0; |
| 576 | } |
| 577 | return __rt; |
| 578 | } |
| 579 | |
| 580 | template <class _CharT, class _Traits> |
| 581 | typename basic_filebuf<_CharT, _Traits>::int_type |
| 582 | basic_filebuf<_CharT, _Traits>::underflow() |
| 583 | { |
| 584 | if (__file_ == 0) |
| 585 | return traits_type::eof(); |
| 586 | bool __initial = __read_mode(); |
| 587 | char_type __1buf; |
| 588 | if (this->gptr() == 0) |
| 589 | this->setg(&__1buf, &__1buf+1, &__1buf+1); |
| 590 | const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4); |
| 591 | int_type __c = traits_type::eof(); |
| 592 | if (this->gptr() == this->egptr()) |
| 593 | { |
| 594 | memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); |
| 595 | if (__always_noconv_) |
| 596 | { |
| 597 | size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz); |
| 598 | __nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_); |
| 599 | if (__nmemb != 0) |
| 600 | { |
| 601 | this->setg(this->eback(), |
| 602 | this->eback() + __unget_sz, |
| 603 | this->eback() + __unget_sz + __nmemb); |
Howard Hinnant | 47a7cce | 2011-02-02 17:37:16 +0000 | [diff] [blame] | 604 | __c = traits_type::to_int_type(*this->gptr()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); |
| 610 | __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); |
| 611 | __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); |
Howard Hinnant | ec423cb | 2012-08-24 20:37:00 +0000 | [diff] [blame] | 612 | size_t __nmemb = _VSTD::min(static_cast<size_t>(__ibs_ - __unget_sz), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | static_cast<size_t>(__extbufend_ - __extbufnext_)); |
| 614 | codecvt_base::result __r; |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 615 | __st_last_ = __st_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_); |
| 617 | if (__nr != 0) |
| 618 | { |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 619 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 620 | if (!__cv_) |
| 621 | throw bad_cast(); |
| 622 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | __extbufend_ = __extbufnext_ + __nr; |
| 624 | char_type* __inext; |
| 625 | __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, |
| 626 | this->eback() + __unget_sz, |
Howard Hinnant | ec423cb | 2012-08-24 20:37:00 +0000 | [diff] [blame] | 627 | this->eback() + __ibs_, __inext); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 628 | if (__r == codecvt_base::noconv) |
| 629 | { |
| 630 | this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); |
Howard Hinnant | 47a7cce | 2011-02-02 17:37:16 +0000 | [diff] [blame] | 631 | __c = traits_type::to_int_type(*this->gptr()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | } |
| 633 | else if (__inext != this->eback() + __unget_sz) |
| 634 | { |
| 635 | this->setg(this->eback(), this->eback() + __unget_sz, __inext); |
Howard Hinnant | 47a7cce | 2011-02-02 17:37:16 +0000 | [diff] [blame] | 636 | __c = traits_type::to_int_type(*this->gptr()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | else |
Howard Hinnant | 47a7cce | 2011-02-02 17:37:16 +0000 | [diff] [blame] | 642 | __c = traits_type::to_int_type(*this->gptr()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | if (this->eback() == &__1buf) |
| 644 | this->setg(0, 0, 0); |
| 645 | return __c; |
| 646 | } |
| 647 | |
| 648 | template <class _CharT, class _Traits> |
| 649 | typename basic_filebuf<_CharT, _Traits>::int_type |
| 650 | basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) |
| 651 | { |
| 652 | if (__file_ && this->eback() < this->gptr()) |
| 653 | { |
| 654 | if (traits_type::eq_int_type(__c, traits_type::eof())) |
| 655 | { |
| 656 | this->gbump(-1); |
| 657 | return traits_type::not_eof(__c); |
| 658 | } |
| 659 | if ((__om_ & ios_base::out) || |
| 660 | traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) |
| 661 | { |
| 662 | this->gbump(-1); |
| 663 | *this->gptr() = traits_type::to_char_type(__c); |
| 664 | return __c; |
| 665 | } |
| 666 | } |
| 667 | return traits_type::eof(); |
| 668 | } |
| 669 | |
| 670 | template <class _CharT, class _Traits> |
| 671 | typename basic_filebuf<_CharT, _Traits>::int_type |
| 672 | basic_filebuf<_CharT, _Traits>::overflow(int_type __c) |
| 673 | { |
| 674 | if (__file_ == 0) |
| 675 | return traits_type::eof(); |
| 676 | __write_mode(); |
| 677 | char_type __1buf; |
| 678 | char_type* __pb_save = this->pbase(); |
| 679 | char_type* __epb_save = this->epptr(); |
| 680 | if (!traits_type::eq_int_type(__c, traits_type::eof())) |
| 681 | { |
| 682 | if (this->pptr() == 0) |
| 683 | this->setp(&__1buf, &__1buf+1); |
| 684 | *this->pptr() = traits_type::to_char_type(__c); |
| 685 | this->pbump(1); |
| 686 | } |
| 687 | if (this->pptr() != this->pbase()) |
| 688 | { |
| 689 | if (__always_noconv_) |
| 690 | { |
| 691 | size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); |
| 692 | if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb) |
| 693 | return traits_type::eof(); |
| 694 | } |
| 695 | else |
| 696 | { |
| 697 | char* __extbe = __extbuf_; |
| 698 | codecvt_base::result __r; |
| 699 | do |
| 700 | { |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 701 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 702 | if (!__cv_) |
| 703 | throw bad_cast(); |
| 704 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 | const char_type* __e; |
| 706 | __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, |
| 707 | __extbuf_, __extbuf_ + __ebs_, __extbe); |
| 708 | if (__e == this->pbase()) |
| 709 | return traits_type::eof(); |
| 710 | if (__r == codecvt_base::noconv) |
| 711 | { |
| 712 | size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); |
| 713 | if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb) |
| 714 | return traits_type::eof(); |
| 715 | } |
| 716 | else if (__r == codecvt_base::ok || __r == codecvt_base::partial) |
| 717 | { |
| 718 | size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); |
| 719 | if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) |
| 720 | return traits_type::eof(); |
| 721 | if (__r == codecvt_base::partial) |
| 722 | { |
| 723 | this->setp((char_type*)__e, this->pptr()); |
| 724 | this->pbump(this->epptr() - this->pbase()); |
| 725 | } |
| 726 | } |
| 727 | else |
| 728 | return traits_type::eof(); |
| 729 | } while (__r == codecvt_base::partial); |
| 730 | } |
| 731 | this->setp(__pb_save, __epb_save); |
| 732 | } |
| 733 | return traits_type::not_eof(__c); |
| 734 | } |
| 735 | |
| 736 | template <class _CharT, class _Traits> |
| 737 | basic_streambuf<_CharT, _Traits>* |
| 738 | basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) |
| 739 | { |
| 740 | this->setg(0, 0, 0); |
| 741 | this->setp(0, 0); |
| 742 | if (__owns_eb_) |
| 743 | delete [] __extbuf_; |
| 744 | if (__owns_ib_) |
| 745 | delete [] __intbuf_; |
| 746 | __ebs_ = __n; |
| 747 | if (__ebs_ > sizeof(__extbuf_min_)) |
| 748 | { |
| 749 | if (__always_noconv_ && __s) |
| 750 | { |
| 751 | __extbuf_ = (char*)__s; |
| 752 | __owns_eb_ = false; |
| 753 | } |
| 754 | else |
| 755 | { |
| 756 | __extbuf_ = new char[__ebs_]; |
| 757 | __owns_eb_ = true; |
| 758 | } |
| 759 | } |
| 760 | else |
| 761 | { |
| 762 | __extbuf_ = __extbuf_min_; |
| 763 | __ebs_ = sizeof(__extbuf_min_); |
| 764 | __owns_eb_ = false; |
| 765 | } |
| 766 | if (!__always_noconv_) |
| 767 | { |
| 768 | __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); |
| 769 | if (__s && __ibs_ >= sizeof(__extbuf_min_)) |
| 770 | { |
| 771 | __intbuf_ = __s; |
| 772 | __owns_ib_ = false; |
| 773 | } |
| 774 | else |
| 775 | { |
| 776 | __intbuf_ = new char_type[__ibs_]; |
| 777 | __owns_ib_ = true; |
| 778 | } |
| 779 | } |
| 780 | else |
| 781 | { |
| 782 | __ibs_ = 0; |
| 783 | __intbuf_ = 0; |
| 784 | __owns_ib_ = false; |
| 785 | } |
| 786 | return this; |
| 787 | } |
| 788 | |
| 789 | template <class _CharT, class _Traits> |
| 790 | typename basic_filebuf<_CharT, _Traits>::pos_type |
| 791 | basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, |
| 792 | ios_base::openmode) |
| 793 | { |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 794 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 795 | if (!__cv_) |
| 796 | throw bad_cast(); |
| 797 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | int __width = __cv_->encoding(); |
| 799 | if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) |
| 800 | return pos_type(off_type(-1)); |
| 801 | // __width > 0 || __off == 0 |
| 802 | int __whence; |
| 803 | switch (__way) |
| 804 | { |
| 805 | case ios_base::beg: |
| 806 | __whence = SEEK_SET; |
| 807 | break; |
| 808 | case ios_base::cur: |
| 809 | __whence = SEEK_CUR; |
| 810 | break; |
| 811 | case ios_base::end: |
| 812 | __whence = SEEK_END; |
| 813 | break; |
| 814 | default: |
| 815 | return pos_type(off_type(-1)); |
| 816 | } |
Jonathan Roelofs | c6893ae | 2015-02-03 15:34:17 +0000 | [diff] [blame] | 817 | #if defined(_WIN32) || defined(_NEWLIB_VERSION) |
Howard Hinnant | cf31d38 | 2013-04-02 22:14:51 +0000 | [diff] [blame] | 818 | if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) |
| 819 | return pos_type(off_type(-1)); |
| 820 | pos_type __r = ftell(__file_); |
| 821 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 822 | if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) |
| 823 | return pos_type(off_type(-1)); |
| 824 | pos_type __r = ftello(__file_); |
Howard Hinnant | cf31d38 | 2013-04-02 22:14:51 +0000 | [diff] [blame] | 825 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | __r.state(__st_); |
| 827 | return __r; |
| 828 | } |
| 829 | |
| 830 | template <class _CharT, class _Traits> |
| 831 | typename basic_filebuf<_CharT, _Traits>::pos_type |
Howard Hinnant | 639a668 | 2010-07-15 18:18:07 +0000 | [diff] [blame] | 832 | basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 833 | { |
| 834 | if (__file_ == 0 || sync()) |
| 835 | return pos_type(off_type(-1)); |
Jonathan Roelofs | c6893ae | 2015-02-03 15:34:17 +0000 | [diff] [blame] | 836 | #if defined(_WIN32) || defined(_NEWLIB_VERSION) |
Howard Hinnant | cf31d38 | 2013-04-02 22:14:51 +0000 | [diff] [blame] | 837 | if (fseek(__file_, __sp, SEEK_SET)) |
| 838 | return pos_type(off_type(-1)); |
| 839 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 840 | if (fseeko(__file_, __sp, SEEK_SET)) |
| 841 | return pos_type(off_type(-1)); |
Howard Hinnant | cf31d38 | 2013-04-02 22:14:51 +0000 | [diff] [blame] | 842 | #endif |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 843 | __st_ = __sp.state(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | return __sp; |
| 845 | } |
| 846 | |
| 847 | template <class _CharT, class _Traits> |
| 848 | int |
| 849 | basic_filebuf<_CharT, _Traits>::sync() |
| 850 | { |
| 851 | if (__file_ == 0) |
| 852 | return 0; |
Howard Hinnant | 8540d4c | 2012-08-24 16:52:47 +0000 | [diff] [blame] | 853 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 854 | if (!__cv_) |
| 855 | throw bad_cast(); |
| 856 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 857 | if (__cm_ & ios_base::out) |
| 858 | { |
| 859 | if (this->pptr() != this->pbase()) |
| 860 | if (overflow() == traits_type::eof()) |
| 861 | return -1; |
| 862 | codecvt_base::result __r; |
| 863 | do |
| 864 | { |
| 865 | char* __extbe; |
| 866 | __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); |
| 867 | size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); |
| 868 | if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) |
| 869 | return -1; |
| 870 | } while (__r == codecvt_base::partial); |
| 871 | if (__r == codecvt_base::error) |
| 872 | return -1; |
| 873 | if (fflush(__file_)) |
| 874 | return -1; |
| 875 | } |
| 876 | else if (__cm_ & ios_base::in) |
| 877 | { |
| 878 | off_type __c; |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 879 | state_type __state = __st_last_; |
| 880 | bool __update_st = false; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 881 | if (__always_noconv_) |
| 882 | __c = this->egptr() - this->gptr(); |
| 883 | else |
| 884 | { |
| 885 | int __width = __cv_->encoding(); |
| 886 | __c = __extbufend_ - __extbufnext_; |
| 887 | if (__width > 0) |
| 888 | __c += __width * (this->egptr() - this->gptr()); |
| 889 | else |
| 890 | { |
| 891 | if (this->gptr() != this->egptr()) |
| 892 | { |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 893 | const int __off = __cv_->length(__state, __extbuf_, |
| 894 | __extbufnext_, |
| 895 | this->gptr() - this->eback()); |
| 896 | __c += __extbufnext_ - __extbuf_ - __off; |
| 897 | __update_st = true; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | } |
Jonathan Roelofs | c6893ae | 2015-02-03 15:34:17 +0000 | [diff] [blame] | 901 | #if defined(_WIN32) || defined(_NEWLIB_VERSION) |
Howard Hinnant | cf31d38 | 2013-04-02 22:14:51 +0000 | [diff] [blame] | 902 | if (fseek(__file_, -__c, SEEK_CUR)) |
| 903 | return -1; |
| 904 | #else |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | if (fseeko(__file_, -__c, SEEK_CUR)) |
| 906 | return -1; |
Howard Hinnant | cf31d38 | 2013-04-02 22:14:51 +0000 | [diff] [blame] | 907 | #endif |
Howard Hinnant | d305d3c | 2012-08-24 21:20:56 +0000 | [diff] [blame] | 908 | if (__update_st) |
| 909 | __st_ = __state; |
| 910 | __extbufnext_ = __extbufend_ = __extbuf_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | this->setg(0, 0, 0); |
| 912 | __cm_ = 0; |
| 913 | } |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | template <class _CharT, class _Traits> |
| 918 | void |
| 919 | basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) |
| 920 | { |
| 921 | sync(); |
| 922 | __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc); |
| 923 | bool __old_anc = __always_noconv_; |
| 924 | __always_noconv_ = __cv_->always_noconv(); |
| 925 | if (__old_anc != __always_noconv_) |
| 926 | { |
| 927 | this->setg(0, 0, 0); |
| 928 | this->setp(0, 0); |
| 929 | // invariant, char_type is char, else we couldn't get here |
| 930 | if (__always_noconv_) // need to dump __intbuf_ |
| 931 | { |
| 932 | if (__owns_eb_) |
| 933 | delete [] __extbuf_; |
| 934 | __owns_eb_ = __owns_ib_; |
| 935 | __ebs_ = __ibs_; |
| 936 | __extbuf_ = (char*)__intbuf_; |
| 937 | __ibs_ = 0; |
| 938 | __intbuf_ = 0; |
| 939 | __owns_ib_ = false; |
| 940 | } |
| 941 | else // need to obtain an __intbuf_. |
| 942 | { // If __extbuf_ is user-supplied, use it, else new __intbuf_ |
| 943 | if (!__owns_eb_ && __extbuf_ != __extbuf_min_) |
| 944 | { |
| 945 | __ibs_ = __ebs_; |
| 946 | __intbuf_ = (char_type*)__extbuf_; |
| 947 | __owns_ib_ = false; |
| 948 | __extbuf_ = new char[__ebs_]; |
| 949 | __owns_eb_ = true; |
| 950 | } |
| 951 | else |
| 952 | { |
| 953 | __ibs_ = __ebs_; |
| 954 | __intbuf_ = new char_type[__ibs_]; |
| 955 | __owns_ib_ = true; |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | template <class _CharT, class _Traits> |
| 962 | bool |
| 963 | basic_filebuf<_CharT, _Traits>::__read_mode() |
| 964 | { |
| 965 | if (!(__cm_ & ios_base::in)) |
| 966 | { |
| 967 | this->setp(0, 0); |
| 968 | if (__always_noconv_) |
| 969 | this->setg((char_type*)__extbuf_, |
| 970 | (char_type*)__extbuf_ + __ebs_, |
| 971 | (char_type*)__extbuf_ + __ebs_); |
| 972 | else |
| 973 | this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); |
| 974 | __cm_ = ios_base::in; |
| 975 | return true; |
| 976 | } |
| 977 | return false; |
| 978 | } |
| 979 | |
| 980 | template <class _CharT, class _Traits> |
| 981 | void |
| 982 | basic_filebuf<_CharT, _Traits>::__write_mode() |
| 983 | { |
| 984 | if (!(__cm_ & ios_base::out)) |
| 985 | { |
| 986 | this->setg(0, 0, 0); |
| 987 | if (__ebs_ > sizeof(__extbuf_min_)) |
| 988 | { |
| 989 | if (__always_noconv_) |
| 990 | this->setp((char_type*)__extbuf_, |
| 991 | (char_type*)__extbuf_ + (__ebs_ - 1)); |
| 992 | else |
| 993 | this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); |
| 994 | } |
| 995 | else |
| 996 | this->setp(0, 0); |
| 997 | __cm_ = ios_base::out; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | // basic_ifstream |
| 1002 | |
| 1003 | template <class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1004 | class _LIBCPP_TYPE_VIS_ONLY basic_ifstream |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1005 | : public basic_istream<_CharT, _Traits> |
| 1006 | { |
| 1007 | public: |
| 1008 | typedef _CharT char_type; |
| 1009 | typedef _Traits traits_type; |
| 1010 | typedef typename traits_type::int_type int_type; |
| 1011 | typedef typename traits_type::pos_type pos_type; |
| 1012 | typedef typename traits_type::off_type off_type; |
| 1013 | |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1014 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1015 | basic_ifstream(); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1016 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1017 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in); |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1019 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1020 | explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1021 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1022 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1023 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | basic_ifstream(basic_ifstream&& __rhs); |
| 1025 | #endif |
| 1026 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1027 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1028 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1029 | basic_ifstream& operator=(basic_ifstream&& __rhs); |
| 1030 | #endif |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1031 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | void swap(basic_ifstream& __rhs); |
| 1033 | |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1034 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | basic_filebuf<char_type, traits_type>* rdbuf() const; |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1036 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1037 | bool is_open() const; |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1038 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | void open(const char* __s, ios_base::openmode __mode = ios_base::in); |
| 1040 | void open(const string& __s, ios_base::openmode __mode = ios_base::in); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1041 | #endif |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1042 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1043 | void close(); |
| 1044 | |
| 1045 | private: |
| 1046 | basic_filebuf<char_type, traits_type> __sb_; |
| 1047 | }; |
| 1048 | |
| 1049 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1050 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | basic_ifstream<_CharT, _Traits>::basic_ifstream() |
| 1052 | : basic_istream<char_type, traits_type>(&__sb_) |
| 1053 | { |
| 1054 | } |
| 1055 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1056 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1057 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1058 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1059 | basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode) |
| 1060 | : basic_istream<char_type, traits_type>(&__sb_) |
| 1061 | { |
| 1062 | if (__sb_.open(__s, __mode | ios_base::in) == 0) |
| 1063 | this->setstate(ios_base::failbit); |
| 1064 | } |
| 1065 | |
| 1066 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1067 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1068 | basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode) |
| 1069 | : basic_istream<char_type, traits_type>(&__sb_) |
| 1070 | { |
| 1071 | if (__sb_.open(__s, __mode | ios_base::in) == 0) |
| 1072 | this->setstate(ios_base::failbit); |
| 1073 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1074 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1075 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1076 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1077 | |
| 1078 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1079 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1080 | basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1081 | : basic_istream<char_type, traits_type>(_VSTD::move(__rhs)), |
| 1082 | __sb_(_VSTD::move(__rhs.__sb_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | { |
| 1084 | this->set_rdbuf(&__sb_); |
| 1085 | } |
| 1086 | |
| 1087 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1088 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1089 | basic_ifstream<_CharT, _Traits>& |
| 1090 | basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) |
| 1091 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1092 | basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); |
| 1093 | __sb_ = _VSTD::move(__rhs.__sb_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | return *this; |
| 1095 | } |
| 1096 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1097 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1098 | |
| 1099 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1100 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | void |
| 1102 | basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) |
| 1103 | { |
| 1104 | basic_istream<char_type, traits_type>::swap(__rhs); |
| 1105 | __sb_.swap(__rhs.__sb_); |
| 1106 | } |
| 1107 | |
| 1108 | template <class _CharT, class _Traits> |
| 1109 | inline _LIBCPP_INLINE_VISIBILITY |
| 1110 | void |
| 1111 | swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) |
| 1112 | { |
| 1113 | __x.swap(__y); |
| 1114 | } |
| 1115 | |
| 1116 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1117 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | basic_filebuf<_CharT, _Traits>* |
| 1119 | basic_ifstream<_CharT, _Traits>::rdbuf() const |
| 1120 | { |
| 1121 | return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); |
| 1122 | } |
| 1123 | |
| 1124 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1125 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1126 | bool |
| 1127 | basic_ifstream<_CharT, _Traits>::is_open() const |
| 1128 | { |
| 1129 | return __sb_.is_open(); |
| 1130 | } |
| 1131 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1132 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1133 | template <class _CharT, class _Traits> |
| 1134 | void |
| 1135 | basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) |
| 1136 | { |
| 1137 | if (__sb_.open(__s, __mode | ios_base::in)) |
| 1138 | this->clear(); |
| 1139 | else |
| 1140 | this->setstate(ios_base::failbit); |
| 1141 | } |
| 1142 | |
| 1143 | template <class _CharT, class _Traits> |
| 1144 | void |
| 1145 | basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) |
| 1146 | { |
| 1147 | if (__sb_.open(__s, __mode | ios_base::in)) |
| 1148 | this->clear(); |
| 1149 | else |
| 1150 | this->setstate(ios_base::failbit); |
| 1151 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1152 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | |
| 1154 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1155 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1156 | void |
| 1157 | basic_ifstream<_CharT, _Traits>::close() |
| 1158 | { |
| 1159 | if (__sb_.close() == 0) |
| 1160 | this->setstate(ios_base::failbit); |
| 1161 | } |
| 1162 | |
| 1163 | // basic_ofstream |
| 1164 | |
| 1165 | template <class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1166 | class _LIBCPP_TYPE_VIS_ONLY basic_ofstream |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | : public basic_ostream<_CharT, _Traits> |
| 1168 | { |
| 1169 | public: |
| 1170 | typedef _CharT char_type; |
| 1171 | typedef _Traits traits_type; |
| 1172 | typedef typename traits_type::int_type int_type; |
| 1173 | typedef typename traits_type::pos_type pos_type; |
| 1174 | typedef typename traits_type::off_type off_type; |
| 1175 | |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1176 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1177 | basic_ofstream(); |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1178 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1179 | explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1180 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1181 | explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1182 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1183 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1184 | basic_ofstream(basic_ofstream&& __rhs); |
| 1185 | #endif |
| 1186 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1187 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1188 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1189 | basic_ofstream& operator=(basic_ofstream&& __rhs); |
| 1190 | #endif |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | void swap(basic_ofstream& __rhs); |
| 1193 | |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1194 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | basic_filebuf<char_type, traits_type>* rdbuf() const; |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1196 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1197 | bool is_open() const; |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1198 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1199 | void open(const char* __s, ios_base::openmode __mode = ios_base::out); |
| 1200 | void open(const string& __s, ios_base::openmode __mode = ios_base::out); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1201 | #endif |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1202 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | void close(); |
| 1204 | |
| 1205 | private: |
| 1206 | basic_filebuf<char_type, traits_type> __sb_; |
| 1207 | }; |
| 1208 | |
| 1209 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1210 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | basic_ofstream<_CharT, _Traits>::basic_ofstream() |
| 1212 | : basic_ostream<char_type, traits_type>(&__sb_) |
| 1213 | { |
| 1214 | } |
| 1215 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1216 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1218 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1219 | basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode) |
| 1220 | : basic_ostream<char_type, traits_type>(&__sb_) |
| 1221 | { |
| 1222 | if (__sb_.open(__s, __mode | ios_base::out) == 0) |
| 1223 | this->setstate(ios_base::failbit); |
| 1224 | } |
| 1225 | |
| 1226 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1227 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode) |
| 1229 | : basic_ostream<char_type, traits_type>(&__sb_) |
| 1230 | { |
| 1231 | if (__sb_.open(__s, __mode | ios_base::out) == 0) |
| 1232 | this->setstate(ios_base::failbit); |
| 1233 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1234 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1235 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1236 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1237 | |
| 1238 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1239 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1240 | basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1241 | : basic_ostream<char_type, traits_type>(_VSTD::move(__rhs)), |
| 1242 | __sb_(_VSTD::move(__rhs.__sb_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1243 | { |
| 1244 | this->set_rdbuf(&__sb_); |
| 1245 | } |
| 1246 | |
| 1247 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1248 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1249 | basic_ofstream<_CharT, _Traits>& |
| 1250 | basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) |
| 1251 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1252 | basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); |
| 1253 | __sb_ = _VSTD::move(__rhs.__sb_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1254 | return *this; |
| 1255 | } |
| 1256 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1257 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1258 | |
| 1259 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1260 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1261 | void |
| 1262 | basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) |
| 1263 | { |
| 1264 | basic_ostream<char_type, traits_type>::swap(__rhs); |
| 1265 | __sb_.swap(__rhs.__sb_); |
| 1266 | } |
| 1267 | |
| 1268 | template <class _CharT, class _Traits> |
| 1269 | inline _LIBCPP_INLINE_VISIBILITY |
| 1270 | void |
| 1271 | swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) |
| 1272 | { |
| 1273 | __x.swap(__y); |
| 1274 | } |
| 1275 | |
| 1276 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1277 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | basic_filebuf<_CharT, _Traits>* |
| 1279 | basic_ofstream<_CharT, _Traits>::rdbuf() const |
| 1280 | { |
| 1281 | return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); |
| 1282 | } |
| 1283 | |
| 1284 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1285 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | bool |
| 1287 | basic_ofstream<_CharT, _Traits>::is_open() const |
| 1288 | { |
| 1289 | return __sb_.is_open(); |
| 1290 | } |
| 1291 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1292 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1293 | template <class _CharT, class _Traits> |
| 1294 | void |
| 1295 | basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) |
| 1296 | { |
| 1297 | if (__sb_.open(__s, __mode | ios_base::out)) |
| 1298 | this->clear(); |
| 1299 | else |
| 1300 | this->setstate(ios_base::failbit); |
| 1301 | } |
| 1302 | |
| 1303 | template <class _CharT, class _Traits> |
| 1304 | void |
| 1305 | basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) |
| 1306 | { |
| 1307 | if (__sb_.open(__s, __mode | ios_base::out)) |
| 1308 | this->clear(); |
| 1309 | else |
| 1310 | this->setstate(ios_base::failbit); |
| 1311 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1312 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | |
| 1314 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1315 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1316 | void |
| 1317 | basic_ofstream<_CharT, _Traits>::close() |
| 1318 | { |
| 1319 | if (__sb_.close() == 0) |
| 1320 | this->setstate(ios_base::failbit); |
| 1321 | } |
| 1322 | |
| 1323 | // basic_fstream |
| 1324 | |
| 1325 | template <class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1326 | class _LIBCPP_TYPE_VIS_ONLY basic_fstream |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1327 | : public basic_iostream<_CharT, _Traits> |
| 1328 | { |
| 1329 | public: |
| 1330 | typedef _CharT char_type; |
| 1331 | typedef _Traits traits_type; |
| 1332 | typedef typename traits_type::int_type int_type; |
| 1333 | typedef typename traits_type::pos_type pos_type; |
| 1334 | typedef typename traits_type::off_type off_type; |
| 1335 | |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1336 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1337 | basic_fstream(); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1338 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1339 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1340 | explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1342 | explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1343 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1344 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1345 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1346 | basic_fstream(basic_fstream&& __rhs); |
| 1347 | #endif |
| 1348 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1349 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1351 | basic_fstream& operator=(basic_fstream&& __rhs); |
| 1352 | #endif |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1353 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1354 | void swap(basic_fstream& __rhs); |
| 1355 | |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | basic_filebuf<char_type, traits_type>* rdbuf() const; |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1358 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1359 | bool is_open() const; |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1360 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 | void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); |
| 1362 | void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1363 | #endif |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1365 | void close(); |
| 1366 | |
| 1367 | private: |
| 1368 | basic_filebuf<char_type, traits_type> __sb_; |
| 1369 | }; |
| 1370 | |
| 1371 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1372 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1373 | basic_fstream<_CharT, _Traits>::basic_fstream() |
| 1374 | : basic_iostream<char_type, traits_type>(&__sb_) |
| 1375 | { |
| 1376 | } |
| 1377 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1378 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1379 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1380 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode) |
| 1382 | : basic_iostream<char_type, traits_type>(&__sb_) |
| 1383 | { |
| 1384 | if (__sb_.open(__s, __mode) == 0) |
| 1385 | this->setstate(ios_base::failbit); |
| 1386 | } |
| 1387 | |
| 1388 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1389 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1390 | basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode) |
| 1391 | : basic_iostream<char_type, traits_type>(&__sb_) |
| 1392 | { |
| 1393 | if (__sb_.open(__s, __mode) == 0) |
| 1394 | this->setstate(ios_base::failbit); |
| 1395 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1396 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1398 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1399 | |
| 1400 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1401 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1403 | : basic_iostream<char_type, traits_type>(_VSTD::move(__rhs)), |
| 1404 | __sb_(_VSTD::move(__rhs.__sb_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | { |
| 1406 | this->set_rdbuf(&__sb_); |
| 1407 | } |
| 1408 | |
| 1409 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1410 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1411 | basic_fstream<_CharT, _Traits>& |
| 1412 | basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) |
| 1413 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1414 | basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); |
| 1415 | __sb_ = _VSTD::move(__rhs.__sb_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | return *this; |
| 1417 | } |
| 1418 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1419 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1420 | |
| 1421 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1422 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | void |
| 1424 | basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) |
| 1425 | { |
| 1426 | basic_iostream<char_type, traits_type>::swap(__rhs); |
| 1427 | __sb_.swap(__rhs.__sb_); |
| 1428 | } |
| 1429 | |
| 1430 | template <class _CharT, class _Traits> |
| 1431 | inline _LIBCPP_INLINE_VISIBILITY |
| 1432 | void |
| 1433 | swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) |
| 1434 | { |
| 1435 | __x.swap(__y); |
| 1436 | } |
| 1437 | |
| 1438 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1439 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | basic_filebuf<_CharT, _Traits>* |
| 1441 | basic_fstream<_CharT, _Traits>::rdbuf() const |
| 1442 | { |
| 1443 | return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); |
| 1444 | } |
| 1445 | |
| 1446 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1447 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | bool |
| 1449 | basic_fstream<_CharT, _Traits>::is_open() const |
| 1450 | { |
| 1451 | return __sb_.is_open(); |
| 1452 | } |
| 1453 | |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1454 | #ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | template <class _CharT, class _Traits> |
| 1456 | void |
| 1457 | basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) |
| 1458 | { |
| 1459 | if (__sb_.open(__s, __mode)) |
| 1460 | this->clear(); |
| 1461 | else |
| 1462 | this->setstate(ios_base::failbit); |
| 1463 | } |
| 1464 | |
| 1465 | template <class _CharT, class _Traits> |
| 1466 | void |
| 1467 | basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) |
| 1468 | { |
| 1469 | if (__sb_.open(__s, __mode)) |
| 1470 | this->clear(); |
| 1471 | else |
| 1472 | this->setstate(ios_base::failbit); |
| 1473 | } |
Ed Schouten | b33ae5b | 2015-03-12 15:44:39 +0000 | [diff] [blame] | 1474 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | |
| 1476 | template <class _CharT, class _Traits> |
Evgeniy Stepanov | 9341a8a | 2016-04-22 01:04:55 +0000 | [diff] [blame] | 1477 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 | void |
| 1479 | basic_fstream<_CharT, _Traits>::close() |
| 1480 | { |
| 1481 | if (__sb_.close() == 0) |
| 1482 | this->setstate(ios_base::failbit); |
| 1483 | } |
| 1484 | |
| 1485 | _LIBCPP_END_NAMESPACE_STD |
| 1486 | |
| 1487 | #endif // _LIBCPP_FSTREAM |