33#ifndef _GLIBCXX_FSTREAM
34#define _GLIBCXX_FSTREAM 1
36#pragma GCC system_header
45#if __cplusplus >= 201103L
50#ifndef _GLIBCXX_BUFSIZ
51# define _GLIBCXX_BUFSIZ BUFSIZ
54namespace std _GLIBCXX_VISIBILITY(default)
56_GLIBCXX_BEGIN_NAMESPACE_VERSION
58#if __cplusplus >= 201703L
60 template<
typename _Path,
typename _Result = _Path,
typename _Path2
61 =
decltype(std::declval<_Path&>().make_preferred().filename())>
62 using _If_fs_path =
enable_if_t<is_same_v<_Path, _Path2>, _Result>;
86 template<
typename _CharT,
typename _Traits>
89#if __cplusplus >= 201103L
90 template<
typename _Tp>
91 using __chk_state = __and_<is_copy_assignable<_Tp>,
95 static_assert(__chk_state<typename _Traits::state_type>::value,
96 "state_type must be CopyAssignable, CopyConstructible"
97 " and DefaultConstructible");
99 static_assert(
is_same<
typename _Traits::pos_type,
101 "pos_type must be fpos<state_type>");
105 typedef _CharT char_type;
106 typedef _Traits traits_type;
107 typedef typename traits_type::int_type int_type;
108 typedef typename traits_type::pos_type pos_type;
109 typedef typename traits_type::off_type off_type;
113 typedef __basic_file<char> __file_type;
114 typedef typename traits_type::state_type __state_type;
131 __state_type _M_state_beg;
136 __state_type _M_state_cur;
140 __state_type _M_state_last;
153 bool _M_buf_allocated;
210 _M_pback_cur_save = this->gptr();
211 _M_pback_end_save = this->egptr();
212 this->setg(&_M_pback, &_M_pback, &_M_pback + 1);
213 _M_pback_init =
true;
228 _M_pback_cur_save += this->gptr() != this->eback();
229 this->setg(_M_buf, _M_pback_cur_save, _M_pback_end_save);
230 _M_pback_init =
false;
244#if __cplusplus >= 201103L
261#if __cplusplus >= 201103L
273 {
return _M_file.is_open(); }
317 open(
const char* __s, ios_base::openmode __mode);
319#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
327 open(
const wchar_t* __s, ios_base::openmode __mode);
330#if __cplusplus >= 201103L
339 {
return open(__s.
c_str(), __mode); }
341#if __cplusplus >= 201703L
348 template<
typename _Path>
349 _If_fs_path<_Path, __filebuf_type*>
350 open(
const _Path& __s, ios_base::openmode __mode)
351 {
return open(__s.c_str(), __mode); }
372 _M_allocate_internal_buffer();
375 _M_destroy_internal_buffer() throw();
390 pbackfail(int_type __c = _Traits::eof());
400 overflow(int_type __c = _Traits::eof());
405 _M_convert_to_external(char_type*,
streamsize);
419 virtual __streambuf_type*
423 seekoff(off_type __off,
ios_base::seekdir __way,
427 seekpos(pos_type __pos,
432 _M_seek(off_type __off,
ios_base::seekdir __way, __state_type __state);
435 _M_get_ext_pos(__state_type &__state);
441 imbue(const
locale& __loc);
451 _M_terminate_output();
472 if (__testin && __off > 0)
473 this->setg(_M_buf, _M_buf, _M_buf + __off);
475 this->setg(_M_buf, _M_buf, _M_buf);
477 if (__testout && __off == 0 && _M_buf_size > 1 )
478 this->setp(_M_buf, _M_buf + _M_buf_size - 1);
498 template<
typename _CharT,
typename _Traits>
503 typedef _CharT char_type;
504 typedef _Traits traits_type;
505 typedef typename traits_type::int_type int_type;
506 typedef typename traits_type::pos_type pos_type;
507 typedef typename traits_type::off_type off_type;
526 { this->
init(&_M_filebuf); }
539 this->
init(&_M_filebuf);
540 this->
open(__s, __mode);
543#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
553 : __istream_type(), _M_filebuf()
555 this->
init(&_M_filebuf);
556 this->
open(__s, __mode);
560#if __cplusplus >= 201103L
573 this->
init(&_M_filebuf);
574 this->
open(__s, __mode);
577#if __cplusplus >= 201703L
585 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
595 : __istream_type(
std::move(__rhs)),
596 _M_filebuf(
std::move(__rhs._M_filebuf))
597 { __istream_type::set_rdbuf(&_M_filebuf); }
609#if __cplusplus >= 201103L
618 __istream_type::operator=(
std::move(__rhs));
619 _M_filebuf =
std::move(__rhs._M_filebuf);
626 __istream_type::swap(__rhs);
627 _M_filebuf.swap(__rhs._M_filebuf);
648 {
return _M_filebuf.
is_open(); }
654 {
return _M_filebuf.
is_open(); }
675#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
694#if __cplusplus >= 201103L
714#if __cplusplus >= 201703L
723 template<
typename _Path>
724 _If_fs_path<_Path, void>
726 {
open(__s.c_str(), __mode); }
739 if (!_M_filebuf.
close())
759 template<
typename _CharT,
typename _Traits>
764 typedef _CharT char_type;
765 typedef _Traits traits_type;
766 typedef typename traits_type::int_type int_type;
767 typedef typename traits_type::pos_type pos_type;
768 typedef typename traits_type::off_type off_type;
787 { this->
init(&_M_filebuf); }
801 this->
init(&_M_filebuf);
802 this->
open(__s, __mode);
805#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
816 : __ostream_type(), _M_filebuf()
818 this->
init(&_M_filebuf);
819 this->
open(__s, __mode);
823#if __cplusplus >= 201103L
836 this->
init(&_M_filebuf);
837 this->
open(__s, __mode);
840#if __cplusplus >= 201703L
848 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
858 : __ostream_type(
std::move(__rhs)),
859 _M_filebuf(
std::move(__rhs._M_filebuf))
860 { __ostream_type::set_rdbuf(&_M_filebuf); }
872#if __cplusplus >= 201103L
881 __ostream_type::operator=(
std::move(__rhs));
882 _M_filebuf =
std::move(__rhs._M_filebuf);
889 __ostream_type::swap(__rhs);
890 _M_filebuf.swap(__rhs._M_filebuf);
911 {
return _M_filebuf.
is_open(); }
917 {
return _M_filebuf.
is_open(); }
938#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
957#if __cplusplus >= 201103L
977#if __cplusplus >= 201703L
986 template<
typename _Path>
987 _If_fs_path<_Path, void>
989 {
open(__s.c_str(), __mode); }
1002 if (!_M_filebuf.
close())
1022 template<
typename _CharT,
typename _Traits>
1027 typedef _CharT char_type;
1028 typedef _Traits traits_type;
1029 typedef typename traits_type::int_type int_type;
1030 typedef typename traits_type::pos_type pos_type;
1031 typedef typename traits_type::off_type off_type;
1052 { this->
init(&_M_filebuf); }
1064 this->
init(&_M_filebuf);
1065 this->
open(__s, __mode);
1068#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1076 : __iostream_type(0), _M_filebuf()
1078 this->
init(&_M_filebuf);
1079 this->
open(__s, __mode);
1083#if __cplusplus >= 201103L
1094 this->
init(&_M_filebuf);
1095 this->
open(__s, __mode);
1098#if __cplusplus >= 201703L
1104 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
1114 : __iostream_type(
std::move(__rhs)),
1115 _M_filebuf(
std::move(__rhs._M_filebuf))
1116 { __iostream_type::set_rdbuf(&_M_filebuf); }
1128#if __cplusplus >= 201103L
1137 __iostream_type::operator=(
std::move(__rhs));
1138 _M_filebuf =
std::move(__rhs._M_filebuf);
1145 __iostream_type::swap(__rhs);
1146 _M_filebuf.swap(__rhs._M_filebuf);
1167 {
return _M_filebuf.
is_open(); }
1173 {
return _M_filebuf.
is_open(); }
1187 if (!_M_filebuf.
open(__s, __mode))
1195#if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1205 open(
const wchar_t* __s,
1208 if (!_M_filebuf.
open(__s, __mode))
1215#if __cplusplus >= 201103L
1228 if (!_M_filebuf.
open(__s, __mode))
1236#if __cplusplus >= 201703L
1245 template<
typename _Path>
1246 _If_fs_path<_Path, void>
1249 {
open(__s.c_str(), __mode); }
1262 if (!_M_filebuf.
close())
1267#if __cplusplus >= 201103L
1269 template <
class _CharT,
class _Traits>
1276 template <
class _CharT,
class _Traits>
1283 template <
class _CharT,
class _Traits>
1290 template <
class _CharT,
class _Traits>
1297_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.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
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...
Container class for localization functionality.
Class representing stream positions.