33#ifndef _GLIBCXX_FSTREAM
34#define _GLIBCXX_FSTREAM 1
36#pragma GCC system_header
43#if __cplusplus >= 201103L
48#ifndef _GLIBCXX_BUFSIZ
49# define _GLIBCXX_BUFSIZ BUFSIZ
52namespace std _GLIBCXX_VISIBILITY(default)
54_GLIBCXX_BEGIN_NAMESPACE_VERSION
56#if __cplusplus >= 201703L
58 template<
typename _Path,
typename _Result = _Path,
typename _Path2
84 template<
typename _CharT,
typename _Traits>
87#if __cplusplus >= 201103L
88 template<
typename _Tp>
89 using __chk_state = __and_<is_copy_assignable<_Tp>,
93 static_assert(__chk_state<typename _Traits::state_type>::value,
94 "state_type must be CopyAssignable, CopyConstructible"
95 " and DefaultConstructible");
97 static_assert(
is_same<
typename _Traits::pos_type,
99 "pos_type must be fpos<state_type>");
103 typedef _CharT char_type;
104 typedef _Traits traits_type;
105 typedef typename traits_type::int_type int_type;
106 typedef typename traits_type::pos_type pos_type;
107 typedef typename traits_type::off_type off_type;
111 typedef __basic_file<char> __file_type;
112 typedef typename traits_type::state_type __state_type;
115 friend class ios_base;
129 __state_type _M_state_beg;
134 __state_type _M_state_cur;
138 __state_type _M_state_last;
151 bool _M_buf_allocated;
176 const __codecvt_type* _M_codecvt;
209 _M_pback_end_save = this->
egptr();
242#if __cplusplus >= 201103L
259#if __cplusplus >= 201103L
271 {
return _M_file.is_open(); }
317#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
328#if __cplusplus >= 201103L
339#if __cplusplus >= 201703L
346 template<
typename _Path>
347 _If_fs_path<_Path, __filebuf_type*>
349 {
return open(__s.c_str(), __mode); }
370 _M_allocate_internal_buffer();
373 _M_destroy_internal_buffer() throw();
403 _M_convert_to_external(char_type*,
streamsize);
417 virtual __streambuf_type*
421 seekoff(off_type __off, ios_base::seekdir __way,
422 ios_base::openmode __mode = ios_base::in | ios_base::out);
426 ios_base::openmode __mode = ios_base::in | ios_base::out);
430 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
433 _M_get_ext_pos(__state_type &__state);
449 _M_terminate_output();
470 if (__testin && __off > 0)
496 template<
typename _CharT,
typename _Traits>
501 typedef _CharT char_type;
502 typedef _Traits traits_type;
503 typedef typename traits_type::int_type int_type;
504 typedef typename traits_type::pos_type pos_type;
505 typedef typename traits_type::off_type off_type;
512 __filebuf_type _M_filebuf;
524 { this->
init(&_M_filebuf); }
535 : __istream_type(), _M_filebuf()
537 this->
init(&_M_filebuf);
538 this->
open(__s, __mode);
541#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
551 : __istream_type(), _M_filebuf()
553 this->
init(&_M_filebuf);
554 this->
open(__s, __mode);
558#if __cplusplus >= 201103L
569 : __istream_type(), _M_filebuf()
571 this->
init(&_M_filebuf);
572 this->
open(__s, __mode);
575#if __cplusplus >= 201703L
583 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
593 : __istream_type(
std::
move(__rhs)),
594 _M_filebuf(
std::
move(__rhs._M_filebuf))
595 { __istream_type::set_rdbuf(&_M_filebuf); }
607#if __cplusplus >= 201103L
616 __istream_type::operator=(
std::move(__rhs));
617 _M_filebuf =
std::move(__rhs._M_filebuf);
624 __istream_type::swap(__rhs);
625 _M_filebuf.swap(__rhs._M_filebuf);
638 {
return const_cast<__filebuf_type*
>(&_M_filebuf); }
646 {
return _M_filebuf.is_open(); }
652 {
return _M_filebuf.
is_open(); }
673#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
692#if __cplusplus >= 201103L
712#if __cplusplus >= 201703L
721 template<
typename _Path>
722 _If_fs_path<_Path, void>
724 {
open(__s.c_str(), __mode); }
737 if (!_M_filebuf.close())
757 template<
typename _CharT,
typename _Traits>
762 typedef _CharT char_type;
763 typedef _Traits traits_type;
764 typedef typename traits_type::int_type int_type;
765 typedef typename traits_type::pos_type pos_type;
766 typedef typename traits_type::off_type off_type;
773 __filebuf_type _M_filebuf;
785 { this->
init(&_M_filebuf); }
797 : __ostream_type(), _M_filebuf()
799 this->
init(&_M_filebuf);
800 this->
open(__s, __mode);
803#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
814 : __ostream_type(), _M_filebuf()
816 this->
init(&_M_filebuf);
817 this->
open(__s, __mode);
821#if __cplusplus >= 201103L
832 : __ostream_type(), _M_filebuf()
834 this->
init(&_M_filebuf);
835 this->
open(__s, __mode);
838#if __cplusplus >= 201703L
846 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
856 : __ostream_type(
std::
move(__rhs)),
857 _M_filebuf(
std::
move(__rhs._M_filebuf))
858 { __ostream_type::set_rdbuf(&_M_filebuf); }
870#if __cplusplus >= 201103L
879 __ostream_type::operator=(
std::move(__rhs));
880 _M_filebuf =
std::move(__rhs._M_filebuf);
887 __ostream_type::swap(__rhs);
888 _M_filebuf.swap(__rhs._M_filebuf);
901 {
return const_cast<__filebuf_type*
>(&_M_filebuf); }
909 {
return _M_filebuf.is_open(); }
915 {
return _M_filebuf.
is_open(); }
936#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
955#if __cplusplus >= 201103L
975#if __cplusplus >= 201703L
984 template<
typename _Path>
985 _If_fs_path<_Path, void>
987 {
open(__s.c_str(), __mode); }
1000 if (!_M_filebuf.close())
1020 template<
typename _CharT,
typename _Traits>
1025 typedef _CharT char_type;
1026 typedef _Traits traits_type;
1027 typedef typename traits_type::int_type int_type;
1028 typedef typename traits_type::pos_type pos_type;
1029 typedef typename traits_type::off_type off_type;
1037 __filebuf_type _M_filebuf;
1049 : __iostream_type(), _M_filebuf()
1050 { this->
init(&_M_filebuf); }
1060 : __iostream_type(0), _M_filebuf()
1062 this->
init(&_M_filebuf);
1063 this->
open(__s, __mode);
1066#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1074 : __iostream_type(0), _M_filebuf()
1076 this->
init(&_M_filebuf);
1077 this->
open(__s, __mode);
1081#if __cplusplus >= 201103L
1090 : __iostream_type(0), _M_filebuf()
1092 this->
init(&_M_filebuf);
1093 this->
open(__s, __mode);
1096#if __cplusplus >= 201703L
1102 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
1112 : __iostream_type(
std::
move(__rhs)),
1113 _M_filebuf(
std::
move(__rhs._M_filebuf))
1114 { __iostream_type::set_rdbuf(&_M_filebuf); }
1126#if __cplusplus >= 201103L
1135 __iostream_type::operator=(
std::move(__rhs));
1136 _M_filebuf =
std::move(__rhs._M_filebuf);
1143 __iostream_type::swap(__rhs);
1144 _M_filebuf.swap(__rhs._M_filebuf);
1157 {
return const_cast<__filebuf_type*
>(&_M_filebuf); }
1165 {
return _M_filebuf.is_open(); }
1171 {
return _M_filebuf.
is_open(); }
1185 if (!_M_filebuf.open(__s, __mode))
1193#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1203 open(
const wchar_t* __s,
1206 if (!_M_filebuf.
open(__s, __mode))
1213#if __cplusplus >= 201103L
1226 if (!_M_filebuf.open(__s, __mode))
1234#if __cplusplus >= 201703L
1243 template<
typename _Path>
1244 _If_fs_path<_Path, void>
1247 {
open(__s.c_str(), __mode); }
1260 if (!_M_filebuf.close())
1265#if __cplusplus >= 201103L
1267 template <
class _CharT,
class _Traits>
1274 template <
class _CharT,
class _Traits>
1281 template <
class _CharT,
class _Traits>
1288 template <
class _CharT,
class _Traits>
1295_GLIBCXX_END_NAMESPACE_VERSION
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
basic_string< char > string
A string of char.
ISO C++ entities toplevel namespace is std.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
The actual work of input and output (for files).
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)
virtual int_type underflow()
virtual streamsize showmanyc()
ios_base::openmode _M_mode
virtual ~basic_filebuf()
The destructor closes the file first.
streamsize _M_ext_buf_size
char_type * _M_pback_cur_save
_If_fs_path< _Path, __filebuf_type * > open(const _Path &__s, ios_base::openmode __mode)
Opens an external file.
__filebuf_type * open(const std::string &__s, ios_base::openmode __mode)
Opens an external file.
virtual void imbue(const locale &__loc)
virtual streamsize xsgetn(char_type *__s, streamsize __n)
bool is_open() const
Returns true if the external file is open.
__filebuf_type * close()
Closes the currently associated file.
char_type * _M_pback_end_save
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
virtual int_type pbackfail(int_type __c=traits_type::eof())
virtual streamsize xsputn(const char_type *__s, streamsize __n)
virtual int_type overflow(int_type __c=traits_type::eof())
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
basic_filebuf()
Does not open any files.
void _M_set_buffer(streamsize __off)
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Controlling input for files.
basic_ifstream()
Default constructor.
~basic_ifstream()
The destructor does nothing.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
basic_ifstream(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
void close()
Close the file.
bool is_open()
Wrapper to test for an open file.
Controlling output for files.
basic_ofstream()
Default constructor.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
void close()
Close the file.
basic_ofstream(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
void open(const char *__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
~basic_ofstream()
The destructor does nothing.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
bool is_open()
Wrapper to test for an open file.
Controlling input and output for files.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
~basic_fstream()
The destructor does nothing.
basic_fstream(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
void open(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
basic_fstream(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
bool is_open()
Wrapper to test for an open file.
void close()
Close the file.
basic_fstream(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
basic_fstream()
Default constructor.
Template class basic_ios, virtual base class for all stream classes.
void clear(iostate __state=goodbit)
[Re]sets the error state.
void setstate(iostate __state)
Sets additional flags in the error state.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
char_type * eback() const
Access to the get area.
char_type * egptr() const
Access to the get area.
char_type * gptr() const
Access to the get area.
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
basic_streambuf()
Base constructor.
basic_istream(__streambuf_type *__sb)
Base constructor.
basic_ostream(__streambuf_type *__sb)
Base constructor.
basic_iostream(basic_streambuf< _CharT, _Traits > *__sb)
Constructor does nothing.
constexpr const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Primary class template codecvt.
static const openmode in
Open for input. Default for ifstream and fstream.
static const openmode out
Open for output. Default for ofstream and fstream.
_Ios_Openmode openmode
This is a bitmask type.
static const openmode app
Seek to end before each write.
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
Container class for localization functionality.
Class representing stream positions.