33#ifndef _GLIBCXX_FSTREAM
34#define _GLIBCXX_FSTREAM 1
37#pragma GCC system_header
47#if __cplusplus >= 201103L
51#define __glibcxx_want_fstream_native_handle
55#ifndef _GLIBCXX_BUFSIZ
56# define _GLIBCXX_BUFSIZ BUFSIZ
59namespace std _GLIBCXX_VISIBILITY(default)
61_GLIBCXX_BEGIN_NAMESPACE_VERSION
63#if __cplusplus >= 201703L
65 template<
typename _Path,
typename _Result = _Path,
typename _Path2
66 =
decltype(std::declval<_Path&>().make_preferred().filename())>
67 using _If_fs_path =
enable_if_t<is_same_v<_Path, _Path2>, _Result>;
91 template<
typename _CharT,
typename _Traits>
94#if __cplusplus >= 201103L
95 template<
typename _Tp>
96 using __chk_state = __and_<is_copy_assignable<_Tp>,
100 static_assert(__chk_state<typename _Traits::state_type>::value,
101 "state_type must be CopyAssignable, CopyConstructible"
102 " and DefaultConstructible");
104 static_assert(
is_same<
typename _Traits::pos_type,
106 "pos_type must be fpos<state_type>");
110 typedef _CharT char_type;
111 typedef _Traits traits_type;
112 typedef typename traits_type::int_type int_type;
113 typedef typename traits_type::pos_type pos_type;
114 typedef typename traits_type::off_type off_type;
118 typedef __basic_file<char> __file_type;
119 typedef typename traits_type::state_type __state_type;
136 __state_type _M_state_beg;
141 __state_type _M_state_cur;
145 __state_type _M_state_last;
158 bool _M_buf_allocated;
183 const __codecvt_type* _M_codecvt;
215 _M_pback_cur_save = this->gptr();
216 _M_pback_end_save = this->egptr();
217 this->setg(&_M_pback, &_M_pback, &_M_pback + 1);
218 _M_pback_init =
true;
233 _M_pback_cur_save += this->gptr() != this->eback();
234 this->setg(_M_buf, _M_pback_cur_save, _M_pback_end_save);
235 _M_pback_init =
false;
249#if __cplusplus >= 201103L
266#if __cplusplus >= 201103L
279 {
return _M_file.is_open(); }
323 open(
const char* __s, ios_base::openmode __mode);
325#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
333 open(
const wchar_t* __s, ios_base::openmode __mode);
336#if __cplusplus >= 201103L
345 {
return open(__s.
c_str(), __mode); }
347#if __cplusplus >= 201703L
354 template<
typename _Path>
355 _If_fs_path<_Path, __filebuf_type*>
356 open(
const _Path& __s, ios_base::openmode __mode)
357 {
return open(__s.c_str(), __mode); }
376#if __cpp_lib_fstream_native_handle
386 using native_handle_type =
typename __file_type::native_handle_type;
397 [[__gnu__::__always_inline__]]
399 native_handle() const noexcept
401 __glibcxx_assert(is_open());
402 return _M_file.native_handle();
408 _M_allocate_internal_buffer();
411 _M_destroy_internal_buffer() throw();
426 pbackfail(int_type __c = _Traits::eof());
436 overflow(int_type __c = _Traits::eof());
441 _M_convert_to_external(char_type*,
streamsize);
455 virtual __streambuf_type*
459 seekoff(off_type __off, ios_base::seekdir __way,
460 ios_base::openmode __mode = ios_base::in | ios_base::out);
463 seekpos(pos_type __pos,
464 ios_base::openmode __mode = ios_base::in | ios_base::out);
468 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
471 _M_get_ext_pos(__state_type &__state);
477 imbue(const locale& __loc);
487 _M_terminate_output();
508 if (__testin && __off > 0)
509 this->setg(_M_buf, _M_buf, _M_buf + __off);
511 this->setg(_M_buf, _M_buf, _M_buf);
513 if (__testout && __off == 0 && _M_buf_size > 1 )
514 this->setp(_M_buf, _M_buf + _M_buf_size - 1);
534 template<
typename _CharT,
typename _Traits>
539 typedef _CharT char_type;
540 typedef _Traits traits_type;
541 typedef typename traits_type::int_type int_type;
542 typedef typename traits_type::pos_type pos_type;
543 typedef typename traits_type::off_type off_type;
562 { this->
init(&_M_filebuf); }
575 this->
init(&_M_filebuf);
576 this->
open(__s, __mode);
579#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
589 : __istream_type(), _M_filebuf()
591 this->
init(&_M_filebuf);
592 this->
open(__s, __mode);
596#if __cplusplus >= 201103L
609 this->
init(&_M_filebuf);
610 this->
open(__s, __mode);
613#if __cplusplus >= 201703L
621 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
631 : __istream_type(
std::move(__rhs)),
632 _M_filebuf(
std::move(__rhs._M_filebuf))
633 { __istream_type::set_rdbuf(&_M_filebuf); }
645#if __cplusplus >= 201103L
654 __istream_type::operator=(
std::move(__rhs));
655 _M_filebuf =
std::move(__rhs._M_filebuf);
662 __istream_type::swap(__rhs);
663 _M_filebuf.swap(__rhs._M_filebuf);
686 {
return _M_filebuf.
is_open(); }
693 {
return _M_filebuf.
is_open(); }
714#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
733#if __cplusplus >= 201103L
753#if __cplusplus >= 201703L
762 template<
typename _Path>
763 _If_fs_path<_Path, void>
765 {
open(__s.c_str(), __mode); }
778 if (!_M_filebuf.
close())
782#if __cpp_lib_fstream_native_handle
783 using native_handle_type =
typename __filebuf_type::native_handle_type;
785 [[__gnu__::__always_inline__]]
787 native_handle() const noexcept
788 {
return _M_filebuf.native_handle(); }
807 template<
typename _CharT,
typename _Traits>
812 typedef _CharT char_type;
813 typedef _Traits traits_type;
814 typedef typename traits_type::int_type int_type;
815 typedef typename traits_type::pos_type pos_type;
816 typedef typename traits_type::off_type off_type;
835 { this->
init(&_M_filebuf); }
849 this->
init(&_M_filebuf);
850 this->
open(__s, __mode);
853#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
864 : __ostream_type(), _M_filebuf()
866 this->
init(&_M_filebuf);
867 this->
open(__s, __mode);
871#if __cplusplus >= 201103L
884 this->
init(&_M_filebuf);
885 this->
open(__s, __mode);
888#if __cplusplus >= 201703L
896 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
906 : __ostream_type(
std::move(__rhs)),
907 _M_filebuf(
std::move(__rhs._M_filebuf))
908 { __ostream_type::set_rdbuf(&_M_filebuf); }
920#if __cplusplus >= 201103L
929 __ostream_type::operator=(
std::move(__rhs));
930 _M_filebuf =
std::move(__rhs._M_filebuf);
937 __ostream_type::swap(__rhs);
938 _M_filebuf.swap(__rhs._M_filebuf);
961 {
return _M_filebuf.
is_open(); }
968 {
return _M_filebuf.
is_open(); }
989#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1008#if __cplusplus >= 201103L
1028#if __cplusplus >= 201703L
1037 template<
typename _Path>
1038 _If_fs_path<_Path, void>
1040 {
open(__s.c_str(), __mode); }
1053 if (!_M_filebuf.
close())
1057#if __cpp_lib_fstream_native_handle
1058 using native_handle_type =
typename __filebuf_type::native_handle_type;
1060 [[__gnu__::__always_inline__]]
1062 native_handle() const noexcept
1063 {
return _M_filebuf.native_handle(); }
1082 template<
typename _CharT,
typename _Traits>
1087 typedef _CharT char_type;
1088 typedef _Traits traits_type;
1089 typedef typename traits_type::int_type int_type;
1090 typedef typename traits_type::pos_type pos_type;
1091 typedef typename traits_type::off_type off_type;
1111 : __iostream_type(), _M_filebuf()
1112 { this->
init(&_M_filebuf); }
1122 : __iostream_type(0), _M_filebuf()
1124 this->
init(&_M_filebuf);
1125 this->
open(__s, __mode);
1128#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1136 : __iostream_type(0), _M_filebuf()
1138 this->
init(&_M_filebuf);
1139 this->
open(__s, __mode);
1143#if __cplusplus >= 201103L
1152 : __iostream_type(0), _M_filebuf()
1154 this->
init(&_M_filebuf);
1155 this->
open(__s, __mode);
1158#if __cplusplus >= 201703L
1164 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
1174 : __iostream_type(
std::
move(__rhs)),
1175 _M_filebuf(
std::
move(__rhs._M_filebuf))
1176 { __iostream_type::set_rdbuf(&_M_filebuf); }
1188#if __cplusplus >= 201103L
1197 __iostream_type::operator=(
std::move(__rhs));
1198 _M_filebuf =
std::move(__rhs._M_filebuf);
1205 __iostream_type::swap(__rhs);
1206 _M_filebuf.swap(__rhs._M_filebuf);
1229 {
return _M_filebuf.
is_open(); }
1236 {
return _M_filebuf.
is_open(); }
1250 if (!_M_filebuf.
open(__s, __mode))
1258#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1268 open(
const wchar_t* __s,
1271 if (!_M_filebuf.
open(__s, __mode))
1278#if __cplusplus >= 201103L
1291 if (!_M_filebuf.
open(__s, __mode))
1299#if __cplusplus >= 201703L
1308 template<
typename _Path>
1309 _If_fs_path<_Path, void>
1312 {
open(__s.c_str(), __mode); }
1325 if (!_M_filebuf.
close())
1329#if __cpp_lib_fstream_native_handle
1330 using native_handle_type =
typename __filebuf_type::native_handle_type;
1332 [[__gnu__::__always_inline__]]
1334 native_handle() const noexcept
1335 {
return _M_filebuf.native_handle(); }
1339#if __cplusplus >= 201103L
1341 template <
class _CharT,
class _Traits>
1348 template <
class _CharT,
class _Traits>
1355 template <
class _CharT,
class _Traits>
1362 template <
class _CharT,
class _Traits>
1369_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.