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
52 namespace std _GLIBCXX_VISIBILITY(default)
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
56 #if __cplusplus >= 201703L
58 template<
typename _Path,
typename _Result = _Path,
typename _Path2
59 = decltype(std::declval<_Path&>().make_preferred().filename())>
60 using _If_fs_path = enable_if_t<is_same_v<_Path, _Path2>, _Result>;
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;
129 __state_type _M_state_beg;
134 __state_type _M_state_cur;
138 __state_type _M_state_last;
151 bool _M_buf_allocated;
170 char_type* _M_pback_cur_save;
171 char_type* _M_pback_end_save;
208 _M_pback_cur_save = this->gptr();
209 _M_pback_end_save = this->egptr();
211 _M_pback_init =
true;
226 _M_pback_cur_save += this->gptr() != this->
eback();
227 this->
setg(_M_buf, _M_pback_cur_save, _M_pback_end_save);
228 _M_pback_init =
false;
242 #if __cplusplus >= 201103L
259 #if __cplusplus >= 201103L
271 {
return _M_file.is_open(); }
315 open(
const char* __s, ios_base::openmode __mode);
317 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
325 open(
const wchar_t* __s, ios_base::openmode __mode);
328 #if __cplusplus >= 201103L
339 #if __cplusplus >= 201703L
346 template<
typename _Path>
347 _If_fs_path<_Path, __filebuf_type*>
348 open(
const _Path& __s, ios_base::openmode __mode)
349 {
return open(__s.c_str(), __mode); }
370 _M_allocate_internal_buffer();
373 _M_destroy_internal_buffer() throw();
388 pbackfail(int_type __c = _Traits::eof());
398 overflow(int_type __c = _Traits::eof());
403 _M_convert_to_external(char_type*,
streamsize);
417 virtual __streambuf_type*
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;
524 { this->
init(&_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
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
617 _M_filebuf =
std::move(__rhs._M_filebuf);
625 _M_filebuf.swap(__rhs._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;
785 { this->
init(&_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
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
880 _M_filebuf =
std::move(__rhs._M_filebuf);
888 _M_filebuf.swap(__rhs._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;
1050 { this->
init(&_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
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);
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
auto_ptr & operator=(auto_ptr &__a)
auto_ptr assignment operator.
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.
void swap(basic_fstream< _CharT, _Traits > &__x, basic_fstream< _CharT, _Traits > &__y)
Swap specialization for fstreams.
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)
Alters the stream positions.
virtual int_type underflow()
Fetches more data from the controlled sequence.
virtual streamsize showmanyc()
Investigating the data available.
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
virtual void imbue(const locale &__loc)
Changes translations.
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
_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.
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
char_type * _M_buf
Pointer to the beginning of internal buffer.
virtual int_type pbackfail(int_type __c=_Traits::eof())
Tries to back up the input sequence.
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
virtual int_type overflow(int_type __c=_Traits::eof())
Consumes data from the buffer; writes to the controlled sequence.
__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 int sync()
Synchronizes the buffer arrays with the controlled sequences.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
Controlling input for files.
basic_ifstream()
Default constructor.
~basic_ifstream()
The destructor does nothing.
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
_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.
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.
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.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
_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.
~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.
bool is_open()
Wrapper to test for an open file.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external 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).
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.
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
Template class basic_istream.
void swap(basic_istream &__rhs)
Simple extraction.
basic_istream & operator=(const basic_istream &)=delete
Simple extraction.
Template class basic_ostream.
void swap(basic_ostream &__rhs)
Simple insertion.
basic_ostream & operator=(const basic_ostream &)=delete
Simple insertion.
Template class basic_iostream.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Primary class template codecvt.
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.