Go to the documentation of this file.
33 #ifndef _GLIBCXX_FSTREAM
34 #define _GLIBCXX_FSTREAM 1
36 #ifdef _GLIBCXX_SYSHDR
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
59 namespace 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;
216 _M_pback_end_save = this->
egptr();
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
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 // C++ >= 26
386 using native_handle_type =
typename __file_type::native_handle_type;
397 [[__gnu__::__always_inline__]]
399 native_handle() const noexcept
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);
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)
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 // C++ >= 26
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 // C++ >= 26
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;
1112 { this->init(&_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
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 // C++ >= 26
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
Controlling output for files.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
char_type * eback() const
Access to the get area.
The actual work of input and output (for files).
virtual int_type underflow()
Fetches more data from the controlled sequence.
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
Template class basic_ostream.
virtual void imbue(const locale &__loc)
Changes translations.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
basic_filebuf()
Does not open any files.
virtual int_type overflow(int_type __c=_Traits::eof())
Consumes data from the buffer; writes to the controlled sequence.
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
static const openmode app
Seek to end before each write.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
__filebuf_type * close()
Closes the currently associated file.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
virtual ~basic_filebuf()
The destructor closes the file first.
static const openmode in
Open for input. Default for ifstream and fstream.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current filebuf.
void open(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
char_type * _M_pback_cur_save
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
static const openmode out
Open for output. Default for ofstream and fstream.
Primary class template codecvt.
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::out)
Opens an external file.
Template class basic_istream.
~basic_ifstream()
The destructor does nothing.
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)
Opens an external file.
basic_ifstream(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
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.
Template class basic_ios, virtual base class for all stream classes.
char_type * egptr() const
Access to the get area.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
Template class basic_iostream.
ISO C++ entities toplevel namespace is std.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
_If_fs_path< _Path, __filebuf_type * > open(const _Path &__s, ios_base::openmode __mode)
Opens an external file.
The actual work of input and output (interface).
streamsize _M_ext_buf_size
basic_ofstream()
Default constructor.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
~basic_ofstream()
The destructor does nothing.
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
void swap(basic_fstream< _CharT, _Traits > &__x, basic_fstream< _CharT, _Traits > &__y)
Swap specialization for fstreams.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
basic_ifstream()
Default constructor.
basic_fstream()
Default constructor.
void close()
Close the file.
The base of the I/O class hierarchy.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
Class representing stream positions.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
bool is_open()
Wrapper to test for an open file.
bool is_open()
Wrapper to test for an open file.
void close()
Close the file.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
void close()
Close the file.
basic_ofstream(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
char_type * gptr() const
Access to the get area.
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
void _M_set_buffer(streamsize __off)
char_type * _M_pback_end_save
Controlling input and output for files.
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
bool is_open() const
Returns true if the external file is open.
char_type * _M_buf
Pointer to the beginning of internal buffer.
~basic_fstream()
The destructor does nothing.
virtual int_type pbackfail(int_type __c=_Traits::eof())
Tries to back up the input sequence.
bool is_open()
Wrapper to test for an open file.
Controlling input for files.
virtual streamsize showmanyc()
Investigating the data available.
__filebuf_type * open(const std::string &__s, ios_base::openmode __mode)
Opens an external file.
basic_fstream(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.