33 #ifndef _GLIBCXX_FSTREAM
34 #define _GLIBCXX_FSTREAM 1
36 #pragma GCC system_header
43 #if __cplusplus >= 201103L
47 namespace std _GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
51 #if __cplusplus >= 201703L
53 template<
typename _Path,
typename _Result = _Path,
typename _Path2
54 = decltype(std::declval<_Path&>().make_preferred().filename())>
55 using _If_fs_path = enable_if_t<is_same_v<_Path, _Path2>, _Result>;
79 template<
typename _CharT,
typename _Traits>
82 #if __cplusplus >= 201103L
83 template<
typename _Tp>
84 using __chk_state = __and_<is_copy_assignable<_Tp>,
88 static_assert(__chk_state<typename _Traits::state_type>::value,
89 "state_type must be CopyAssignable, CopyConstructible"
90 " and DefaultConstructible");
92 static_assert(
is_same<
typename _Traits::pos_type,
94 "pos_type must be fpos<state_type>");
98 typedef _CharT char_type;
99 typedef _Traits traits_type;
100 typedef typename traits_type::int_type int_type;
101 typedef typename traits_type::pos_type pos_type;
102 typedef typename traits_type::off_type off_type;
106 typedef __basic_file<char> __file_type;
107 typedef typename traits_type::state_type __state_type;
124 __state_type _M_state_beg;
129 __state_type _M_state_cur;
133 __state_type _M_state_last;
146 bool _M_buf_allocated;
237 #if __cplusplus >= 201103L
254 #if __cplusplus >= 201103L
266 {
return _M_file.is_open(); }
310 open(
const char* __s, ios_base::openmode __mode);
312 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
320 open(
const wchar_t* __s, ios_base::openmode __mode);
323 #if __cplusplus >= 201103L
334 #if __cplusplus >= 201703L
341 template<
typename _Path>
342 _If_fs_path<_Path, __filebuf_type*>
343 open(
const _Path& __s, ios_base::openmode __mode)
344 {
return open(__s.c_str(), __mode); }
365 _M_allocate_internal_buffer();
368 _M_destroy_internal_buffer() throw();
383 pbackfail(int_type __c = _Traits::eof());
393 overflow(int_type __c = _Traits::eof());
398 _M_convert_to_external(char_type*,
streamsize);
412 virtual __streambuf_type*
413 setbuf(char_type* __s, streamsize __n);
416 seekoff(off_type __off, ios_base::seekdir __way,
417 ios_base::openmode __mode = ios_base::in | ios_base::out);
421 ios_base::openmode __mode = ios_base::in | ios_base::out);
425 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
428 _M_get_ext_pos(__state_type &__state);
434 imbue(const locale& __loc);
437 xsgetn(char_type* __s, streamsize __n);
440 xsputn(const char_type* __s, streamsize __n);
444 _M_terminate_output();
465 if (__testin && __off > 0)
491 template<
typename _CharT,
typename _Traits>
496 typedef _CharT char_type;
497 typedef _Traits traits_type;
498 typedef typename traits_type::int_type int_type;
499 typedef typename traits_type::pos_type pos_type;
500 typedef typename traits_type::off_type off_type;
519 { this->
init(&_M_filebuf); }
532 this->
init(&_M_filebuf);
533 this->
open(__s, __mode);
536 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
546 : __istream_type(), _M_filebuf()
548 this->
init(&_M_filebuf);
549 this->
open(__s, __mode);
553 #if __cplusplus >= 201103L
566 this->
init(&_M_filebuf);
567 this->
open(__s, __mode);
570 #if __cplusplus >= 201703L
578 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
588 : __istream_type(std::move(__rhs)),
589 _M_filebuf(std::move(__rhs._M_filebuf))
590 { __istream_type::set_rdbuf(&_M_filebuf); }
602 #if __cplusplus >= 201103L
611 __istream_type::operator=(
std::move(__rhs));
612 _M_filebuf =
std::move(__rhs._M_filebuf);
619 __istream_type::swap(__rhs);
620 _M_filebuf.swap(__rhs._M_filebuf);
641 {
return _M_filebuf.
is_open(); }
647 {
return _M_filebuf.
is_open(); }
668 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
687 #if __cplusplus >= 201103L
707 #if __cplusplus >= 201703L
716 template<
typename _Path>
717 _If_fs_path<_Path, void>
719 {
open(__s.c_str(), __mode); }
732 if (!_M_filebuf.
close())
752 template<
typename _CharT,
typename _Traits>
757 typedef _CharT char_type;
758 typedef _Traits traits_type;
759 typedef typename traits_type::int_type int_type;
760 typedef typename traits_type::pos_type pos_type;
761 typedef typename traits_type::off_type off_type;
780 { this->
init(&_M_filebuf); }
794 this->
init(&_M_filebuf);
795 this->
open(__s, __mode);
798 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
809 : __ostream_type(), _M_filebuf()
811 this->
init(&_M_filebuf);
812 this->
open(__s, __mode);
816 #if __cplusplus >= 201103L
829 this->
init(&_M_filebuf);
830 this->
open(__s, __mode);
833 #if __cplusplus >= 201703L
841 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
851 : __ostream_type(std::move(__rhs)),
852 _M_filebuf(std::move(__rhs._M_filebuf))
853 { __ostream_type::set_rdbuf(&_M_filebuf); }
865 #if __cplusplus >= 201103L
874 __ostream_type::operator=(
std::move(__rhs));
875 _M_filebuf =
std::move(__rhs._M_filebuf);
882 __ostream_type::swap(__rhs);
883 _M_filebuf.swap(__rhs._M_filebuf);
904 {
return _M_filebuf.
is_open(); }
910 {
return _M_filebuf.
is_open(); }
931 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
950 #if __cplusplus >= 201103L
970 #if __cplusplus >= 201703L
979 template<
typename _Path>
980 _If_fs_path<_Path, void>
982 {
open(__s.c_str(), __mode); }
995 if (!_M_filebuf.
close())
1015 template<
typename _CharT,
typename _Traits>
1020 typedef _CharT char_type;
1021 typedef _Traits traits_type;
1022 typedef typename traits_type::int_type int_type;
1023 typedef typename traits_type::pos_type pos_type;
1024 typedef typename traits_type::off_type off_type;
1045 { this->
init(&_M_filebuf); }
1057 this->
init(&_M_filebuf);
1058 this->
open(__s, __mode);
1061 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1069 : __iostream_type(0), _M_filebuf()
1071 this->
init(&_M_filebuf);
1072 this->
open(__s, __mode);
1076 #if __cplusplus >= 201103L
1087 this->
init(&_M_filebuf);
1088 this->
open(__s, __mode);
1091 #if __cplusplus >= 201703L
1097 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
1107 : __iostream_type(std::move(__rhs)),
1108 _M_filebuf(std::move(__rhs._M_filebuf))
1109 { __iostream_type::set_rdbuf(&_M_filebuf); }
1121 #if __cplusplus >= 201103L
1130 __iostream_type::operator=(
std::move(__rhs));
1131 _M_filebuf =
std::move(__rhs._M_filebuf);
1138 __iostream_type::swap(__rhs);
1139 _M_filebuf.swap(__rhs._M_filebuf);
1160 {
return _M_filebuf.
is_open(); }
1166 {
return _M_filebuf.
is_open(); }
1180 if (!_M_filebuf.
open(__s, __mode))
1188 #if _GLIBCXX_HAVE__WFOPEN && _GLIBCXX_USE_WCHAR_T
1198 open(
const wchar_t* __s,
1201 if (!_M_filebuf.
open(__s, __mode))
1208 #if __cplusplus >= 201103L
1221 if (!_M_filebuf.
open(__s, __mode))
1229 #if __cplusplus >= 201703L
1238 template<
typename _Path>
1239 _If_fs_path<_Path, void>
1240 open(
const _Path& __s,
1242 {
open(__s.c_str(), __mode); }
1255 if (!_M_filebuf.
close())
1260 #if __cplusplus >= 201103L
1262 template <
class _CharT,
class _Traits>
1269 template <
class _CharT,
class _Traits>
1276 template <
class _CharT,
class _Traits>
1283 template <
class _CharT,
class _Traits>
1290 _GLIBCXX_END_NAMESPACE_VERSION
The actual work of input and output (for files).
bool is_open()
Wrapper to test for an open file.
~basic_ifstream()
The destructor does nothing.
Controlling output for files.
Class representing stream positions.
char_type * egptr() const
Access to the get area.
basic_fstream(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
char_type * eback() const
Access to the get area.
char_type * _M_pback_end_save
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
Primary class template codecvt.NB: Generic, mostly useless implementation.
char_type * _M_buf
Pointer to the beginning of internal buffer.
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
basic_fstream()
Default constructor.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
void open(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
streamsize _M_ext_buf_size
static const openmode app
Seek to end before each write.
~basic_fstream()
The destructor does nothing.
Template class basic_istream.
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
~basic_ofstream()
The destructor does nothing.
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
bool is_open()
Wrapper to test for an open file.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current filebuf.
void clear(iostate __state=goodbit)
[Re]sets the error state.
Controlling input for files.
static const openmode in
Open for input. Default for ifstream and fstream.
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
void _M_set_buffer(streamsize __off)
bool is_open()
Wrapper to test for an open file.
void close()
Close the file.
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
The actual work of input and output (interface).
basic_ifstream()
Default constructor.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
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.
void close()
Close the file.
bool is_open() const
Returns true if the external file is open.
static const openmode out
Open for output. Default for ofstream and fstream.
virtual streamsize showmanyc()
Investigating the data available.
Template class basic_iostream.
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
virtual int_type underflow()
Fetches more data from the controlled sequence.
__filebuf_type * close()
Closes the currently associated file.
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
virtual ~basic_filebuf()
The destructor closes the file first.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
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.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
basic_filebuf()
Does not open any files.
basic_ofstream()
Default constructor.
void close()
Close the file.
Controlling input and output for files.
char_type * _M_pback_cur_save
void open(const char *__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
__filebuf_type * open(const std::string &__s, ios_base::openmode __mode)
Opens an external file.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
virtual void imbue(const locale &__loc)
Changes translations.
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
Template class basic_ios, virtual base class for all stream classes.
Template class basic_ostream.
void setstate(iostate __state)
Sets additional flags in the error state.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
void init(basic_streambuf< _CharT, _Traits > *__sb)
All setup is performed here.
basic_fstream(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
char_type * gptr() const
Access to the get area.