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;
183 const __codecvt_type* _M_codecvt;
215 _M_pback_cur_save = this->
gptr();
216 _M_pback_end_save = this->
egptr();
217 this->
setg(&_M_pback, &_M_pback, &_M_pback + 1);
218 _M_pback_init =
true;
233 _M_pback_cur_save += this->
gptr() != this->
eback();
234 this->
setg(_M_buf, _M_pback_cur_save, _M_pback_end_save);
235 _M_pback_init =
false;
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,
468 _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state);
471 _M_get_ext_pos(__state_type &__state);
487 _M_terminate_output();
508 if (__testin && __off > 0)
509 this->
setg(_M_buf, _M_buf, _M_buf + __off);
511 this->
setg(_M_buf, _M_buf, _M_buf);
513 if (__testout && __off == 0 && _M_buf_size > 1 )
514 this->
setp(_M_buf, _M_buf + _M_buf_size - 1);
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;
550 __filebuf_type _M_filebuf;
562 { this->init(&_M_filebuf); }
573 : __istream_type(), _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 607 : __istream_type(), _M_filebuf()
609 this->init(&_M_filebuf);
610 this->
open(__s, __mode);
613 #if __cplusplus >= 201703L 621 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
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);
663 _M_filebuf.swap(__rhs._M_filebuf);
677 {
return const_cast<__filebuf_type*
>(&_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;
823 __filebuf_type _M_filebuf;
835 { this->init(&_M_filebuf); }
847 : __ostream_type(), _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 882 : __ostream_type(), _M_filebuf()
884 this->init(&_M_filebuf);
885 this->
open(__s, __mode);
888 #if __cplusplus >= 201703L 896 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
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);
938 _M_filebuf.swap(__rhs._M_filebuf);
952 {
return const_cast<__filebuf_type*
>(&_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;
1099 __filebuf_type _M_filebuf;
1111 : __iostream_type(), _M_filebuf()
1112 { this->init(&_M_filebuf); }
1122 : __iostream_type(0), _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 1152 : __iostream_type(0), _M_filebuf()
1154 this->init(&_M_filebuf);
1155 this->
open(__s, __mode);
1158 #if __cplusplus >= 201703L 1164 template<
typename _Path,
typename _Require = _If_fs_path<_Path>>
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);
1206 _M_filebuf.swap(__rhs._M_filebuf);
1220 {
return const_cast<__filebuf_type*
>(&_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
The actual work of input and output (for files).
~basic_fstream()
The destructor does nothing.
bool is_open()
Wrapper to test for an open file.
static const openmode app
Seek to end before each write.
char_type * egptr() const
Access to the get area.
char_type * eback() const
Access to the get area.
Controlling output for files.
basic_ifstream(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
static const openmode in
Open for input. Default for ifstream and fstream.
bool is_open()
Wrapper to test for an open file.
basic_ofstream(const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
char_type * _M_pback_cur_save
bool is_open() const
Returns true if the external file is open.
virtual int_type pbackfail(int_type __c=_Traits::eof())
Tries to back up the input sequence.
void close()
Close the file.
char_type * _M_buf
Pointer to the beginning of internal buffer.
basic_fstream(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
basic_filebuf()
Does not open any files.
virtual int sync()
Synchronizes the buffer arrays with the controlled sequences.
static const openmode out
Open for output. Default for ofstream and fstream.
void close()
Close the file.
void open(const char *__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 * open(const char *__s, ios_base::openmode __mode)
Opens an external file.
~basic_ifstream()
The destructor does nothing.
virtual streamsize xsputn(const char_type *__s, streamsize __n)
Multiple character insertion.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::in)
Opens an external file.
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
basic_ifstream(const char *__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
void _M_set_buffer(streamsize __off)
basic_fstream()
Default constructor.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Opens an external file.
Template class basic_ostream.
basic_ofstream()
Default constructor.
virtual __streambuf_type * setbuf(char_type *__s, streamsize __n)
Manipulates the buffer.
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.
virtual streamsize showmanyc()
Investigating the data available.
static const openmode trunc
Truncate an existing stream when opening. Default for ofstream.
Container class for localization functionality.The locale class is first a class wrapper for C librar...
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
__filebuf_type * rdbuf() const
Accessing the underlying buffer.
The base of the I/O class hierarchy.This class defines everything that can be defined about I/O that ...
ios_base::openmode _M_mode
Place to stash in || out || in | out settings for current filebuf.
__filebuf_type * close()
Closes the currently associated file.
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 setg(char_type *__gbeg, char_type *__gnext, char_type *__gend)
Setting the three read area pointers.
basic_ifstream(const _Path &__s, ios_base::openmode __mode=ios_base::in)
Create an input file stream.
Template class basic_ios, virtual base class for all stream classes.
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode=ios_base::in|ios_base::out)
Alters the stream positions.
void open(const char *__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
streamsize _M_ext_buf_size
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
~basic_ofstream()
The destructor does nothing.
void open(const std::string &__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.
basic_fstream(const std::string &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
virtual int_type overflow(int_type __c=_Traits::eof())
Consumes data from the buffer; writes to the controlled sequence.
void setp(char_type *__pbeg, char_type *__pend)
Setting the three write area pointers.
Template class basic_istream.
void swap(basic_fstream< _CharT, _Traits > &__x, basic_fstream< _CharT, _Traits > &__y)
Swap specialization for fstreams.
basic_ifstream()
Default constructor.
basic_ofstream(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
void close()
Close the file.
virtual streamsize xsgetn(char_type *__s, streamsize __n)
Multiple character extraction.
ptrdiff_t streamsize
Integral type for I/O operation counts and buffer sizes.
void open(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
virtual void imbue(const locale &__loc)
Changes translations.
Class representing stream positions.
Template class basic_iostream.
basic_ofstream(const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
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.
The actual work of input and output (interface).
__filebuf_type * open(const std::string &__s, ios_base::openmode __mode)
Opens an external file.
Primary class template codecvt.NB: Generic, mostly useless implementation.
Controlling input for files.
basic_fstream(const char *__s, ios_base::openmode __mode=ios_base::in|ios_base::out)
Create an input/output file stream.
virtual ~basic_filebuf()
The destructor closes the file first.
char_type * _M_pback_end_save
virtual int_type underflow()
Fetches more data from the controlled sequence.
_If_fs_path< _Path, void > open(const _Path &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
Controlling input and output for files.
char_type * gptr() const
Access to the get area.