| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | #ifndef _GLIBCXX_FSTREAM |
| 34 | #define _GLIBCXX_FSTREAM 1 |
| 35 | |
| 36 | #pragma GCC system_header |
| 37 | |
| 38 | #include <istream> |
| 39 | #include <ostream> |
| 40 | #include <bits/codecvt.h> |
| 41 | #include <cstdio> |
| 42 | #include <bits/basic_file.h> |
| 43 | #if __cplusplus >= 201103L |
| 44 | #include <string> |
| 45 | #endif |
| 46 | |
| 47 | namespace std _GLIBCXX_VISIBILITY(default) |
| 48 | { |
| 49 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | template<typename _CharT, typename _Traits> |
| 72 | class basic_filebuf : public basic_streambuf<_CharT, _Traits> |
| 73 | { |
| 74 | #if __cplusplus >= 201103L |
| 75 | template<typename _Tp> |
| 76 | using __chk_state = __and_<is_copy_assignable<_Tp>, |
| 77 | is_copy_constructible<_Tp>, |
| 78 | is_default_constructible<_Tp>>; |
| 79 | |
| 80 | static_assert(__chk_state<typename _Traits::state_type>::value, |
| 81 | "state_type must be CopyAssignable, CopyConstructible" |
| 82 | " and DefaultConstructible"); |
| 83 | |
| 84 | static_assert(is_same<typename _Traits::pos_type, |
| 85 | fpos<typename _Traits::state_type>>::value, |
| 86 | "pos_type must be fpos<state_type>"); |
| 87 | #endif |
| 88 | public: |
| 89 | |
| 90 | typedef _CharT char_type; |
| 91 | typedef _Traits traits_type; |
| 92 | typedef typename traits_type::int_type int_type; |
| 93 | typedef typename traits_type::pos_type pos_type; |
| 94 | typedef typename traits_type::off_type off_type; |
| 95 | |
| 96 | typedef basic_streambuf<char_type, traits_type> __streambuf_type; |
| 97 | typedef basic_filebuf<char_type, traits_type> __filebuf_type; |
| 98 | typedef __basic_file<char> __file_type; |
| 99 | typedef typename traits_type::state_type __state_type; |
| 100 | typedef codecvt<char_type, char, __state_type> __codecvt_type; |
| 101 | |
| 102 | friend class ios_base; |
| 103 | |
| 104 | protected: |
| 105 | |
| 106 | |
| 107 | __c_lock _M_lock; |
| 108 | |
| 109 | |
| 110 | __file_type _M_file; |
| 111 | |
| 112 | |
| 113 | ios_base::openmode _M_mode; |
| 114 | |
| 115 | |
| 116 | __state_type _M_state_beg; |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | __state_type _M_state_cur; |
| 122 | |
| 123 | |
| 124 | |
| 125 | __state_type _M_state_last; |
| 126 | |
| 127 | |
| 128 | char_type* _M_buf; |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | size_t _M_buf_size; |
| 136 | |
| 137 | |
| 138 | bool _M_buf_allocated; |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | bool _M_reading; |
| 148 | bool _M_writing; |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | char_type _M_pback; |
| 157 | char_type* _M_pback_cur_save; |
| 158 | char_type* _M_pback_end_save; |
| 159 | bool _M_pback_init; |
| 160 | |
| 161 | |
| 162 | |
| 163 | const __codecvt_type* _M_codecvt; |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | char* _M_ext_buf; |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | streamsize _M_ext_buf_size; |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | const char* _M_ext_next; |
| 183 | char* _M_ext_end; |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | void |
| 191 | _M_create_pback() |
| 192 | { |
| 193 | if (!_M_pback_init) |
| 194 | { |
| 195 | _M_pback_cur_save = this->gptr(); |
| 196 | _M_pback_end_save = this->egptr(); |
| 197 | this->setg(&_M_pback, &_M_pback, &_M_pback + 1); |
| 198 | _M_pback_init = true; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | void |
| 208 | _M_destroy_pback() throw() |
| 209 | { |
| 210 | if (_M_pback_init) |
| 211 | { |
| 212 | |
| 213 | _M_pback_cur_save += this->gptr() != this->eback(); |
| 214 | this->setg(_M_buf, _M_pback_cur_save, _M_pback_end_save); |
| 215 | _M_pback_init = false; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | public: |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | basic_filebuf(); |
| 228 | |
| 229 | #if __cplusplus >= 201103L |
| 230 | basic_filebuf(const basic_filebuf&) = delete; |
| 231 | basic_filebuf(basic_filebuf&&); |
| 232 | #endif |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | virtual |
| 238 | ~basic_filebuf() |
| 239 | { this->close(); } |
| 240 | |
| 241 | #if __cplusplus >= 201103L |
| 242 | basic_filebuf& operator=(const basic_filebuf&) = delete; |
| 243 | basic_filebuf& operator=(basic_filebuf&&); |
| 244 | void swap(basic_filebuf&); |
| 245 | #endif |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | bool |
| 252 | is_open() const throw() |
| 253 | { return _M_file.is_open(); } |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | __filebuf_type* |
| 297 | open(const char* __s, ios_base::openmode __mode); |
| 298 | |
| 299 | #if __cplusplus >= 201103L |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | __filebuf_type* |
| 307 | open(const std::string& __s, ios_base::openmode __mode) |
| 308 | { return open(__s.c_str(), __mode); } |
| 309 | #endif |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | __filebuf_type* |
| 324 | close(); |
| 325 | |
| 326 | protected: |
| 327 | void |
| 328 | _M_allocate_internal_buffer(); |
| 329 | |
| 330 | void |
| 331 | _M_destroy_internal_buffer() throw(); |
| 332 | |
| 333 | |
| 334 | virtual streamsize |
| 335 | showmanyc(); |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | virtual int_type |
| 343 | underflow(); |
| 344 | |
| 345 | virtual int_type |
| 346 | pbackfail(int_type __c = _Traits::eof()); |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | virtual int_type |
| 356 | overflow(int_type __c = _Traits::eof()); |
| 357 | |
| 358 | |
| 359 | |
| 360 | bool |
| 361 | _M_convert_to_external(char_type*, streamsize); |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | virtual __streambuf_type* |
| 376 | setbuf(char_type* __s, streamsize __n); |
| 377 | |
| 378 | virtual pos_type |
| 379 | seekoff(off_type __off, ios_base::seekdir __way, |
| 380 | ios_base::openmode __mode = ios_base::in | ios_base::out); |
| 381 | |
| 382 | virtual pos_type |
| 383 | seekpos(pos_type __pos, |
| 384 | ios_base::openmode __mode = ios_base::in | ios_base::out); |
| 385 | |
| 386 | |
| 387 | pos_type |
| 388 | _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state); |
| 389 | |
| 390 | int |
| 391 | _M_get_ext_pos(__state_type &__state); |
| 392 | |
| 393 | virtual int |
| 394 | sync(); |
| 395 | |
| 396 | virtual void |
| 397 | imbue(const locale& __loc); |
| 398 | |
| 399 | virtual streamsize |
| 400 | xsgetn(char_type* __s, streamsize __n); |
| 401 | |
| 402 | virtual streamsize |
| 403 | xsputn(const char_type* __s, streamsize __n); |
| 404 | |
| 405 | |
| 406 | bool |
| 407 | _M_terminate_output(); |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | void |
| 422 | _M_set_buffer(streamsize __off) |
| 423 | { |
| 424 | const bool __testin = _M_mode & ios_base::in; |
| 425 | const bool __testout = (_M_mode & ios_base::out |
| 426 | || _M_mode & ios_base::app); |
| 427 | |
| 428 | if (__testin && __off > 0) |
| 429 | this->setg(_M_buf, _M_buf, _M_buf + __off); |
| 430 | else |
| 431 | this->setg(_M_buf, _M_buf, _M_buf); |
| 432 | |
| 433 | if (__testout && __off == 0 && _M_buf_size > 1 ) |
| 434 | this->setp(_M_buf, _M_buf + _M_buf_size - 1); |
| 435 | else |
| 436 | this->setp(0, 0); |
| 437 | } |
| 438 | }; |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | template<typename _CharT, typename _Traits> |
| 455 | class basic_ifstream : public basic_istream<_CharT, _Traits> |
| 456 | { |
| 457 | public: |
| 458 | |
| 459 | typedef _CharT char_type; |
| 460 | typedef _Traits traits_type; |
| 461 | typedef typename traits_type::int_type int_type; |
| 462 | typedef typename traits_type::pos_type pos_type; |
| 463 | typedef typename traits_type::off_type off_type; |
| 464 | |
| 465 | |
| 466 | typedef basic_filebuf<char_type, traits_type> __filebuf_type; |
| 467 | typedef basic_istream<char_type, traits_type> __istream_type; |
| 468 | |
| 469 | private: |
| 470 | __filebuf_type _M_filebuf; |
| 471 | |
| 472 | public: |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | basic_ifstream() : __istream_type(), _M_filebuf() |
| 482 | { this->init(&_M_filebuf); } |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | explicit |
| 495 | basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in) |
| 496 | : __istream_type(), _M_filebuf() |
| 497 | { |
| 498 | this->init(&_M_filebuf); |
| 499 | this->open(__s, __mode); |
| 500 | } |
| 501 | |
| 502 | #if __cplusplus >= 201103L |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | explicit |
| 511 | basic_ifstream(const std::string& __s, |
| 512 | ios_base::openmode __mode = ios_base::in) |
| 513 | : __istream_type(), _M_filebuf() |
| 514 | { |
| 515 | this->init(&_M_filebuf); |
| 516 | this->open(__s, __mode); |
| 517 | } |
| 518 | |
| 519 | basic_ifstream(const basic_ifstream&) = delete; |
| 520 | |
| 521 | basic_ifstream(basic_ifstream&& __rhs) |
| 522 | : __istream_type(std::move(__rhs)), |
| 523 | _M_filebuf(std::move(__rhs._M_filebuf)) |
| 524 | { __istream_type::set_rdbuf(&_M_filebuf); } |
| 525 | #endif |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | ~basic_ifstream() |
| 534 | { } |
| 535 | |
| 536 | #if __cplusplus >= 201103L |
| 537 | |
| 538 | |
| 539 | basic_ifstream& |
| 540 | operator=(const basic_ifstream&) = delete; |
| 541 | |
| 542 | basic_ifstream& |
| 543 | operator=(basic_ifstream&& __rhs) |
| 544 | { |
| 545 | __istream_type::operator=(std::move(__rhs)); |
| 546 | _M_filebuf = std::move(__rhs._M_filebuf); |
| 547 | return *this; |
| 548 | } |
| 549 | |
| 550 | void |
| 551 | swap(basic_ifstream& __rhs) |
| 552 | { |
| 553 | __istream_type::swap(__rhs); |
| 554 | _M_filebuf.swap(__rhs._M_filebuf); |
| 555 | } |
| 556 | #endif |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | __filebuf_type* |
| 566 | rdbuf() const |
| 567 | { return const_cast<__filebuf_type*>(&_M_filebuf); } |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | bool |
| 574 | is_open() |
| 575 | { return _M_filebuf.is_open(); } |
| 576 | |
| 577 | |
| 578 | |
| 579 | bool |
| 580 | is_open() const |
| 581 | { return _M_filebuf.is_open(); } |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | void |
| 595 | open(const char* __s, ios_base::openmode __mode = ios_base::in) |
| 596 | { |
| 597 | if (!_M_filebuf.open(__s, __mode | ios_base::in)) |
| 598 | this->setstate(ios_base::failbit); |
| 599 | else |
| 600 | |
| 601 | |
| 602 | this->clear(); |
| 603 | } |
| 604 | |
| 605 | #if __cplusplus >= 201103L |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | void |
| 615 | open(const std::string& __s, ios_base::openmode __mode = ios_base::in) |
| 616 | { |
| 617 | if (!_M_filebuf.open(__s, __mode | ios_base::in)) |
| 618 | this->setstate(ios_base::failbit); |
| 619 | else |
| 620 | |
| 621 | |
| 622 | this->clear(); |
| 623 | } |
| 624 | #endif |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | void |
| 633 | close() |
| 634 | { |
| 635 | if (!_M_filebuf.close()) |
| 636 | this->setstate(ios_base::failbit); |
| 637 | } |
| 638 | }; |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | template<typename _CharT, typename _Traits> |
| 656 | class basic_ofstream : public basic_ostream<_CharT,_Traits> |
| 657 | { |
| 658 | public: |
| 659 | |
| 660 | typedef _CharT char_type; |
| 661 | typedef _Traits traits_type; |
| 662 | typedef typename traits_type::int_type int_type; |
| 663 | typedef typename traits_type::pos_type pos_type; |
| 664 | typedef typename traits_type::off_type off_type; |
| 665 | |
| 666 | |
| 667 | typedef basic_filebuf<char_type, traits_type> __filebuf_type; |
| 668 | typedef basic_ostream<char_type, traits_type> __ostream_type; |
| 669 | |
| 670 | private: |
| 671 | __filebuf_type _M_filebuf; |
| 672 | |
| 673 | public: |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | basic_ofstream(): __ostream_type(), _M_filebuf() |
| 683 | { this->init(&_M_filebuf); } |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | explicit |
| 697 | basic_ofstream(const char* __s, |
| 698 | ios_base::openmode __mode = ios_base::out|ios_base::trunc) |
| 699 | : __ostream_type(), _M_filebuf() |
| 700 | { |
| 701 | this->init(&_M_filebuf); |
| 702 | this->open(__s, __mode); |
| 703 | } |
| 704 | |
| 705 | #if __cplusplus >= 201103L |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | explicit |
| 715 | basic_ofstream(const std::string& __s, |
| 716 | ios_base::openmode __mode = ios_base::out|ios_base::trunc) |
| 717 | : __ostream_type(), _M_filebuf() |
| 718 | { |
| 719 | this->init(&_M_filebuf); |
| 720 | this->open(__s, __mode); |
| 721 | } |
| 722 | |
| 723 | basic_ofstream(const basic_ofstream&) = delete; |
| 724 | |
| 725 | basic_ofstream(basic_ofstream&& __rhs) |
| 726 | : __ostream_type(std::move(__rhs)), |
| 727 | _M_filebuf(std::move(__rhs._M_filebuf)) |
| 728 | { __ostream_type::set_rdbuf(&_M_filebuf); } |
| 729 | #endif |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | ~basic_ofstream() |
| 738 | { } |
| 739 | |
| 740 | #if __cplusplus >= 201103L |
| 741 | |
| 742 | |
| 743 | basic_ofstream& |
| 744 | operator=(const basic_ofstream&) = delete; |
| 745 | |
| 746 | basic_ofstream& |
| 747 | operator=(basic_ofstream&& __rhs) |
| 748 | { |
| 749 | __ostream_type::operator=(std::move(__rhs)); |
| 750 | _M_filebuf = std::move(__rhs._M_filebuf); |
| 751 | return *this; |
| 752 | } |
| 753 | |
| 754 | void |
| 755 | swap(basic_ofstream& __rhs) |
| 756 | { |
| 757 | __ostream_type::swap(__rhs); |
| 758 | _M_filebuf.swap(__rhs._M_filebuf); |
| 759 | } |
| 760 | #endif |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | __filebuf_type* |
| 770 | rdbuf() const |
| 771 | { return const_cast<__filebuf_type*>(&_M_filebuf); } |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | bool |
| 778 | is_open() |
| 779 | { return _M_filebuf.is_open(); } |
| 780 | |
| 781 | |
| 782 | |
| 783 | bool |
| 784 | is_open() const |
| 785 | { return _M_filebuf.is_open(); } |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | void |
| 799 | open(const char* __s, |
| 800 | ios_base::openmode __mode = ios_base::out | ios_base::trunc) |
| 801 | { |
| 802 | if (!_M_filebuf.open(__s, __mode | ios_base::out)) |
| 803 | this->setstate(ios_base::failbit); |
| 804 | else |
| 805 | |
| 806 | |
| 807 | this->clear(); |
| 808 | } |
| 809 | |
| 810 | #if __cplusplus >= 201103L |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | void |
| 820 | open(const std::string& __s, |
| 821 | ios_base::openmode __mode = ios_base::out | ios_base::trunc) |
| 822 | { |
| 823 | if (!_M_filebuf.open(__s, __mode | ios_base::out)) |
| 824 | this->setstate(ios_base::failbit); |
| 825 | else |
| 826 | |
| 827 | |
| 828 | this->clear(); |
| 829 | } |
| 830 | #endif |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | void |
| 839 | close() |
| 840 | { |
| 841 | if (!_M_filebuf.close()) |
| 842 | this->setstate(ios_base::failbit); |
| 843 | } |
| 844 | }; |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | template<typename _CharT, typename _Traits> |
| 862 | class basic_fstream : public basic_iostream<_CharT, _Traits> |
| 863 | { |
| 864 | public: |
| 865 | |
| 866 | typedef _CharT char_type; |
| 867 | typedef _Traits traits_type; |
| 868 | typedef typename traits_type::int_type int_type; |
| 869 | typedef typename traits_type::pos_type pos_type; |
| 870 | typedef typename traits_type::off_type off_type; |
| 871 | |
| 872 | |
| 873 | typedef basic_filebuf<char_type, traits_type> __filebuf_type; |
| 874 | typedef basic_ios<char_type, traits_type> __ios_type; |
| 875 | typedef basic_iostream<char_type, traits_type> __iostream_type; |
| 876 | |
| 877 | private: |
| 878 | __filebuf_type _M_filebuf; |
| 879 | |
| 880 | public: |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | basic_fstream() |
| 890 | : __iostream_type(), _M_filebuf() |
| 891 | { this->init(&_M_filebuf); } |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | explicit |
| 902 | basic_fstream(const char* __s, |
| 903 | ios_base::openmode __mode = ios_base::in | ios_base::out) |
| 904 | : __iostream_type(0), _M_filebuf() |
| 905 | { |
| 906 | this->init(&_M_filebuf); |
| 907 | this->open(__s, __mode); |
| 908 | } |
| 909 | |
| 910 | #if __cplusplus >= 201103L |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | explicit |
| 917 | basic_fstream(const std::string& __s, |
| 918 | ios_base::openmode __mode = ios_base::in | ios_base::out) |
| 919 | : __iostream_type(0), _M_filebuf() |
| 920 | { |
| 921 | this->init(&_M_filebuf); |
| 922 | this->open(__s, __mode); |
| 923 | } |
| 924 | |
| 925 | basic_fstream(const basic_fstream&) = delete; |
| 926 | |
| 927 | basic_fstream(basic_fstream&& __rhs) |
| 928 | : __iostream_type(std::move(__rhs)), |
| 929 | _M_filebuf(std::move(__rhs._M_filebuf)) |
| 930 | { __iostream_type::set_rdbuf(&_M_filebuf); } |
| 931 | #endif |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | ~basic_fstream() |
| 940 | { } |
| 941 | |
| 942 | #if __cplusplus >= 201103L |
| 943 | |
| 944 | |
| 945 | basic_fstream& |
| 946 | operator=(const basic_fstream&) = delete; |
| 947 | |
| 948 | basic_fstream& |
| 949 | operator=(basic_fstream&& __rhs) |
| 950 | { |
| 951 | __iostream_type::operator=(std::move(__rhs)); |
| 952 | _M_filebuf = std::move(__rhs._M_filebuf); |
| 953 | return *this; |
| 954 | } |
| 955 | |
| 956 | void |
| 957 | swap(basic_fstream& __rhs) |
| 958 | { |
| 959 | __iostream_type::swap(__rhs); |
| 960 | _M_filebuf.swap(__rhs._M_filebuf); |
| 961 | } |
| 962 | #endif |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | __filebuf_type* |
| 972 | rdbuf() const |
| 973 | { return const_cast<__filebuf_type*>(&_M_filebuf); } |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | bool |
| 980 | is_open() |
| 981 | { return _M_filebuf.is_open(); } |
| 982 | |
| 983 | |
| 984 | |
| 985 | bool |
| 986 | is_open() const |
| 987 | { return _M_filebuf.is_open(); } |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | |
| 998 | |
| 999 | |
| 1000 | void |
| 1001 | open(const char* __s, |
| 1002 | ios_base::openmode __mode = ios_base::in | ios_base::out) |
| 1003 | { |
| 1004 | if (!_M_filebuf.open(__s, __mode)) |
| 1005 | this->setstate(ios_base::failbit); |
| 1006 | else |
| 1007 | |
| 1008 | |
| 1009 | this->clear(); |
| 1010 | } |
| 1011 | |
| 1012 | #if __cplusplus >= 201103L |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | |
| 1021 | void |
| 1022 | open(const std::string& __s, |
| 1023 | ios_base::openmode __mode = ios_base::in | ios_base::out) |
| 1024 | { |
| 1025 | if (!_M_filebuf.open(__s, __mode)) |
| 1026 | this->setstate(ios_base::failbit); |
| 1027 | else |
| 1028 | |
| 1029 | |
| 1030 | this->clear(); |
| 1031 | } |
| 1032 | #endif |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | void |
| 1041 | close() |
| 1042 | { |
| 1043 | if (!_M_filebuf.close()) |
| 1044 | this->setstate(ios_base::failbit); |
| 1045 | } |
| 1046 | }; |
| 1047 | |
| 1048 | #if __cplusplus >= 201103L |
| 1049 | |
| 1050 | template <class _CharT, class _Traits> |
| 1051 | inline void |
| 1052 | swap(basic_filebuf<_CharT, _Traits>& __x, |
| 1053 | basic_filebuf<_CharT, _Traits>& __y) |
| 1054 | { __x.swap(__y); } |
| 1055 | |
| 1056 | |
| 1057 | template <class _CharT, class _Traits> |
| 1058 | inline void |
| 1059 | swap(basic_ifstream<_CharT, _Traits>& __x, |
| 1060 | basic_ifstream<_CharT, _Traits>& __y) |
| 1061 | { __x.swap(__y); } |
| 1062 | |
| 1063 | |
| 1064 | template <class _CharT, class _Traits> |
| 1065 | inline void |
| 1066 | swap(basic_ofstream<_CharT, _Traits>& __x, |
| 1067 | basic_ofstream<_CharT, _Traits>& __y) |
| 1068 | { __x.swap(__y); } |
| 1069 | |
| 1070 | |
| 1071 | template <class _CharT, class _Traits> |
| 1072 | inline void |
| 1073 | swap(basic_fstream<_CharT, _Traits>& __x, |
| 1074 | basic_fstream<_CharT, _Traits>& __y) |
| 1075 | { __x.swap(__y); } |
| 1076 | #endif |
| 1077 | |
| 1078 | _GLIBCXX_END_NAMESPACE_VERSION |
| 1079 | } |
| 1080 | |
| 1081 | #include <bits/fstream.tcc> |
| 1082 | |
| 1083 | #endif |
| 1084 | |