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;
171 const __codecvt_type* _M_codecvt;
203 _M_pback_cur_save = this->
gptr();
204 _M_pback_end_save = this->
egptr();
205 this->
setg(&_M_pback, &_M_pback, &_M_pback + 1);
206 _M_pback_init =
true;
221 _M_pback_cur_save += this->
gptr() != this->
eback();
222 this->
setg(_M_buf, _M_pback_cur_save, _M_pback_end_save);
223 _M_pback_init =
false;
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*
416 seekoff(off_type __off, ios_base::seekdir __way,
425 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
428 _M_get_ext_pos(__state_type &__state);
444 _M_terminate_output();
465 if (__testin && __off > 0)
466 this->
setg(_M_buf, _M_buf, _M_buf + __off);
468 this->
setg(_M_buf, _M_buf, _M_buf);
470 if (__testout && __off == 0 && _M_buf_size > 1 )
471 this->
setp(_M_buf, _M_buf + _M_buf_size - 1);
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;
507 __filebuf_type _M_filebuf;
519 { this->init(&_M_filebuf); }
530 : __istream_type(), _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 564 : __istream_type(), _M_filebuf()
566 this->init(&_M_filebuf);
567 this->
open(__s, __mode);
570 #if __cplusplus >= 201703L 578 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
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);
620 _M_filebuf.swap(__rhs._M_filebuf);
633 {
return const_cast<__filebuf_type*
>(&_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;
768 __filebuf_type _M_filebuf;
780 { this->init(&_M_filebuf); }
792 : __ostream_type(), _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 827 : __ostream_type(), _M_filebuf()
829 this->init(&_M_filebuf);
830 this->
open(__s, __mode);
833 #if __cplusplus >= 201703L 841 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
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);
883 _M_filebuf.swap(__rhs._M_filebuf);
896 {
return const_cast<__filebuf_type*
>(&_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;
1032 __filebuf_type _M_filebuf;
1044 : __iostream_type(), _M_filebuf()
1045 { this->init(&_M_filebuf); }
1055 : __iostream_type(0), _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 1085 : __iostream_type(0), _M_filebuf()
1087 this->init(&_M_filebuf);
1088 this->
open(__s, __mode);
1091 #if __cplusplus >= 201703L 1097 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
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);
1139 _M_filebuf.swap(__rhs._M_filebuf);
1152 {
return const_cast<__filebuf_type*
>(&_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
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
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.
Primary class template codecvt.NB: Generic, mostly useless implementation.
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
bool is_open() const
Returns true if the external file is open.
void setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
void open(const char *__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
void open(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
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_ostream.
char_type * eback() const
Access to the get area.
Template class basic_ios, virtual base class for all stream classes.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
bool is_open()
Wrapper to test for an open file.
Controlling input and output for files.
void _M_set_buffer(streamsize __off)
char_type * _M_pback_end_save
The actual work of input and output (for files).
Template class basic_istream.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
virtual int_type pbackfail(int_type __c=_Traits::eof())
Tries to back up the input sequence.
streamsize _M_ext_buf_size
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
Controlling output for files.
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
__filebuf_type * open(const std::string &__s, ios_base::openmode __mode)
Opens an external file.
Template class basic_iostream.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
static const openmode app
Seek to end before each write.
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current filebuf.
basic_filebuf()
Does not open any files.
virtual int_type underflow()
Fetches more data from the controlled sequence.
virtual int_type overflow(int_type __c=_Traits::eof())
Consumes data from the buffer; writes to the controlled sequence.
~basic_ofstream()
The destructor does nothing.
virtual void imbue(const locale &__loc)
Changes translations.
void swap(basic_fstream< _CharT, _Traits > &__x, basic_fstream< _CharT, _Traits > &__y)
Swap specialization for fstreams.
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
basic_ofstream()
Default constructor.
basic_fstream(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
virtual streamsize showmanyc()
Investigating the data available.
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
basic_ifstream()
Default constructor.
~basic_ifstream()
The destructor does nothing.
void close()
Close the file.
bool is_open()
Wrapper to test for an open file.
virtual ~basic_filebuf()
The destructor closes the file first.
ISO C++ entities toplevel namespace is std.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
char_type * _M_buf
Pointer to the beginning of internal buffer.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
static const openmode out
Open for output. Default for ofstream and fstream.
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.
__filebuf_type * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
~basic_fstream()
The destructor does nothing.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
void open(const char *__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
char_type * gptr() const
Access to the get area.
Class representing stream positions.
static const openmode in
Open for input. Default for ifstream and fstream.
The actual work of input and output (interface).
void close()
Close the file.
basic_fstream()
Default constructor.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
char_type * _M_pback_cur_save
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
__filebuf_type * close()
Closes the currently associated file.
Controlling input for files.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
char_type * egptr() const
Access to the get area.