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;
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*
418 setbuf(char_type* __s, streamsize __n);
430 _M_seek(off_type __off,
ios_base::seekdir __way, __state_type __state);
433 _M_get_ext_pos(__state_type &__state);
442 xsgetn(char_type* __s, streamsize __n);
445 xsputn(const char_type* __s, streamsize __n);
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
616 __istream_type::operator=(
std::move(__rhs));
617 _M_filebuf =
std::move(__rhs._M_filebuf);
624 __istream_type::swap(__rhs);
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
879 __ostream_type::operator=(
std::move(__rhs));
880 _M_filebuf =
std::move(__rhs._M_filebuf);
887 __ostream_type::swap(__rhs);
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
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
basic_fstream()
Default constructor.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current filebuf.
void close()
Close the file.
_If_fs_path< _Path, __filebuf_type * > open(const _Path &__s, ios_base::openmode __mode)
Opens an external file.
Template class basic_iostream.
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
char_type * eback() const
Access to the get area.
char_type * _M_buf
Pointer to the beginning of internal buffer.
virtual ~basic_filebuf()
The destructor closes the file first.
basic_fstream(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
~basic_ifstream()
The destructor does nothing.
Controlling output for files.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
char_type * _M_pback_cur_save
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
streamsize _M_ext_buf_size
Controlling input and output for files.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
basic_ofstream()
Default constructor.
Template class basic_ios, virtual base class for all stream classes.
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
~basic_fstream()
The destructor does nothing.
basic_filebuf()
Does not open any files.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
Class representing stream positions.
The actual work of input and output (interface).
virtual int_type underflow()
Fetches more data from the controlled sequence.
Primary class template codecvt.NB: Generic, mostly useless implementation.
__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|ios_base::out)
Opens an external file.
void clear(iostate __state=goodbit)
[Re]sets the error state.
void close()
Close the file.
char_type * egptr() const
Access to the get area.
bool is_open()
Wrapper to test for an open file.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
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.
__filebuf_type * close()
Closes the currently associated file.
virtual streamsize showmanyc()
Investigating the data available.
basic_ifstream()
Default constructor.
The actual work of input and output (for files).
~basic_ofstream()
The destructor does nothing.
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.
bool is_open()
Wrapper to test for an open file.
void open(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external 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.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
static const openmode out
Open for output. Default for ofstream and fstream.
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
char_type * gptr() const
Access to the get area.
Template class basic_istream.
basic_ifstream(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
void _M_set_buffer(streamsize __off)
bool is_open() const
Returns true if the external file is open.
Template class basic_ostream.
basic_fstream(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
virtual void imbue(const locale &__loc)
Changes translations.
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
bool is_open()
Wrapper to test for an open file.
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
static const openmode app
Seek to end before each write.
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.
Controlling input for files.
static const openmode in
Open for input. Default for ifstream and fstream.
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
void close()
Close the file.
char_type * _M_pback_end_save
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
void setstate(iostate __state)
Sets additional flags in the error state.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.