33#ifndef _GLIBCXX_FSTREAM
34#define _GLIBCXX_FSTREAM 1
36#pragma GCC system_header
45#if __cplusplus >= 201103L
49#define __glibcxx_want_fstream_native_handle
53#ifndef _GLIBCXX_BUFSIZ
54# define _GLIBCXX_BUFSIZ BUFSIZ
57namespace std _GLIBCXX_VISIBILITY(default)
59_GLIBCXX_BEGIN_NAMESPACE_VERSION
61#if __cplusplus >= 201703L
63 template<
typename _Path,
typename _Result = _Path,
typename _Path2
64 =
decltype(std::declval<_Path&>().make_preferred().filename())>
65 using _If_fs_path =
enable_if_t<is_same_v<_Path, _Path2>, _Result>;
89 template<
typename _CharT,
typename _Traits>
92#if __cplusplus >= 201103L
93 template<
typename _Tp>
94 using __chk_state = __and_<is_copy_assignable<_Tp>,
98 static_assert(__chk_state<typename _Traits::state_type>::value,
99 "state_type must be CopyAssignable, CopyConstructible"
100 " and DefaultConstructible");
102 static_assert(
is_same<
typename _Traits::pos_type,
104 "pos_type must be fpos<state_type>");
108 typedef _CharT char_type;
109 typedef _Traits traits_type;
110 typedef typename traits_type::int_type int_type;
111 typedef typename traits_type::pos_type pos_type;
112 typedef typename traits_type::off_type off_type;
116 typedef __basic_file<char> __file_type;
117 typedef typename traits_type::state_type __state_type;
134 __state_type _M_state_beg;
139 __state_type _M_state_cur;
143 __state_type _M_state_last;
156 bool _M_buf_allocated;
213 _M_pback_cur_save = this->gptr();
214 _M_pback_end_save = this->egptr();
215 this->setg(&_M_pback, &_M_pback, &_M_pback + 1);
216 _M_pback_init =
true;
231 _M_pback_cur_save += this->gptr() != this->eback();
232 this->setg(_M_buf, _M_pback_cur_save, _M_pback_end_save);
233 _M_pback_init =
false;
247#if __cplusplus >= 201103L
264#if __cplusplus >= 201103L
276 {
return _M_file.is_open(); }
320 open(
const char* __s, ios_base::openmode __mode);
322#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
330 open(
const wchar_t* __s, ios_base::openmode __mode);
333#if __cplusplus >= 201103L
342 {
return open(__s.
c_str(), __mode); }
344#if __cplusplus >= 201703L
351 template<
typename _Path>
352 _If_fs_path<_Path, __filebuf_type*>
353 open(
const _Path& __s, ios_base::openmode __mode)
354 {
return open(__s.c_str(), __mode); }
373#if __cpp_lib_fstream_native_handle
383 using native_handle_type =
typename __file_type::native_handle_type;
394 [[__gnu__::__always_inline__]]
396 native_handle() const noexcept
398 __glibcxx_assert(is_open());
399 return _M_file.native_handle();
405 _M_allocate_internal_buffer();
408 _M_destroy_internal_buffer() throw();
423 pbackfail(int_type __c = _Traits::eof());
433 overflow(int_type __c = _Traits::eof());
438 _M_convert_to_external(char_type*,
streamsize);
452 virtual __streambuf_type*
456 seekoff(off_type __off, ios_base::seekdir __way,
457 ios_base::openmode __mode = ios_base::in | ios_base::out);
460 seekpos(pos_type __pos,
461 ios_base::openmode __mode = ios_base::in | ios_base::out);
465 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
468 _M_get_ext_pos(__state_type &__state);
474 imbue(const locale& __loc);
484 _M_terminate_output();
505 if (__testin && __off > 0)
506 this->setg(_M_buf, _M_buf, _M_buf + __off);
508 this->setg(_M_buf, _M_buf, _M_buf);
510 if (__testout && __off == 0 && _M_buf_size > 1 )
511 this->setp(_M_buf, _M_buf + _M_buf_size - 1);
531 template<
typename _CharT,
typename _Traits>
536 typedef _CharT char_type;
537 typedef _Traits traits_type;
538 typedef typename traits_type::int_type int_type;
539 typedef typename traits_type::pos_type pos_type;
540 typedef typename traits_type::off_type off_type;
559 { this->
init(&_M_filebuf); }
572 this->
init(&_M_filebuf);
573 this->
open(__s, __mode);
576#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
586 : __istream_type(), _M_filebuf()
588 this->
init(&_M_filebuf);
589 this->
open(__s, __mode);
593#if __cplusplus >= 201103L
606 this->
init(&_M_filebuf);
607 this->
open(__s, __mode);
610#if __cplusplus >= 201703L
618 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
628 : __istream_type(
std::move(__rhs)),
629 _M_filebuf(
std::move(__rhs._M_filebuf))
630 { __istream_type::set_rdbuf(&_M_filebuf); }
642#if __cplusplus >= 201103L
651 __istream_type::operator=(
std::move(__rhs));
652 _M_filebuf =
std::move(__rhs._M_filebuf);
659 __istream_type::swap(__rhs);
660 _M_filebuf.swap(__rhs._M_filebuf);
681 {
return _M_filebuf.
is_open(); }
687 {
return _M_filebuf.
is_open(); }
708#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
727#if __cplusplus >= 201103L
747#if __cplusplus >= 201703L
756 template<
typename _Path>
757 _If_fs_path<_Path, void>
759 {
open(__s.c_str(), __mode); }
772 if (!_M_filebuf.
close())
776#if __cpp_lib_fstream_native_handle
777 using native_handle_type =
typename __filebuf_type::native_handle_type;
779 [[__gnu__::__always_inline__]]
781 native_handle() const noexcept
782 {
return _M_filebuf.native_handle(); }
801 template<
typename _CharT,
typename _Traits>
806 typedef _CharT char_type;
807 typedef _Traits traits_type;
808 typedef typename traits_type::int_type int_type;
809 typedef typename traits_type::pos_type pos_type;
810 typedef typename traits_type::off_type off_type;
829 { this->
init(&_M_filebuf); }
843 this->
init(&_M_filebuf);
844 this->
open(__s, __mode);
847#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
858 : __ostream_type(), _M_filebuf()
860 this->
init(&_M_filebuf);
861 this->
open(__s, __mode);
865#if __cplusplus >= 201103L
878 this->
init(&_M_filebuf);
879 this->
open(__s, __mode);
882#if __cplusplus >= 201703L
890 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
900 : __ostream_type(
std::move(__rhs)),
901 _M_filebuf(
std::move(__rhs._M_filebuf))
902 { __ostream_type::set_rdbuf(&_M_filebuf); }
914#if __cplusplus >= 201103L
923 __ostream_type::operator=(
std::move(__rhs));
924 _M_filebuf =
std::move(__rhs._M_filebuf);
931 __ostream_type::swap(__rhs);
932 _M_filebuf.swap(__rhs._M_filebuf);
953 {
return _M_filebuf.
is_open(); }
959 {
return _M_filebuf.
is_open(); }
980#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
999#if __cplusplus >= 201103L
1019#if __cplusplus >= 201703L
1028 template<
typename _Path>
1029 _If_fs_path<_Path, void>
1031 {
open(__s.c_str(), __mode); }
1044 if (!_M_filebuf.
close())
1048#if __cpp_lib_fstream_native_handle
1049 using native_handle_type =
typename __filebuf_type::native_handle_type;
1051 [[__gnu__::__always_inline__]]
1053 native_handle() const noexcept
1054 {
return _M_filebuf.native_handle(); }
1073 template<
typename _CharT,
typename _Traits>
1078 typedef _CharT char_type;
1079 typedef _Traits traits_type;
1080 typedef typename traits_type::int_type int_type;
1081 typedef typename traits_type::pos_type pos_type;
1082 typedef typename traits_type::off_type off_type;
1103 { this->
init(&_M_filebuf); }
1115 this->
init(&_M_filebuf);
1116 this->
open(__s, __mode);
1119#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1127 : __iostream_type(0), _M_filebuf()
1129 this->
init(&_M_filebuf);
1130 this->
open(__s, __mode);
1134#if __cplusplus >= 201103L
1145 this->
init(&_M_filebuf);
1146 this->
open(__s, __mode);
1149#if __cplusplus >= 201703L
1155 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
1165 : __iostream_type(
std::
move(__rhs)),
1166 _M_filebuf(
std::
move(__rhs._M_filebuf))
1167 { __iostream_type::set_rdbuf(&_M_filebuf); }
1179#if __cplusplus >= 201103L
1188 __iostream_type::operator=(
std::move(__rhs));
1189 _M_filebuf =
std::move(__rhs._M_filebuf);
1196 __iostream_type::swap(__rhs);
1197 _M_filebuf.swap(__rhs._M_filebuf);
1218 {
return _M_filebuf.
is_open(); }
1224 {
return _M_filebuf.
is_open(); }
1238 if (!_M_filebuf.
open(__s, __mode))
1246#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1256 open(
const wchar_t* __s,
1259 if (!_M_filebuf.
open(__s, __mode))
1266#if __cplusplus >= 201103L
1279 if (!_M_filebuf.
open(__s, __mode))
1287#if __cplusplus >= 201703L
1296 template<
typename _Path>
1297 _If_fs_path<_Path, void>
1300 {
open(__s.c_str(), __mode); }
1313 if (!_M_filebuf.
close())
1317#if __cpp_lib_fstream_native_handle
1318 using native_handle_type =
typename __filebuf_type::native_handle_type;
1320 [[__gnu__::__always_inline__]]
1322 native_handle() const noexcept
1323 {
return _M_filebuf.native_handle(); }
1327#if __cplusplus >= 201103L
1329 template <
class _CharT,
class _Traits>
1336 template <
class _CharT,
class _Traits>
1343 template <
class _CharT,
class _Traits>
1350 template <
class _CharT,
class _Traits>
1357_GLIBCXX_END_NAMESPACE_VERSION
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
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).
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current filebuf.
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.
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
char_type * _M_buf
Pointer to the beginning of internal buffer.
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
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.
The actual work of input and output (interface).
Template class basic_istream.
Template class basic_ostream.
Template class basic_iostream.
Primary class template codecvt.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
The base of the I/O class hierarchy.
static const openmode in
Open for input. Default for ifstream and fstream.
static const openmode out
Open for output. Default for ofstream and fstream.
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...
Class representing stream positions.