14684ddb6SLionel Sambuc// -*- C++ -*- 24684ddb6SLionel Sambuc//===------------------------- fstream ------------------------------------===// 34684ddb6SLionel Sambuc// 44684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 54684ddb6SLionel Sambuc// 64684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 74684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 84684ddb6SLionel Sambuc// 94684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 104684ddb6SLionel Sambuc 114684ddb6SLionel Sambuc#ifndef _LIBCPP_FSTREAM 124684ddb6SLionel Sambuc#define _LIBCPP_FSTREAM 134684ddb6SLionel Sambuc 144684ddb6SLionel Sambuc/* 154684ddb6SLionel Sambuc fstream synopsis 164684ddb6SLionel Sambuc 174684ddb6SLionel Sambuctemplate <class charT, class traits = char_traits<charT> > 184684ddb6SLionel Sambucclass basic_filebuf 194684ddb6SLionel Sambuc : public basic_streambuf<charT, traits> 204684ddb6SLionel Sambuc{ 214684ddb6SLionel Sambucpublic: 224684ddb6SLionel Sambuc typedef charT char_type; 234684ddb6SLionel Sambuc typedef traits traits_type; 244684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 254684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 264684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 274684ddb6SLionel Sambuc 284684ddb6SLionel Sambuc // 27.9.1.2 Constructors/destructor: 294684ddb6SLionel Sambuc basic_filebuf(); 304684ddb6SLionel Sambuc basic_filebuf(basic_filebuf&& rhs); 314684ddb6SLionel Sambuc virtual ~basic_filebuf(); 324684ddb6SLionel Sambuc 334684ddb6SLionel Sambuc // 27.9.1.3 Assign/swap: 344684ddb6SLionel Sambuc basic_filebuf& operator=(basic_filebuf&& rhs); 354684ddb6SLionel Sambuc void swap(basic_filebuf& rhs); 364684ddb6SLionel Sambuc 374684ddb6SLionel Sambuc // 27.9.1.4 Members: 384684ddb6SLionel Sambuc bool is_open() const; 394684ddb6SLionel Sambuc basic_filebuf* open(const char* s, ios_base::openmode mode); 404684ddb6SLionel Sambuc basic_filebuf* open(const string& s, ios_base::openmode mode); 414684ddb6SLionel Sambuc basic_filebuf* close(); 424684ddb6SLionel Sambuc 434684ddb6SLionel Sambucprotected: 444684ddb6SLionel Sambuc // 27.9.1.5 Overridden virtual functions: 454684ddb6SLionel Sambuc virtual streamsize showmanyc(); 464684ddb6SLionel Sambuc virtual int_type underflow(); 474684ddb6SLionel Sambuc virtual int_type uflow(); 484684ddb6SLionel Sambuc virtual int_type pbackfail(int_type c = traits_type::eof()); 494684ddb6SLionel Sambuc virtual int_type overflow (int_type c = traits_type::eof()); 504684ddb6SLionel Sambuc virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n); 514684ddb6SLionel Sambuc virtual pos_type seekoff(off_type off, ios_base::seekdir way, 524684ddb6SLionel Sambuc ios_base::openmode which = ios_base::in | ios_base::out); 534684ddb6SLionel Sambuc virtual pos_type seekpos(pos_type sp, 544684ddb6SLionel Sambuc ios_base::openmode which = ios_base::in | ios_base::out); 554684ddb6SLionel Sambuc virtual int sync(); 564684ddb6SLionel Sambuc virtual void imbue(const locale& loc); 574684ddb6SLionel Sambuc}; 584684ddb6SLionel Sambuc 594684ddb6SLionel Sambuctemplate <class charT, class traits> 604684ddb6SLionel Sambuc void 614684ddb6SLionel Sambuc swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y); 624684ddb6SLionel Sambuc 634684ddb6SLionel Sambuctypedef basic_filebuf<char> filebuf; 644684ddb6SLionel Sambuctypedef basic_filebuf<wchar_t> wfilebuf; 654684ddb6SLionel Sambuc 664684ddb6SLionel Sambuctemplate <class charT, class traits = char_traits<charT> > 674684ddb6SLionel Sambucclass basic_ifstream 684684ddb6SLionel Sambuc : public basic_istream<charT,traits> 694684ddb6SLionel Sambuc{ 704684ddb6SLionel Sambucpublic: 714684ddb6SLionel Sambuc typedef charT char_type; 724684ddb6SLionel Sambuc typedef traits traits_type; 734684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 744684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 754684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 764684ddb6SLionel Sambuc 774684ddb6SLionel Sambuc basic_ifstream(); 784684ddb6SLionel Sambuc explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in); 794684ddb6SLionel Sambuc explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in); 804684ddb6SLionel Sambuc basic_ifstream(basic_ifstream&& rhs); 814684ddb6SLionel Sambuc 824684ddb6SLionel Sambuc basic_ifstream& operator=(basic_ifstream&& rhs); 834684ddb6SLionel Sambuc void swap(basic_ifstream& rhs); 844684ddb6SLionel Sambuc 854684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type>* rdbuf() const; 864684ddb6SLionel Sambuc bool is_open() const; 874684ddb6SLionel Sambuc void open(const char* s, ios_base::openmode mode = ios_base::in); 884684ddb6SLionel Sambuc void open(const string& s, ios_base::openmode mode = ios_base::in); 894684ddb6SLionel Sambuc void close(); 904684ddb6SLionel Sambuc}; 914684ddb6SLionel Sambuc 924684ddb6SLionel Sambuctemplate <class charT, class traits> 934684ddb6SLionel Sambuc void 944684ddb6SLionel Sambuc swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y); 954684ddb6SLionel Sambuc 964684ddb6SLionel Sambuctypedef basic_ifstream<char> ifstream; 974684ddb6SLionel Sambuctypedef basic_ifstream<wchar_t> wifstream; 984684ddb6SLionel Sambuc 994684ddb6SLionel Sambuctemplate <class charT, class traits = char_traits<charT> > 1004684ddb6SLionel Sambucclass basic_ofstream 1014684ddb6SLionel Sambuc : public basic_ostream<charT,traits> 1024684ddb6SLionel Sambuc{ 1034684ddb6SLionel Sambucpublic: 1044684ddb6SLionel Sambuc typedef charT char_type; 1054684ddb6SLionel Sambuc typedef traits traits_type; 1064684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 1074684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 1084684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 1094684ddb6SLionel Sambuc 1104684ddb6SLionel Sambuc basic_ofstream(); 1114684ddb6SLionel Sambuc explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); 1124684ddb6SLionel Sambuc explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); 1134684ddb6SLionel Sambuc basic_ofstream(basic_ofstream&& rhs); 1144684ddb6SLionel Sambuc 1154684ddb6SLionel Sambuc basic_ofstream& operator=(basic_ofstream&& rhs); 1164684ddb6SLionel Sambuc void swap(basic_ofstream& rhs); 1174684ddb6SLionel Sambuc 1184684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type>* rdbuf() const; 1194684ddb6SLionel Sambuc bool is_open() const; 1204684ddb6SLionel Sambuc void open(const char* s, ios_base::openmode mode = ios_base::out); 1214684ddb6SLionel Sambuc void open(const string& s, ios_base::openmode mode = ios_base::out); 1224684ddb6SLionel Sambuc void close(); 1234684ddb6SLionel Sambuc}; 1244684ddb6SLionel Sambuc 1254684ddb6SLionel Sambuctemplate <class charT, class traits> 1264684ddb6SLionel Sambuc void 1274684ddb6SLionel Sambuc swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y); 1284684ddb6SLionel Sambuc 1294684ddb6SLionel Sambuctypedef basic_ofstream<char> ofstream; 1304684ddb6SLionel Sambuctypedef basic_ofstream<wchar_t> wofstream; 1314684ddb6SLionel Sambuc 1324684ddb6SLionel Sambuctemplate <class charT, class traits=char_traits<charT> > 1334684ddb6SLionel Sambucclass basic_fstream 1344684ddb6SLionel Sambuc : public basic_iostream<charT,traits> 1354684ddb6SLionel Sambuc{ 1364684ddb6SLionel Sambucpublic: 1374684ddb6SLionel Sambuc typedef charT char_type; 1384684ddb6SLionel Sambuc typedef traits traits_type; 1394684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 1404684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 1414684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 1424684ddb6SLionel Sambuc 1434684ddb6SLionel Sambuc basic_fstream(); 1444684ddb6SLionel Sambuc explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); 1454684ddb6SLionel Sambuc explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); 1464684ddb6SLionel Sambuc basic_fstream(basic_fstream&& rhs); 1474684ddb6SLionel Sambuc 1484684ddb6SLionel Sambuc basic_fstream& operator=(basic_fstream&& rhs); 1494684ddb6SLionel Sambuc void swap(basic_fstream& rhs); 1504684ddb6SLionel Sambuc 1514684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type>* rdbuf() const; 1524684ddb6SLionel Sambuc bool is_open() const; 1534684ddb6SLionel Sambuc void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); 1544684ddb6SLionel Sambuc void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); 1554684ddb6SLionel Sambuc void close(); 1564684ddb6SLionel Sambuc}; 1574684ddb6SLionel Sambuc 1584684ddb6SLionel Sambuctemplate <class charT, class traits> 1594684ddb6SLionel Sambuc void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y); 1604684ddb6SLionel Sambuc 1614684ddb6SLionel Sambuctypedef basic_fstream<char> fstream; 1624684ddb6SLionel Sambuctypedef basic_fstream<wchar_t> wfstream; 1634684ddb6SLionel Sambuc 1644684ddb6SLionel Sambuc} // std 1654684ddb6SLionel Sambuc 1664684ddb6SLionel Sambuc*/ 1674684ddb6SLionel Sambuc 1684684ddb6SLionel Sambuc#include <__config> 1694684ddb6SLionel Sambuc#include <ostream> 1704684ddb6SLionel Sambuc#include <istream> 1714684ddb6SLionel Sambuc#include <__locale> 1724684ddb6SLionel Sambuc#include <cstdio> 1734684ddb6SLionel Sambuc 1744684ddb6SLionel Sambuc#include <__undef_min_max> 1754684ddb6SLionel Sambuc 1764684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1774684ddb6SLionel Sambuc#pragma GCC system_header 1784684ddb6SLionel Sambuc#endif 1794684ddb6SLionel Sambuc 1804684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 1814684ddb6SLionel Sambuc 1824684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 1834684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY basic_filebuf 1844684ddb6SLionel Sambuc : public basic_streambuf<_CharT, _Traits> 1854684ddb6SLionel Sambuc{ 1864684ddb6SLionel Sambucpublic: 1874684ddb6SLionel Sambuc typedef _CharT char_type; 1884684ddb6SLionel Sambuc typedef _Traits traits_type; 1894684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 1904684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 1914684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 1924684ddb6SLionel Sambuc typedef typename traits_type::state_type state_type; 1934684ddb6SLionel Sambuc 1944684ddb6SLionel Sambuc // 27.9.1.2 Constructors/destructor: 1954684ddb6SLionel Sambuc basic_filebuf(); 1964684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1974684ddb6SLionel Sambuc basic_filebuf(basic_filebuf&& __rhs); 1984684ddb6SLionel Sambuc#endif 1994684ddb6SLionel Sambuc virtual ~basic_filebuf(); 2004684ddb6SLionel Sambuc 2014684ddb6SLionel Sambuc // 27.9.1.3 Assign/swap: 2024684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2034684ddb6SLionel Sambuc basic_filebuf& operator=(basic_filebuf&& __rhs); 2044684ddb6SLionel Sambuc#endif 2054684ddb6SLionel Sambuc void swap(basic_filebuf& __rhs); 2064684ddb6SLionel Sambuc 2074684ddb6SLionel Sambuc // 27.9.1.4 Members: 2084684ddb6SLionel Sambuc bool is_open() const; 209*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 2104684ddb6SLionel Sambuc basic_filebuf* open(const char* __s, ios_base::openmode __mode); 2114684ddb6SLionel Sambuc basic_filebuf* open(const string& __s, ios_base::openmode __mode); 212*0a6a1f1dSLionel Sambuc#endif 2134684ddb6SLionel Sambuc basic_filebuf* close(); 2144684ddb6SLionel Sambuc 2154684ddb6SLionel Sambucprotected: 2164684ddb6SLionel Sambuc // 27.9.1.5 Overridden virtual functions: 2174684ddb6SLionel Sambuc virtual int_type underflow(); 2184684ddb6SLionel Sambuc virtual int_type pbackfail(int_type __c = traits_type::eof()); 2194684ddb6SLionel Sambuc virtual int_type overflow (int_type __c = traits_type::eof()); 2204684ddb6SLionel Sambuc virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n); 2214684ddb6SLionel Sambuc virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, 2224684ddb6SLionel Sambuc ios_base::openmode __wch = ios_base::in | ios_base::out); 2234684ddb6SLionel Sambuc virtual pos_type seekpos(pos_type __sp, 2244684ddb6SLionel Sambuc ios_base::openmode __wch = ios_base::in | ios_base::out); 2254684ddb6SLionel Sambuc virtual int sync(); 2264684ddb6SLionel Sambuc virtual void imbue(const locale& __loc); 2274684ddb6SLionel Sambuc 2284684ddb6SLionel Sambucprivate: 2294684ddb6SLionel Sambuc char* __extbuf_; 2304684ddb6SLionel Sambuc const char* __extbufnext_; 2314684ddb6SLionel Sambuc const char* __extbufend_; 2324684ddb6SLionel Sambuc char __extbuf_min_[8]; 2334684ddb6SLionel Sambuc size_t __ebs_; 2344684ddb6SLionel Sambuc char_type* __intbuf_; 2354684ddb6SLionel Sambuc size_t __ibs_; 2364684ddb6SLionel Sambuc FILE* __file_; 2374684ddb6SLionel Sambuc const codecvt<char_type, char, state_type>* __cv_; 2384684ddb6SLionel Sambuc state_type __st_; 2394684ddb6SLionel Sambuc state_type __st_last_; 2404684ddb6SLionel Sambuc ios_base::openmode __om_; 2414684ddb6SLionel Sambuc ios_base::openmode __cm_; 2424684ddb6SLionel Sambuc bool __owns_eb_; 2434684ddb6SLionel Sambuc bool __owns_ib_; 2444684ddb6SLionel Sambuc bool __always_noconv_; 2454684ddb6SLionel Sambuc 2464684ddb6SLionel Sambuc bool __read_mode(); 2474684ddb6SLionel Sambuc void __write_mode(); 2484684ddb6SLionel Sambuc}; 2494684ddb6SLionel Sambuc 2504684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 2514684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::basic_filebuf() 2524684ddb6SLionel Sambuc : __extbuf_(0), 2534684ddb6SLionel Sambuc __extbufnext_(0), 2544684ddb6SLionel Sambuc __extbufend_(0), 2554684ddb6SLionel Sambuc __ebs_(0), 2564684ddb6SLionel Sambuc __intbuf_(0), 2574684ddb6SLionel Sambuc __ibs_(0), 2584684ddb6SLionel Sambuc __file_(0), 2594684ddb6SLionel Sambuc __cv_(nullptr), 2604684ddb6SLionel Sambuc __st_(), 2614684ddb6SLionel Sambuc __st_last_(), 2624684ddb6SLionel Sambuc __om_(0), 2634684ddb6SLionel Sambuc __cm_(0), 2644684ddb6SLionel Sambuc __owns_eb_(false), 2654684ddb6SLionel Sambuc __owns_ib_(false), 2664684ddb6SLionel Sambuc __always_noconv_(false) 2674684ddb6SLionel Sambuc{ 2684684ddb6SLionel Sambuc if (has_facet<codecvt<char_type, char, state_type> >(this->getloc())) 2694684ddb6SLionel Sambuc { 2704684ddb6SLionel Sambuc __cv_ = &use_facet<codecvt<char_type, char, state_type> >(this->getloc()); 2714684ddb6SLionel Sambuc __always_noconv_ = __cv_->always_noconv(); 2724684ddb6SLionel Sambuc } 2734684ddb6SLionel Sambuc setbuf(0, 4096); 2744684ddb6SLionel Sambuc} 2754684ddb6SLionel Sambuc 2764684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2774684ddb6SLionel Sambuc 2784684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 2794684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) 2804684ddb6SLionel Sambuc : basic_streambuf<_CharT, _Traits>(__rhs) 2814684ddb6SLionel Sambuc{ 2824684ddb6SLionel Sambuc if (__rhs.__extbuf_ == __rhs.__extbuf_min_) 2834684ddb6SLionel Sambuc { 2844684ddb6SLionel Sambuc __extbuf_ = __extbuf_min_; 2854684ddb6SLionel Sambuc __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_); 2864684ddb6SLionel Sambuc __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_); 2874684ddb6SLionel Sambuc } 2884684ddb6SLionel Sambuc else 2894684ddb6SLionel Sambuc { 2904684ddb6SLionel Sambuc __extbuf_ = __rhs.__extbuf_; 2914684ddb6SLionel Sambuc __extbufnext_ = __rhs.__extbufnext_; 2924684ddb6SLionel Sambuc __extbufend_ = __rhs.__extbufend_; 2934684ddb6SLionel Sambuc } 2944684ddb6SLionel Sambuc __ebs_ = __rhs.__ebs_; 2954684ddb6SLionel Sambuc __intbuf_ = __rhs.__intbuf_; 2964684ddb6SLionel Sambuc __ibs_ = __rhs.__ibs_; 2974684ddb6SLionel Sambuc __file_ = __rhs.__file_; 2984684ddb6SLionel Sambuc __cv_ = __rhs.__cv_; 2994684ddb6SLionel Sambuc __st_ = __rhs.__st_; 3004684ddb6SLionel Sambuc __st_last_ = __rhs.__st_last_; 3014684ddb6SLionel Sambuc __om_ = __rhs.__om_; 3024684ddb6SLionel Sambuc __cm_ = __rhs.__cm_; 3034684ddb6SLionel Sambuc __owns_eb_ = __rhs.__owns_eb_; 3044684ddb6SLionel Sambuc __owns_ib_ = __rhs.__owns_ib_; 3054684ddb6SLionel Sambuc __always_noconv_ = __rhs.__always_noconv_; 3064684ddb6SLionel Sambuc if (__rhs.pbase()) 3074684ddb6SLionel Sambuc { 3084684ddb6SLionel Sambuc if (__rhs.pbase() == __rhs.__intbuf_) 3094684ddb6SLionel Sambuc this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase())); 3104684ddb6SLionel Sambuc else 3114684ddb6SLionel Sambuc this->setp((char_type*)__extbuf_, 3124684ddb6SLionel Sambuc (char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase())); 3134684ddb6SLionel Sambuc this->pbump(__rhs. pptr() - __rhs.pbase()); 3144684ddb6SLionel Sambuc } 3154684ddb6SLionel Sambuc else if (__rhs.eback()) 3164684ddb6SLionel Sambuc { 3174684ddb6SLionel Sambuc if (__rhs.eback() == __rhs.__intbuf_) 3184684ddb6SLionel Sambuc this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), 3194684ddb6SLionel Sambuc __intbuf_ + (__rhs.egptr() - __rhs.eback())); 3204684ddb6SLionel Sambuc else 3214684ddb6SLionel Sambuc this->setg((char_type*)__extbuf_, 3224684ddb6SLionel Sambuc (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()), 3234684ddb6SLionel Sambuc (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback())); 3244684ddb6SLionel Sambuc } 3254684ddb6SLionel Sambuc __rhs.__extbuf_ = 0; 3264684ddb6SLionel Sambuc __rhs.__extbufnext_ = 0; 3274684ddb6SLionel Sambuc __rhs.__extbufend_ = 0; 3284684ddb6SLionel Sambuc __rhs.__ebs_ = 0; 3294684ddb6SLionel Sambuc __rhs.__intbuf_ = 0; 3304684ddb6SLionel Sambuc __rhs.__ibs_ = 0; 3314684ddb6SLionel Sambuc __rhs.__file_ = 0; 3324684ddb6SLionel Sambuc __rhs.__st_ = state_type(); 3334684ddb6SLionel Sambuc __rhs.__st_last_ = state_type(); 3344684ddb6SLionel Sambuc __rhs.__om_ = 0; 3354684ddb6SLionel Sambuc __rhs.__cm_ = 0; 3364684ddb6SLionel Sambuc __rhs.__owns_eb_ = false; 3374684ddb6SLionel Sambuc __rhs.__owns_ib_ = false; 3384684ddb6SLionel Sambuc __rhs.setg(0, 0, 0); 3394684ddb6SLionel Sambuc __rhs.setp(0, 0); 3404684ddb6SLionel Sambuc} 3414684ddb6SLionel Sambuc 3424684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 3434684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 3444684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>& 3454684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) 3464684ddb6SLionel Sambuc{ 3474684ddb6SLionel Sambuc close(); 3484684ddb6SLionel Sambuc swap(__rhs); 3494684ddb6SLionel Sambuc return *this; 3504684ddb6SLionel Sambuc} 3514684ddb6SLionel Sambuc 3524684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3534684ddb6SLionel Sambuc 3544684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 3554684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::~basic_filebuf() 3564684ddb6SLionel Sambuc{ 3574684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 3584684ddb6SLionel Sambuc try 3594684ddb6SLionel Sambuc { 3604684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 3614684ddb6SLionel Sambuc close(); 3624684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 3634684ddb6SLionel Sambuc } 3644684ddb6SLionel Sambuc catch (...) 3654684ddb6SLionel Sambuc { 3664684ddb6SLionel Sambuc } 3674684ddb6SLionel Sambuc#endif // _LIBCPP_NO_EXCEPTIONS 3684684ddb6SLionel Sambuc if (__owns_eb_) 3694684ddb6SLionel Sambuc delete [] __extbuf_; 3704684ddb6SLionel Sambuc if (__owns_ib_) 3714684ddb6SLionel Sambuc delete [] __intbuf_; 3724684ddb6SLionel Sambuc} 3734684ddb6SLionel Sambuc 3744684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 3754684ddb6SLionel Sambucvoid 3764684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) 3774684ddb6SLionel Sambuc{ 3784684ddb6SLionel Sambuc basic_streambuf<char_type, traits_type>::swap(__rhs); 3794684ddb6SLionel Sambuc if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) 3804684ddb6SLionel Sambuc { 3814684ddb6SLionel Sambuc _VSTD::swap(__extbuf_, __rhs.__extbuf_); 3824684ddb6SLionel Sambuc _VSTD::swap(__extbufnext_, __rhs.__extbufnext_); 3834684ddb6SLionel Sambuc _VSTD::swap(__extbufend_, __rhs.__extbufend_); 3844684ddb6SLionel Sambuc } 3854684ddb6SLionel Sambuc else 3864684ddb6SLionel Sambuc { 3874684ddb6SLionel Sambuc ptrdiff_t __ln = __extbufnext_ - __extbuf_; 3884684ddb6SLionel Sambuc ptrdiff_t __le = __extbufend_ - __extbuf_; 3894684ddb6SLionel Sambuc ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_; 3904684ddb6SLionel Sambuc ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_; 3914684ddb6SLionel Sambuc if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) 3924684ddb6SLionel Sambuc { 3934684ddb6SLionel Sambuc __extbuf_ = __rhs.__extbuf_; 3944684ddb6SLionel Sambuc __rhs.__extbuf_ = __rhs.__extbuf_min_; 3954684ddb6SLionel Sambuc } 3964684ddb6SLionel Sambuc else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) 3974684ddb6SLionel Sambuc { 3984684ddb6SLionel Sambuc __rhs.__extbuf_ = __extbuf_; 3994684ddb6SLionel Sambuc __extbuf_ = __extbuf_min_; 4004684ddb6SLionel Sambuc } 4014684ddb6SLionel Sambuc __extbufnext_ = __extbuf_ + __rn; 4024684ddb6SLionel Sambuc __extbufend_ = __extbuf_ + __re; 4034684ddb6SLionel Sambuc __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln; 4044684ddb6SLionel Sambuc __rhs.__extbufend_ = __rhs.__extbuf_ + __le; 4054684ddb6SLionel Sambuc } 4064684ddb6SLionel Sambuc _VSTD::swap(__ebs_, __rhs.__ebs_); 4074684ddb6SLionel Sambuc _VSTD::swap(__intbuf_, __rhs.__intbuf_); 4084684ddb6SLionel Sambuc _VSTD::swap(__ibs_, __rhs.__ibs_); 4094684ddb6SLionel Sambuc _VSTD::swap(__file_, __rhs.__file_); 4104684ddb6SLionel Sambuc _VSTD::swap(__cv_, __rhs.__cv_); 4114684ddb6SLionel Sambuc _VSTD::swap(__st_, __rhs.__st_); 4124684ddb6SLionel Sambuc _VSTD::swap(__st_last_, __rhs.__st_last_); 4134684ddb6SLionel Sambuc _VSTD::swap(__om_, __rhs.__om_); 4144684ddb6SLionel Sambuc _VSTD::swap(__cm_, __rhs.__cm_); 4154684ddb6SLionel Sambuc _VSTD::swap(__owns_eb_, __rhs.__owns_eb_); 4164684ddb6SLionel Sambuc _VSTD::swap(__owns_ib_, __rhs.__owns_ib_); 4174684ddb6SLionel Sambuc _VSTD::swap(__always_noconv_, __rhs.__always_noconv_); 4184684ddb6SLionel Sambuc if (this->eback() == (char_type*)__rhs.__extbuf_min_) 4194684ddb6SLionel Sambuc { 4204684ddb6SLionel Sambuc ptrdiff_t __n = this->gptr() - this->eback(); 4214684ddb6SLionel Sambuc ptrdiff_t __e = this->egptr() - this->eback(); 4224684ddb6SLionel Sambuc this->setg((char_type*)__extbuf_min_, 4234684ddb6SLionel Sambuc (char_type*)__extbuf_min_ + __n, 4244684ddb6SLionel Sambuc (char_type*)__extbuf_min_ + __e); 4254684ddb6SLionel Sambuc } 4264684ddb6SLionel Sambuc else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) 4274684ddb6SLionel Sambuc { 4284684ddb6SLionel Sambuc ptrdiff_t __n = this->pptr() - this->pbase(); 4294684ddb6SLionel Sambuc ptrdiff_t __e = this->epptr() - this->pbase(); 4304684ddb6SLionel Sambuc this->setp((char_type*)__extbuf_min_, 4314684ddb6SLionel Sambuc (char_type*)__extbuf_min_ + __e); 4324684ddb6SLionel Sambuc this->pbump(__n); 4334684ddb6SLionel Sambuc } 4344684ddb6SLionel Sambuc if (__rhs.eback() == (char_type*)__extbuf_min_) 4354684ddb6SLionel Sambuc { 4364684ddb6SLionel Sambuc ptrdiff_t __n = __rhs.gptr() - __rhs.eback(); 4374684ddb6SLionel Sambuc ptrdiff_t __e = __rhs.egptr() - __rhs.eback(); 4384684ddb6SLionel Sambuc __rhs.setg((char_type*)__rhs.__extbuf_min_, 4394684ddb6SLionel Sambuc (char_type*)__rhs.__extbuf_min_ + __n, 4404684ddb6SLionel Sambuc (char_type*)__rhs.__extbuf_min_ + __e); 4414684ddb6SLionel Sambuc } 4424684ddb6SLionel Sambuc else if (__rhs.pbase() == (char_type*)__extbuf_min_) 4434684ddb6SLionel Sambuc { 4444684ddb6SLionel Sambuc ptrdiff_t __n = __rhs.pptr() - __rhs.pbase(); 4454684ddb6SLionel Sambuc ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); 4464684ddb6SLionel Sambuc __rhs.setp((char_type*)__rhs.__extbuf_min_, 4474684ddb6SLionel Sambuc (char_type*)__rhs.__extbuf_min_ + __e); 4484684ddb6SLionel Sambuc __rhs.pbump(__n); 4494684ddb6SLionel Sambuc } 4504684ddb6SLionel Sambuc} 4514684ddb6SLionel Sambuc 4524684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 4534684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4544684ddb6SLionel Sambucvoid 4554684ddb6SLionel Sambucswap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) 4564684ddb6SLionel Sambuc{ 4574684ddb6SLionel Sambuc __x.swap(__y); 4584684ddb6SLionel Sambuc} 4594684ddb6SLionel Sambuc 4604684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 4614684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 4624684ddb6SLionel Sambucbool 4634684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::is_open() const 4644684ddb6SLionel Sambuc{ 4654684ddb6SLionel Sambuc return __file_ != 0; 4664684ddb6SLionel Sambuc} 4674684ddb6SLionel Sambuc 468*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 4694684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 4704684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>* 4714684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) 4724684ddb6SLionel Sambuc{ 4734684ddb6SLionel Sambuc basic_filebuf<_CharT, _Traits>* __rt = 0; 4744684ddb6SLionel Sambuc if (__file_ == 0) 4754684ddb6SLionel Sambuc { 4764684ddb6SLionel Sambuc __rt = this; 4774684ddb6SLionel Sambuc const char* __mdstr; 4784684ddb6SLionel Sambuc switch (__mode & ~ios_base::ate) 4794684ddb6SLionel Sambuc { 4804684ddb6SLionel Sambuc case ios_base::out: 4814684ddb6SLionel Sambuc case ios_base::out | ios_base::trunc: 4824684ddb6SLionel Sambuc __mdstr = "w"; 4834684ddb6SLionel Sambuc break; 4844684ddb6SLionel Sambuc case ios_base::out | ios_base::app: 4854684ddb6SLionel Sambuc case ios_base::app: 4864684ddb6SLionel Sambuc __mdstr = "a"; 4874684ddb6SLionel Sambuc break; 4884684ddb6SLionel Sambuc case ios_base::in: 4894684ddb6SLionel Sambuc __mdstr = "r"; 4904684ddb6SLionel Sambuc break; 4914684ddb6SLionel Sambuc case ios_base::in | ios_base::out: 4924684ddb6SLionel Sambuc __mdstr = "r+"; 4934684ddb6SLionel Sambuc break; 4944684ddb6SLionel Sambuc case ios_base::in | ios_base::out | ios_base::trunc: 4954684ddb6SLionel Sambuc __mdstr = "w+"; 4964684ddb6SLionel Sambuc break; 4974684ddb6SLionel Sambuc case ios_base::in | ios_base::out | ios_base::app: 4984684ddb6SLionel Sambuc case ios_base::in | ios_base::app: 4994684ddb6SLionel Sambuc __mdstr = "a+"; 5004684ddb6SLionel Sambuc break; 5014684ddb6SLionel Sambuc case ios_base::out | ios_base::binary: 5024684ddb6SLionel Sambuc case ios_base::out | ios_base::trunc | ios_base::binary: 5034684ddb6SLionel Sambuc __mdstr = "wb"; 5044684ddb6SLionel Sambuc break; 5054684ddb6SLionel Sambuc case ios_base::out | ios_base::app | ios_base::binary: 5064684ddb6SLionel Sambuc case ios_base::app | ios_base::binary: 5074684ddb6SLionel Sambuc __mdstr = "ab"; 5084684ddb6SLionel Sambuc break; 5094684ddb6SLionel Sambuc case ios_base::in | ios_base::binary: 5104684ddb6SLionel Sambuc __mdstr = "rb"; 5114684ddb6SLionel Sambuc break; 5124684ddb6SLionel Sambuc case ios_base::in | ios_base::out | ios_base::binary: 5134684ddb6SLionel Sambuc __mdstr = "r+b"; 5144684ddb6SLionel Sambuc break; 5154684ddb6SLionel Sambuc case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: 5164684ddb6SLionel Sambuc __mdstr = "w+b"; 5174684ddb6SLionel Sambuc break; 5184684ddb6SLionel Sambuc case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: 5194684ddb6SLionel Sambuc case ios_base::in | ios_base::app | ios_base::binary: 5204684ddb6SLionel Sambuc __mdstr = "a+b"; 5214684ddb6SLionel Sambuc break; 5224684ddb6SLionel Sambuc default: 5234684ddb6SLionel Sambuc __rt = 0; 5244684ddb6SLionel Sambuc break; 5254684ddb6SLionel Sambuc } 5264684ddb6SLionel Sambuc if (__rt) 5274684ddb6SLionel Sambuc { 5284684ddb6SLionel Sambuc __file_ = fopen(__s, __mdstr); 5294684ddb6SLionel Sambuc if (__file_) 5304684ddb6SLionel Sambuc { 5314684ddb6SLionel Sambuc __om_ = __mode; 5324684ddb6SLionel Sambuc if (__mode & ios_base::ate) 5334684ddb6SLionel Sambuc { 5344684ddb6SLionel Sambuc if (fseek(__file_, 0, SEEK_END)) 5354684ddb6SLionel Sambuc { 5364684ddb6SLionel Sambuc fclose(__file_); 5374684ddb6SLionel Sambuc __file_ = 0; 5384684ddb6SLionel Sambuc __rt = 0; 5394684ddb6SLionel Sambuc } 5404684ddb6SLionel Sambuc } 5414684ddb6SLionel Sambuc } 5424684ddb6SLionel Sambuc else 5434684ddb6SLionel Sambuc __rt = 0; 5444684ddb6SLionel Sambuc } 5454684ddb6SLionel Sambuc } 5464684ddb6SLionel Sambuc return __rt; 5474684ddb6SLionel Sambuc} 5484684ddb6SLionel Sambuc 5494684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 5504684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 5514684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>* 5524684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) 5534684ddb6SLionel Sambuc{ 5544684ddb6SLionel Sambuc return open(__s.c_str(), __mode); 5554684ddb6SLionel Sambuc} 556*0a6a1f1dSLionel Sambuc#endif 5574684ddb6SLionel Sambuc 5584684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 5594684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>* 5604684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::close() 5614684ddb6SLionel Sambuc{ 5624684ddb6SLionel Sambuc basic_filebuf<_CharT, _Traits>* __rt = 0; 5634684ddb6SLionel Sambuc if (__file_) 5644684ddb6SLionel Sambuc { 5654684ddb6SLionel Sambuc __rt = this; 5664684ddb6SLionel Sambuc unique_ptr<FILE, int(*)(FILE*)> __h(__file_, fclose); 5674684ddb6SLionel Sambuc if (sync()) 5684684ddb6SLionel Sambuc __rt = 0; 5694684ddb6SLionel Sambuc if (fclose(__h.release()) == 0) 5704684ddb6SLionel Sambuc __file_ = 0; 5714684ddb6SLionel Sambuc else 5724684ddb6SLionel Sambuc __rt = 0; 5734684ddb6SLionel Sambuc } 5744684ddb6SLionel Sambuc return __rt; 5754684ddb6SLionel Sambuc} 5764684ddb6SLionel Sambuc 5774684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 5784684ddb6SLionel Sambuctypename basic_filebuf<_CharT, _Traits>::int_type 5794684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::underflow() 5804684ddb6SLionel Sambuc{ 5814684ddb6SLionel Sambuc if (__file_ == 0) 5824684ddb6SLionel Sambuc return traits_type::eof(); 5834684ddb6SLionel Sambuc bool __initial = __read_mode(); 5844684ddb6SLionel Sambuc char_type __1buf; 5854684ddb6SLionel Sambuc if (this->gptr() == 0) 5864684ddb6SLionel Sambuc this->setg(&__1buf, &__1buf+1, &__1buf+1); 5874684ddb6SLionel Sambuc const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4); 5884684ddb6SLionel Sambuc int_type __c = traits_type::eof(); 5894684ddb6SLionel Sambuc if (this->gptr() == this->egptr()) 5904684ddb6SLionel Sambuc { 5914684ddb6SLionel Sambuc memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); 5924684ddb6SLionel Sambuc if (__always_noconv_) 5934684ddb6SLionel Sambuc { 5944684ddb6SLionel Sambuc size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz); 5954684ddb6SLionel Sambuc __nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_); 5964684ddb6SLionel Sambuc if (__nmemb != 0) 5974684ddb6SLionel Sambuc { 5984684ddb6SLionel Sambuc this->setg(this->eback(), 5994684ddb6SLionel Sambuc this->eback() + __unget_sz, 6004684ddb6SLionel Sambuc this->eback() + __unget_sz + __nmemb); 6014684ddb6SLionel Sambuc __c = traits_type::to_int_type(*this->gptr()); 6024684ddb6SLionel Sambuc } 6034684ddb6SLionel Sambuc } 6044684ddb6SLionel Sambuc else 6054684ddb6SLionel Sambuc { 6064684ddb6SLionel Sambuc memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); 6074684ddb6SLionel Sambuc __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); 6084684ddb6SLionel Sambuc __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); 6094684ddb6SLionel Sambuc size_t __nmemb = _VSTD::min(static_cast<size_t>(__ibs_ - __unget_sz), 6104684ddb6SLionel Sambuc static_cast<size_t>(__extbufend_ - __extbufnext_)); 6114684ddb6SLionel Sambuc codecvt_base::result __r; 6124684ddb6SLionel Sambuc __st_last_ = __st_; 6134684ddb6SLionel Sambuc size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_); 6144684ddb6SLionel Sambuc if (__nr != 0) 6154684ddb6SLionel Sambuc { 6164684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 6174684ddb6SLionel Sambuc if (!__cv_) 6184684ddb6SLionel Sambuc throw bad_cast(); 6194684ddb6SLionel Sambuc#endif 6204684ddb6SLionel Sambuc __extbufend_ = __extbufnext_ + __nr; 6214684ddb6SLionel Sambuc char_type* __inext; 6224684ddb6SLionel Sambuc __r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_, 6234684ddb6SLionel Sambuc this->eback() + __unget_sz, 6244684ddb6SLionel Sambuc this->eback() + __ibs_, __inext); 6254684ddb6SLionel Sambuc if (__r == codecvt_base::noconv) 6264684ddb6SLionel Sambuc { 6274684ddb6SLionel Sambuc this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_); 6284684ddb6SLionel Sambuc __c = traits_type::to_int_type(*this->gptr()); 6294684ddb6SLionel Sambuc } 6304684ddb6SLionel Sambuc else if (__inext != this->eback() + __unget_sz) 6314684ddb6SLionel Sambuc { 6324684ddb6SLionel Sambuc this->setg(this->eback(), this->eback() + __unget_sz, __inext); 6334684ddb6SLionel Sambuc __c = traits_type::to_int_type(*this->gptr()); 6344684ddb6SLionel Sambuc } 6354684ddb6SLionel Sambuc } 6364684ddb6SLionel Sambuc } 6374684ddb6SLionel Sambuc } 6384684ddb6SLionel Sambuc else 6394684ddb6SLionel Sambuc __c = traits_type::to_int_type(*this->gptr()); 6404684ddb6SLionel Sambuc if (this->eback() == &__1buf) 6414684ddb6SLionel Sambuc this->setg(0, 0, 0); 6424684ddb6SLionel Sambuc return __c; 6434684ddb6SLionel Sambuc} 6444684ddb6SLionel Sambuc 6454684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 6464684ddb6SLionel Sambuctypename basic_filebuf<_CharT, _Traits>::int_type 6474684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) 6484684ddb6SLionel Sambuc{ 6494684ddb6SLionel Sambuc if (__file_ && this->eback() < this->gptr()) 6504684ddb6SLionel Sambuc { 6514684ddb6SLionel Sambuc if (traits_type::eq_int_type(__c, traits_type::eof())) 6524684ddb6SLionel Sambuc { 6534684ddb6SLionel Sambuc this->gbump(-1); 6544684ddb6SLionel Sambuc return traits_type::not_eof(__c); 6554684ddb6SLionel Sambuc } 6564684ddb6SLionel Sambuc if ((__om_ & ios_base::out) || 6574684ddb6SLionel Sambuc traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) 6584684ddb6SLionel Sambuc { 6594684ddb6SLionel Sambuc this->gbump(-1); 6604684ddb6SLionel Sambuc *this->gptr() = traits_type::to_char_type(__c); 6614684ddb6SLionel Sambuc return __c; 6624684ddb6SLionel Sambuc } 6634684ddb6SLionel Sambuc } 6644684ddb6SLionel Sambuc return traits_type::eof(); 6654684ddb6SLionel Sambuc} 6664684ddb6SLionel Sambuc 6674684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 6684684ddb6SLionel Sambuctypename basic_filebuf<_CharT, _Traits>::int_type 6694684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::overflow(int_type __c) 6704684ddb6SLionel Sambuc{ 6714684ddb6SLionel Sambuc if (__file_ == 0) 6724684ddb6SLionel Sambuc return traits_type::eof(); 6734684ddb6SLionel Sambuc __write_mode(); 6744684ddb6SLionel Sambuc char_type __1buf; 6754684ddb6SLionel Sambuc char_type* __pb_save = this->pbase(); 6764684ddb6SLionel Sambuc char_type* __epb_save = this->epptr(); 6774684ddb6SLionel Sambuc if (!traits_type::eq_int_type(__c, traits_type::eof())) 6784684ddb6SLionel Sambuc { 6794684ddb6SLionel Sambuc if (this->pptr() == 0) 6804684ddb6SLionel Sambuc this->setp(&__1buf, &__1buf+1); 6814684ddb6SLionel Sambuc *this->pptr() = traits_type::to_char_type(__c); 6824684ddb6SLionel Sambuc this->pbump(1); 6834684ddb6SLionel Sambuc } 6844684ddb6SLionel Sambuc if (this->pptr() != this->pbase()) 6854684ddb6SLionel Sambuc { 6864684ddb6SLionel Sambuc if (__always_noconv_) 6874684ddb6SLionel Sambuc { 6884684ddb6SLionel Sambuc size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); 6894684ddb6SLionel Sambuc if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb) 6904684ddb6SLionel Sambuc return traits_type::eof(); 6914684ddb6SLionel Sambuc } 6924684ddb6SLionel Sambuc else 6934684ddb6SLionel Sambuc { 6944684ddb6SLionel Sambuc char* __extbe = __extbuf_; 6954684ddb6SLionel Sambuc codecvt_base::result __r; 6964684ddb6SLionel Sambuc do 6974684ddb6SLionel Sambuc { 6984684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 6994684ddb6SLionel Sambuc if (!__cv_) 7004684ddb6SLionel Sambuc throw bad_cast(); 7014684ddb6SLionel Sambuc#endif 7024684ddb6SLionel Sambuc const char_type* __e; 7034684ddb6SLionel Sambuc __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, 7044684ddb6SLionel Sambuc __extbuf_, __extbuf_ + __ebs_, __extbe); 7054684ddb6SLionel Sambuc if (__e == this->pbase()) 7064684ddb6SLionel Sambuc return traits_type::eof(); 7074684ddb6SLionel Sambuc if (__r == codecvt_base::noconv) 7084684ddb6SLionel Sambuc { 7094684ddb6SLionel Sambuc size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); 7104684ddb6SLionel Sambuc if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb) 7114684ddb6SLionel Sambuc return traits_type::eof(); 7124684ddb6SLionel Sambuc } 7134684ddb6SLionel Sambuc else if (__r == codecvt_base::ok || __r == codecvt_base::partial) 7144684ddb6SLionel Sambuc { 7154684ddb6SLionel Sambuc size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); 7164684ddb6SLionel Sambuc if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) 7174684ddb6SLionel Sambuc return traits_type::eof(); 7184684ddb6SLionel Sambuc if (__r == codecvt_base::partial) 7194684ddb6SLionel Sambuc { 7204684ddb6SLionel Sambuc this->setp((char_type*)__e, this->pptr()); 7214684ddb6SLionel Sambuc this->pbump(this->epptr() - this->pbase()); 7224684ddb6SLionel Sambuc } 7234684ddb6SLionel Sambuc } 7244684ddb6SLionel Sambuc else 7254684ddb6SLionel Sambuc return traits_type::eof(); 7264684ddb6SLionel Sambuc } while (__r == codecvt_base::partial); 7274684ddb6SLionel Sambuc } 7284684ddb6SLionel Sambuc this->setp(__pb_save, __epb_save); 7294684ddb6SLionel Sambuc } 7304684ddb6SLionel Sambuc return traits_type::not_eof(__c); 7314684ddb6SLionel Sambuc} 7324684ddb6SLionel Sambuc 7334684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 7344684ddb6SLionel Sambucbasic_streambuf<_CharT, _Traits>* 7354684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) 7364684ddb6SLionel Sambuc{ 7374684ddb6SLionel Sambuc this->setg(0, 0, 0); 7384684ddb6SLionel Sambuc this->setp(0, 0); 7394684ddb6SLionel Sambuc if (__owns_eb_) 7404684ddb6SLionel Sambuc delete [] __extbuf_; 7414684ddb6SLionel Sambuc if (__owns_ib_) 7424684ddb6SLionel Sambuc delete [] __intbuf_; 7434684ddb6SLionel Sambuc __ebs_ = __n; 7444684ddb6SLionel Sambuc if (__ebs_ > sizeof(__extbuf_min_)) 7454684ddb6SLionel Sambuc { 7464684ddb6SLionel Sambuc if (__always_noconv_ && __s) 7474684ddb6SLionel Sambuc { 7484684ddb6SLionel Sambuc __extbuf_ = (char*)__s; 7494684ddb6SLionel Sambuc __owns_eb_ = false; 7504684ddb6SLionel Sambuc } 7514684ddb6SLionel Sambuc else 7524684ddb6SLionel Sambuc { 7534684ddb6SLionel Sambuc __extbuf_ = new char[__ebs_]; 7544684ddb6SLionel Sambuc __owns_eb_ = true; 7554684ddb6SLionel Sambuc } 7564684ddb6SLionel Sambuc } 7574684ddb6SLionel Sambuc else 7584684ddb6SLionel Sambuc { 7594684ddb6SLionel Sambuc __extbuf_ = __extbuf_min_; 7604684ddb6SLionel Sambuc __ebs_ = sizeof(__extbuf_min_); 7614684ddb6SLionel Sambuc __owns_eb_ = false; 7624684ddb6SLionel Sambuc } 7634684ddb6SLionel Sambuc if (!__always_noconv_) 7644684ddb6SLionel Sambuc { 7654684ddb6SLionel Sambuc __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); 7664684ddb6SLionel Sambuc if (__s && __ibs_ >= sizeof(__extbuf_min_)) 7674684ddb6SLionel Sambuc { 7684684ddb6SLionel Sambuc __intbuf_ = __s; 7694684ddb6SLionel Sambuc __owns_ib_ = false; 7704684ddb6SLionel Sambuc } 7714684ddb6SLionel Sambuc else 7724684ddb6SLionel Sambuc { 7734684ddb6SLionel Sambuc __intbuf_ = new char_type[__ibs_]; 7744684ddb6SLionel Sambuc __owns_ib_ = true; 7754684ddb6SLionel Sambuc } 7764684ddb6SLionel Sambuc } 7774684ddb6SLionel Sambuc else 7784684ddb6SLionel Sambuc { 7794684ddb6SLionel Sambuc __ibs_ = 0; 7804684ddb6SLionel Sambuc __intbuf_ = 0; 7814684ddb6SLionel Sambuc __owns_ib_ = false; 7824684ddb6SLionel Sambuc } 7834684ddb6SLionel Sambuc return this; 7844684ddb6SLionel Sambuc} 7854684ddb6SLionel Sambuc 7864684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 7874684ddb6SLionel Sambuctypename basic_filebuf<_CharT, _Traits>::pos_type 7884684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, 7894684ddb6SLionel Sambuc ios_base::openmode) 7904684ddb6SLionel Sambuc{ 7914684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 7924684ddb6SLionel Sambuc if (!__cv_) 7934684ddb6SLionel Sambuc throw bad_cast(); 7944684ddb6SLionel Sambuc#endif 7954684ddb6SLionel Sambuc int __width = __cv_->encoding(); 7964684ddb6SLionel Sambuc if (__file_ == 0 || (__width <= 0 && __off != 0) || sync()) 7974684ddb6SLionel Sambuc return pos_type(off_type(-1)); 7984684ddb6SLionel Sambuc // __width > 0 || __off == 0 7994684ddb6SLionel Sambuc int __whence; 8004684ddb6SLionel Sambuc switch (__way) 8014684ddb6SLionel Sambuc { 8024684ddb6SLionel Sambuc case ios_base::beg: 8034684ddb6SLionel Sambuc __whence = SEEK_SET; 8044684ddb6SLionel Sambuc break; 8054684ddb6SLionel Sambuc case ios_base::cur: 8064684ddb6SLionel Sambuc __whence = SEEK_CUR; 8074684ddb6SLionel Sambuc break; 8084684ddb6SLionel Sambuc case ios_base::end: 8094684ddb6SLionel Sambuc __whence = SEEK_END; 8104684ddb6SLionel Sambuc break; 8114684ddb6SLionel Sambuc default: 8124684ddb6SLionel Sambuc return pos_type(off_type(-1)); 8134684ddb6SLionel Sambuc } 814*0a6a1f1dSLionel Sambuc#if defined(_WIN32) || defined(_NEWLIB_VERSION) 8154684ddb6SLionel Sambuc if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) 8164684ddb6SLionel Sambuc return pos_type(off_type(-1)); 8174684ddb6SLionel Sambuc pos_type __r = ftell(__file_); 8184684ddb6SLionel Sambuc#else 8194684ddb6SLionel Sambuc if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) 8204684ddb6SLionel Sambuc return pos_type(off_type(-1)); 8214684ddb6SLionel Sambuc pos_type __r = ftello(__file_); 8224684ddb6SLionel Sambuc#endif 8234684ddb6SLionel Sambuc __r.state(__st_); 8244684ddb6SLionel Sambuc return __r; 8254684ddb6SLionel Sambuc} 8264684ddb6SLionel Sambuc 8274684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 8284684ddb6SLionel Sambuctypename basic_filebuf<_CharT, _Traits>::pos_type 8294684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) 8304684ddb6SLionel Sambuc{ 8314684ddb6SLionel Sambuc if (__file_ == 0 || sync()) 8324684ddb6SLionel Sambuc return pos_type(off_type(-1)); 833*0a6a1f1dSLionel Sambuc#if defined(_WIN32) || defined(_NEWLIB_VERSION) 8344684ddb6SLionel Sambuc if (fseek(__file_, __sp, SEEK_SET)) 8354684ddb6SLionel Sambuc return pos_type(off_type(-1)); 8364684ddb6SLionel Sambuc#else 8374684ddb6SLionel Sambuc if (fseeko(__file_, __sp, SEEK_SET)) 8384684ddb6SLionel Sambuc return pos_type(off_type(-1)); 8394684ddb6SLionel Sambuc#endif 8404684ddb6SLionel Sambuc __st_ = __sp.state(); 8414684ddb6SLionel Sambuc return __sp; 8424684ddb6SLionel Sambuc} 8434684ddb6SLionel Sambuc 8444684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 8454684ddb6SLionel Sambucint 8464684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::sync() 8474684ddb6SLionel Sambuc{ 8484684ddb6SLionel Sambuc if (__file_ == 0) 8494684ddb6SLionel Sambuc return 0; 8504684ddb6SLionel Sambuc#ifndef _LIBCPP_NO_EXCEPTIONS 8514684ddb6SLionel Sambuc if (!__cv_) 8524684ddb6SLionel Sambuc throw bad_cast(); 8534684ddb6SLionel Sambuc#endif 8544684ddb6SLionel Sambuc if (__cm_ & ios_base::out) 8554684ddb6SLionel Sambuc { 8564684ddb6SLionel Sambuc if (this->pptr() != this->pbase()) 8574684ddb6SLionel Sambuc if (overflow() == traits_type::eof()) 8584684ddb6SLionel Sambuc return -1; 8594684ddb6SLionel Sambuc codecvt_base::result __r; 8604684ddb6SLionel Sambuc do 8614684ddb6SLionel Sambuc { 8624684ddb6SLionel Sambuc char* __extbe; 8634684ddb6SLionel Sambuc __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); 8644684ddb6SLionel Sambuc size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); 8654684ddb6SLionel Sambuc if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) 8664684ddb6SLionel Sambuc return -1; 8674684ddb6SLionel Sambuc } while (__r == codecvt_base::partial); 8684684ddb6SLionel Sambuc if (__r == codecvt_base::error) 8694684ddb6SLionel Sambuc return -1; 8704684ddb6SLionel Sambuc if (fflush(__file_)) 8714684ddb6SLionel Sambuc return -1; 8724684ddb6SLionel Sambuc } 8734684ddb6SLionel Sambuc else if (__cm_ & ios_base::in) 8744684ddb6SLionel Sambuc { 8754684ddb6SLionel Sambuc off_type __c; 8764684ddb6SLionel Sambuc state_type __state = __st_last_; 8774684ddb6SLionel Sambuc bool __update_st = false; 8784684ddb6SLionel Sambuc if (__always_noconv_) 8794684ddb6SLionel Sambuc __c = this->egptr() - this->gptr(); 8804684ddb6SLionel Sambuc else 8814684ddb6SLionel Sambuc { 8824684ddb6SLionel Sambuc int __width = __cv_->encoding(); 8834684ddb6SLionel Sambuc __c = __extbufend_ - __extbufnext_; 8844684ddb6SLionel Sambuc if (__width > 0) 8854684ddb6SLionel Sambuc __c += __width * (this->egptr() - this->gptr()); 8864684ddb6SLionel Sambuc else 8874684ddb6SLionel Sambuc { 8884684ddb6SLionel Sambuc if (this->gptr() != this->egptr()) 8894684ddb6SLionel Sambuc { 8904684ddb6SLionel Sambuc const int __off = __cv_->length(__state, __extbuf_, 8914684ddb6SLionel Sambuc __extbufnext_, 8924684ddb6SLionel Sambuc this->gptr() - this->eback()); 8934684ddb6SLionel Sambuc __c += __extbufnext_ - __extbuf_ - __off; 8944684ddb6SLionel Sambuc __update_st = true; 8954684ddb6SLionel Sambuc } 8964684ddb6SLionel Sambuc } 8974684ddb6SLionel Sambuc } 898*0a6a1f1dSLionel Sambuc#if defined(_WIN32) || defined(_NEWLIB_VERSION) 8994684ddb6SLionel Sambuc if (fseek(__file_, -__c, SEEK_CUR)) 9004684ddb6SLionel Sambuc return -1; 9014684ddb6SLionel Sambuc#else 9024684ddb6SLionel Sambuc if (fseeko(__file_, -__c, SEEK_CUR)) 9034684ddb6SLionel Sambuc return -1; 9044684ddb6SLionel Sambuc#endif 9054684ddb6SLionel Sambuc if (__update_st) 9064684ddb6SLionel Sambuc __st_ = __state; 9074684ddb6SLionel Sambuc __extbufnext_ = __extbufend_ = __extbuf_; 9084684ddb6SLionel Sambuc this->setg(0, 0, 0); 9094684ddb6SLionel Sambuc __cm_ = 0; 9104684ddb6SLionel Sambuc } 9114684ddb6SLionel Sambuc return 0; 9124684ddb6SLionel Sambuc} 9134684ddb6SLionel Sambuc 9144684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 9154684ddb6SLionel Sambucvoid 9164684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) 9174684ddb6SLionel Sambuc{ 9184684ddb6SLionel Sambuc sync(); 9194684ddb6SLionel Sambuc __cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc); 9204684ddb6SLionel Sambuc bool __old_anc = __always_noconv_; 9214684ddb6SLionel Sambuc __always_noconv_ = __cv_->always_noconv(); 9224684ddb6SLionel Sambuc if (__old_anc != __always_noconv_) 9234684ddb6SLionel Sambuc { 9244684ddb6SLionel Sambuc this->setg(0, 0, 0); 9254684ddb6SLionel Sambuc this->setp(0, 0); 9264684ddb6SLionel Sambuc // invariant, char_type is char, else we couldn't get here 9274684ddb6SLionel Sambuc if (__always_noconv_) // need to dump __intbuf_ 9284684ddb6SLionel Sambuc { 9294684ddb6SLionel Sambuc if (__owns_eb_) 9304684ddb6SLionel Sambuc delete [] __extbuf_; 9314684ddb6SLionel Sambuc __owns_eb_ = __owns_ib_; 9324684ddb6SLionel Sambuc __ebs_ = __ibs_; 9334684ddb6SLionel Sambuc __extbuf_ = (char*)__intbuf_; 9344684ddb6SLionel Sambuc __ibs_ = 0; 9354684ddb6SLionel Sambuc __intbuf_ = 0; 9364684ddb6SLionel Sambuc __owns_ib_ = false; 9374684ddb6SLionel Sambuc } 9384684ddb6SLionel Sambuc else // need to obtain an __intbuf_. 9394684ddb6SLionel Sambuc { // If __extbuf_ is user-supplied, use it, else new __intbuf_ 9404684ddb6SLionel Sambuc if (!__owns_eb_ && __extbuf_ != __extbuf_min_) 9414684ddb6SLionel Sambuc { 9424684ddb6SLionel Sambuc __ibs_ = __ebs_; 9434684ddb6SLionel Sambuc __intbuf_ = (char_type*)__extbuf_; 9444684ddb6SLionel Sambuc __owns_ib_ = false; 9454684ddb6SLionel Sambuc __extbuf_ = new char[__ebs_]; 9464684ddb6SLionel Sambuc __owns_eb_ = true; 9474684ddb6SLionel Sambuc } 9484684ddb6SLionel Sambuc else 9494684ddb6SLionel Sambuc { 9504684ddb6SLionel Sambuc __ibs_ = __ebs_; 9514684ddb6SLionel Sambuc __intbuf_ = new char_type[__ibs_]; 9524684ddb6SLionel Sambuc __owns_ib_ = true; 9534684ddb6SLionel Sambuc } 9544684ddb6SLionel Sambuc } 9554684ddb6SLionel Sambuc } 9564684ddb6SLionel Sambuc} 9574684ddb6SLionel Sambuc 9584684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 9594684ddb6SLionel Sambucbool 9604684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::__read_mode() 9614684ddb6SLionel Sambuc{ 9624684ddb6SLionel Sambuc if (!(__cm_ & ios_base::in)) 9634684ddb6SLionel Sambuc { 9644684ddb6SLionel Sambuc this->setp(0, 0); 9654684ddb6SLionel Sambuc if (__always_noconv_) 9664684ddb6SLionel Sambuc this->setg((char_type*)__extbuf_, 9674684ddb6SLionel Sambuc (char_type*)__extbuf_ + __ebs_, 9684684ddb6SLionel Sambuc (char_type*)__extbuf_ + __ebs_); 9694684ddb6SLionel Sambuc else 9704684ddb6SLionel Sambuc this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); 9714684ddb6SLionel Sambuc __cm_ = ios_base::in; 9724684ddb6SLionel Sambuc return true; 9734684ddb6SLionel Sambuc } 9744684ddb6SLionel Sambuc return false; 9754684ddb6SLionel Sambuc} 9764684ddb6SLionel Sambuc 9774684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 9784684ddb6SLionel Sambucvoid 9794684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>::__write_mode() 9804684ddb6SLionel Sambuc{ 9814684ddb6SLionel Sambuc if (!(__cm_ & ios_base::out)) 9824684ddb6SLionel Sambuc { 9834684ddb6SLionel Sambuc this->setg(0, 0, 0); 9844684ddb6SLionel Sambuc if (__ebs_ > sizeof(__extbuf_min_)) 9854684ddb6SLionel Sambuc { 9864684ddb6SLionel Sambuc if (__always_noconv_) 9874684ddb6SLionel Sambuc this->setp((char_type*)__extbuf_, 9884684ddb6SLionel Sambuc (char_type*)__extbuf_ + (__ebs_ - 1)); 9894684ddb6SLionel Sambuc else 9904684ddb6SLionel Sambuc this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); 9914684ddb6SLionel Sambuc } 9924684ddb6SLionel Sambuc else 9934684ddb6SLionel Sambuc this->setp(0, 0); 9944684ddb6SLionel Sambuc __cm_ = ios_base::out; 9954684ddb6SLionel Sambuc } 9964684ddb6SLionel Sambuc} 9974684ddb6SLionel Sambuc 9984684ddb6SLionel Sambuc// basic_ifstream 9994684ddb6SLionel Sambuc 10004684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10014684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY basic_ifstream 10024684ddb6SLionel Sambuc : public basic_istream<_CharT, _Traits> 10034684ddb6SLionel Sambuc{ 10044684ddb6SLionel Sambucpublic: 10054684ddb6SLionel Sambuc typedef _CharT char_type; 10064684ddb6SLionel Sambuc typedef _Traits traits_type; 10074684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 10084684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 10094684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 10104684ddb6SLionel Sambuc 10114684ddb6SLionel Sambuc basic_ifstream(); 1012*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 10134684ddb6SLionel Sambuc explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in); 10144684ddb6SLionel Sambuc explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); 1015*0a6a1f1dSLionel Sambuc#endif 10164684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10174684ddb6SLionel Sambuc basic_ifstream(basic_ifstream&& __rhs); 10184684ddb6SLionel Sambuc#endif 10194684ddb6SLionel Sambuc 10204684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10214684ddb6SLionel Sambuc basic_ifstream& operator=(basic_ifstream&& __rhs); 10224684ddb6SLionel Sambuc#endif 10234684ddb6SLionel Sambuc void swap(basic_ifstream& __rhs); 10244684ddb6SLionel Sambuc 10254684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type>* rdbuf() const; 10264684ddb6SLionel Sambuc bool is_open() const; 1027*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 10284684ddb6SLionel Sambuc void open(const char* __s, ios_base::openmode __mode = ios_base::in); 10294684ddb6SLionel Sambuc void open(const string& __s, ios_base::openmode __mode = ios_base::in); 1030*0a6a1f1dSLionel Sambuc#endif 10314684ddb6SLionel Sambuc void close(); 10324684ddb6SLionel Sambuc 10334684ddb6SLionel Sambucprivate: 10344684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type> __sb_; 10354684ddb6SLionel Sambuc}; 10364684ddb6SLionel Sambuc 10374684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10384684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10394684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::basic_ifstream() 10404684ddb6SLionel Sambuc : basic_istream<char_type, traits_type>(&__sb_) 10414684ddb6SLionel Sambuc{ 10424684ddb6SLionel Sambuc} 10434684ddb6SLionel Sambuc 1044*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 10454684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10464684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10474684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode) 10484684ddb6SLionel Sambuc : basic_istream<char_type, traits_type>(&__sb_) 10494684ddb6SLionel Sambuc{ 10504684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::in) == 0) 10514684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 10524684ddb6SLionel Sambuc} 10534684ddb6SLionel Sambuc 10544684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10554684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10564684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode) 10574684ddb6SLionel Sambuc : basic_istream<char_type, traits_type>(&__sb_) 10584684ddb6SLionel Sambuc{ 10594684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::in) == 0) 10604684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 10614684ddb6SLionel Sambuc} 1062*0a6a1f1dSLionel Sambuc#endif 10634684ddb6SLionel Sambuc 10644684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 10654684ddb6SLionel Sambuc 10664684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10674684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10684684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs) 10694684ddb6SLionel Sambuc : basic_istream<char_type, traits_type>(_VSTD::move(__rhs)), 10704684ddb6SLionel Sambuc __sb_(_VSTD::move(__rhs.__sb_)) 10714684ddb6SLionel Sambuc{ 10724684ddb6SLionel Sambuc this->set_rdbuf(&__sb_); 10734684ddb6SLionel Sambuc} 10744684ddb6SLionel Sambuc 10754684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10764684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10774684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>& 10784684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) 10794684ddb6SLionel Sambuc{ 10804684ddb6SLionel Sambuc basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 10814684ddb6SLionel Sambuc __sb_ = _VSTD::move(__rhs.__sb_); 10824684ddb6SLionel Sambuc return *this; 10834684ddb6SLionel Sambuc} 10844684ddb6SLionel Sambuc 10854684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 10864684ddb6SLionel Sambuc 10874684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10884684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10894684ddb6SLionel Sambucvoid 10904684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) 10914684ddb6SLionel Sambuc{ 10924684ddb6SLionel Sambuc basic_istream<char_type, traits_type>::swap(__rhs); 10934684ddb6SLionel Sambuc __sb_.swap(__rhs.__sb_); 10944684ddb6SLionel Sambuc} 10954684ddb6SLionel Sambuc 10964684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 10974684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 10984684ddb6SLionel Sambucvoid 10994684ddb6SLionel Sambucswap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) 11004684ddb6SLionel Sambuc{ 11014684ddb6SLionel Sambuc __x.swap(__y); 11024684ddb6SLionel Sambuc} 11034684ddb6SLionel Sambuc 11044684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11054684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 11064684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>* 11074684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::rdbuf() const 11084684ddb6SLionel Sambuc{ 11094684ddb6SLionel Sambuc return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); 11104684ddb6SLionel Sambuc} 11114684ddb6SLionel Sambuc 11124684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11134684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 11144684ddb6SLionel Sambucbool 11154684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::is_open() const 11164684ddb6SLionel Sambuc{ 11174684ddb6SLionel Sambuc return __sb_.is_open(); 11184684ddb6SLionel Sambuc} 11194684ddb6SLionel Sambuc 1120*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 11214684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11224684ddb6SLionel Sambucvoid 11234684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) 11244684ddb6SLionel Sambuc{ 11254684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::in)) 11264684ddb6SLionel Sambuc this->clear(); 11274684ddb6SLionel Sambuc else 11284684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 11294684ddb6SLionel Sambuc} 11304684ddb6SLionel Sambuc 11314684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11324684ddb6SLionel Sambucvoid 11334684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) 11344684ddb6SLionel Sambuc{ 11354684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::in)) 11364684ddb6SLionel Sambuc this->clear(); 11374684ddb6SLionel Sambuc else 11384684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 11394684ddb6SLionel Sambuc} 1140*0a6a1f1dSLionel Sambuc#endif 11414684ddb6SLionel Sambuc 11424684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11434684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 11444684ddb6SLionel Sambucvoid 11454684ddb6SLionel Sambucbasic_ifstream<_CharT, _Traits>::close() 11464684ddb6SLionel Sambuc{ 11474684ddb6SLionel Sambuc if (__sb_.close() == 0) 11484684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 11494684ddb6SLionel Sambuc} 11504684ddb6SLionel Sambuc 11514684ddb6SLionel Sambuc// basic_ofstream 11524684ddb6SLionel Sambuc 11534684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11544684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY basic_ofstream 11554684ddb6SLionel Sambuc : public basic_ostream<_CharT, _Traits> 11564684ddb6SLionel Sambuc{ 11574684ddb6SLionel Sambucpublic: 11584684ddb6SLionel Sambuc typedef _CharT char_type; 11594684ddb6SLionel Sambuc typedef _Traits traits_type; 11604684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 11614684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 11624684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 11634684ddb6SLionel Sambuc 11644684ddb6SLionel Sambuc basic_ofstream(); 11654684ddb6SLionel Sambuc explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); 11664684ddb6SLionel Sambuc explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); 11674684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 11684684ddb6SLionel Sambuc basic_ofstream(basic_ofstream&& __rhs); 11694684ddb6SLionel Sambuc#endif 11704684ddb6SLionel Sambuc 11714684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 11724684ddb6SLionel Sambuc basic_ofstream& operator=(basic_ofstream&& __rhs); 11734684ddb6SLionel Sambuc#endif 11744684ddb6SLionel Sambuc void swap(basic_ofstream& __rhs); 11754684ddb6SLionel Sambuc 11764684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type>* rdbuf() const; 11774684ddb6SLionel Sambuc bool is_open() const; 1178*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 11794684ddb6SLionel Sambuc void open(const char* __s, ios_base::openmode __mode = ios_base::out); 11804684ddb6SLionel Sambuc void open(const string& __s, ios_base::openmode __mode = ios_base::out); 1181*0a6a1f1dSLionel Sambuc#endif 11824684ddb6SLionel Sambuc void close(); 11834684ddb6SLionel Sambuc 11844684ddb6SLionel Sambucprivate: 11854684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type> __sb_; 11864684ddb6SLionel Sambuc}; 11874684ddb6SLionel Sambuc 11884684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11894684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 11904684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::basic_ofstream() 11914684ddb6SLionel Sambuc : basic_ostream<char_type, traits_type>(&__sb_) 11924684ddb6SLionel Sambuc{ 11934684ddb6SLionel Sambuc} 11944684ddb6SLionel Sambuc 1195*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 11964684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 11974684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 11984684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode) 11994684ddb6SLionel Sambuc : basic_ostream<char_type, traits_type>(&__sb_) 12004684ddb6SLionel Sambuc{ 12014684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::out) == 0) 12024684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 12034684ddb6SLionel Sambuc} 12044684ddb6SLionel Sambuc 12054684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12064684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12074684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode) 12084684ddb6SLionel Sambuc : basic_ostream<char_type, traits_type>(&__sb_) 12094684ddb6SLionel Sambuc{ 12104684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::out) == 0) 12114684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 12124684ddb6SLionel Sambuc} 1213*0a6a1f1dSLionel Sambuc#endif 12144684ddb6SLionel Sambuc 12154684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 12164684ddb6SLionel Sambuc 12174684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12184684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12194684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs) 12204684ddb6SLionel Sambuc : basic_ostream<char_type, traits_type>(_VSTD::move(__rhs)), 12214684ddb6SLionel Sambuc __sb_(_VSTD::move(__rhs.__sb_)) 12224684ddb6SLionel Sambuc{ 12234684ddb6SLionel Sambuc this->set_rdbuf(&__sb_); 12244684ddb6SLionel Sambuc} 12254684ddb6SLionel Sambuc 12264684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12274684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12284684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>& 12294684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) 12304684ddb6SLionel Sambuc{ 12314684ddb6SLionel Sambuc basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 12324684ddb6SLionel Sambuc __sb_ = _VSTD::move(__rhs.__sb_); 12334684ddb6SLionel Sambuc return *this; 12344684ddb6SLionel Sambuc} 12354684ddb6SLionel Sambuc 12364684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 12374684ddb6SLionel Sambuc 12384684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12394684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12404684ddb6SLionel Sambucvoid 12414684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) 12424684ddb6SLionel Sambuc{ 12434684ddb6SLionel Sambuc basic_ostream<char_type, traits_type>::swap(__rhs); 12444684ddb6SLionel Sambuc __sb_.swap(__rhs.__sb_); 12454684ddb6SLionel Sambuc} 12464684ddb6SLionel Sambuc 12474684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12484684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12494684ddb6SLionel Sambucvoid 12504684ddb6SLionel Sambucswap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) 12514684ddb6SLionel Sambuc{ 12524684ddb6SLionel Sambuc __x.swap(__y); 12534684ddb6SLionel Sambuc} 12544684ddb6SLionel Sambuc 12554684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12564684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12574684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>* 12584684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::rdbuf() const 12594684ddb6SLionel Sambuc{ 12604684ddb6SLionel Sambuc return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); 12614684ddb6SLionel Sambuc} 12624684ddb6SLionel Sambuc 12634684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12644684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12654684ddb6SLionel Sambucbool 12664684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::is_open() const 12674684ddb6SLionel Sambuc{ 12684684ddb6SLionel Sambuc return __sb_.is_open(); 12694684ddb6SLionel Sambuc} 12704684ddb6SLionel Sambuc 1271*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 12724684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12734684ddb6SLionel Sambucvoid 12744684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) 12754684ddb6SLionel Sambuc{ 12764684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::out)) 12774684ddb6SLionel Sambuc this->clear(); 12784684ddb6SLionel Sambuc else 12794684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 12804684ddb6SLionel Sambuc} 12814684ddb6SLionel Sambuc 12824684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12834684ddb6SLionel Sambucvoid 12844684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) 12854684ddb6SLionel Sambuc{ 12864684ddb6SLionel Sambuc if (__sb_.open(__s, __mode | ios_base::out)) 12874684ddb6SLionel Sambuc this->clear(); 12884684ddb6SLionel Sambuc else 12894684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 12904684ddb6SLionel Sambuc} 1291*0a6a1f1dSLionel Sambuc#endif 12924684ddb6SLionel Sambuc 12934684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 12944684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 12954684ddb6SLionel Sambucvoid 12964684ddb6SLionel Sambucbasic_ofstream<_CharT, _Traits>::close() 12974684ddb6SLionel Sambuc{ 12984684ddb6SLionel Sambuc if (__sb_.close() == 0) 12994684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 13004684ddb6SLionel Sambuc} 13014684ddb6SLionel Sambuc 13024684ddb6SLionel Sambuc// basic_fstream 13034684ddb6SLionel Sambuc 13044684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13054684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS_ONLY basic_fstream 13064684ddb6SLionel Sambuc : public basic_iostream<_CharT, _Traits> 13074684ddb6SLionel Sambuc{ 13084684ddb6SLionel Sambucpublic: 13094684ddb6SLionel Sambuc typedef _CharT char_type; 13104684ddb6SLionel Sambuc typedef _Traits traits_type; 13114684ddb6SLionel Sambuc typedef typename traits_type::int_type int_type; 13124684ddb6SLionel Sambuc typedef typename traits_type::pos_type pos_type; 13134684ddb6SLionel Sambuc typedef typename traits_type::off_type off_type; 13144684ddb6SLionel Sambuc 13154684ddb6SLionel Sambuc basic_fstream(); 1316*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 13174684ddb6SLionel Sambuc explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 13184684ddb6SLionel Sambuc explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 1319*0a6a1f1dSLionel Sambuc#endif 13204684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 13214684ddb6SLionel Sambuc basic_fstream(basic_fstream&& __rhs); 13224684ddb6SLionel Sambuc#endif 13234684ddb6SLionel Sambuc 13244684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 13254684ddb6SLionel Sambuc basic_fstream& operator=(basic_fstream&& __rhs); 13264684ddb6SLionel Sambuc#endif 13274684ddb6SLionel Sambuc void swap(basic_fstream& __rhs); 13284684ddb6SLionel Sambuc 13294684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type>* rdbuf() const; 13304684ddb6SLionel Sambuc bool is_open() const; 1331*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 13324684ddb6SLionel Sambuc void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 13334684ddb6SLionel Sambuc void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 1334*0a6a1f1dSLionel Sambuc#endif 13354684ddb6SLionel Sambuc void close(); 13364684ddb6SLionel Sambuc 13374684ddb6SLionel Sambucprivate: 13384684ddb6SLionel Sambuc basic_filebuf<char_type, traits_type> __sb_; 13394684ddb6SLionel Sambuc}; 13404684ddb6SLionel Sambuc 13414684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13424684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13434684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::basic_fstream() 13444684ddb6SLionel Sambuc : basic_iostream<char_type, traits_type>(&__sb_) 13454684ddb6SLionel Sambuc{ 13464684ddb6SLionel Sambuc} 13474684ddb6SLionel Sambuc 1348*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 13494684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13504684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13514684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode) 13524684ddb6SLionel Sambuc : basic_iostream<char_type, traits_type>(&__sb_) 13534684ddb6SLionel Sambuc{ 13544684ddb6SLionel Sambuc if (__sb_.open(__s, __mode) == 0) 13554684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 13564684ddb6SLionel Sambuc} 13574684ddb6SLionel Sambuc 13584684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13594684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13604684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode) 13614684ddb6SLionel Sambuc : basic_iostream<char_type, traits_type>(&__sb_) 13624684ddb6SLionel Sambuc{ 13634684ddb6SLionel Sambuc if (__sb_.open(__s, __mode) == 0) 13644684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 13654684ddb6SLionel Sambuc} 1366*0a6a1f1dSLionel Sambuc#endif 13674684ddb6SLionel Sambuc 13684684ddb6SLionel Sambuc#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 13694684ddb6SLionel Sambuc 13704684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13714684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13724684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs) 13734684ddb6SLionel Sambuc : basic_iostream<char_type, traits_type>(_VSTD::move(__rhs)), 13744684ddb6SLionel Sambuc __sb_(_VSTD::move(__rhs.__sb_)) 13754684ddb6SLionel Sambuc{ 13764684ddb6SLionel Sambuc this->set_rdbuf(&__sb_); 13774684ddb6SLionel Sambuc} 13784684ddb6SLionel Sambuc 13794684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13804684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13814684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>& 13824684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) 13834684ddb6SLionel Sambuc{ 13844684ddb6SLionel Sambuc basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs)); 13854684ddb6SLionel Sambuc __sb_ = _VSTD::move(__rhs.__sb_); 13864684ddb6SLionel Sambuc return *this; 13874684ddb6SLionel Sambuc} 13884684ddb6SLionel Sambuc 13894684ddb6SLionel Sambuc#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 13904684ddb6SLionel Sambuc 13914684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 13924684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 13934684ddb6SLionel Sambucvoid 13944684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) 13954684ddb6SLionel Sambuc{ 13964684ddb6SLionel Sambuc basic_iostream<char_type, traits_type>::swap(__rhs); 13974684ddb6SLionel Sambuc __sb_.swap(__rhs.__sb_); 13984684ddb6SLionel Sambuc} 13994684ddb6SLionel Sambuc 14004684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14014684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14024684ddb6SLionel Sambucvoid 14034684ddb6SLionel Sambucswap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) 14044684ddb6SLionel Sambuc{ 14054684ddb6SLionel Sambuc __x.swap(__y); 14064684ddb6SLionel Sambuc} 14074684ddb6SLionel Sambuc 14084684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14094684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14104684ddb6SLionel Sambucbasic_filebuf<_CharT, _Traits>* 14114684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::rdbuf() const 14124684ddb6SLionel Sambuc{ 14134684ddb6SLionel Sambuc return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_); 14144684ddb6SLionel Sambuc} 14154684ddb6SLionel Sambuc 14164684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14174684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14184684ddb6SLionel Sambucbool 14194684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::is_open() const 14204684ddb6SLionel Sambuc{ 14214684ddb6SLionel Sambuc return __sb_.is_open(); 14224684ddb6SLionel Sambuc} 14234684ddb6SLionel Sambuc 1424*0a6a1f1dSLionel Sambuc#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE 14254684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14264684ddb6SLionel Sambucvoid 14274684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) 14284684ddb6SLionel Sambuc{ 14294684ddb6SLionel Sambuc if (__sb_.open(__s, __mode)) 14304684ddb6SLionel Sambuc this->clear(); 14314684ddb6SLionel Sambuc else 14324684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 14334684ddb6SLionel Sambuc} 14344684ddb6SLionel Sambuc 14354684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14364684ddb6SLionel Sambucvoid 14374684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) 14384684ddb6SLionel Sambuc{ 14394684ddb6SLionel Sambuc if (__sb_.open(__s, __mode)) 14404684ddb6SLionel Sambuc this->clear(); 14414684ddb6SLionel Sambuc else 14424684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 14434684ddb6SLionel Sambuc} 1444*0a6a1f1dSLionel Sambuc#endif 14454684ddb6SLionel Sambuc 14464684ddb6SLionel Sambuctemplate <class _CharT, class _Traits> 14474684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 14484684ddb6SLionel Sambucvoid 14494684ddb6SLionel Sambucbasic_fstream<_CharT, _Traits>::close() 14504684ddb6SLionel Sambuc{ 14514684ddb6SLionel Sambuc if (__sb_.close() == 0) 14524684ddb6SLionel Sambuc this->setstate(ios_base::failbit); 14534684ddb6SLionel Sambuc} 14544684ddb6SLionel Sambuc 14554684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 14564684ddb6SLionel Sambuc 14574684ddb6SLionel Sambuc#endif // _LIBCPP_FSTREAM 1458