This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

102
cppdraft/filebuf/general.md Normal file
View File

@@ -0,0 +1,102 @@
[filebuf.general]
# 31 Input/output library [[input.output]](./#input.output)
## 31.10 File-based streams [[file.streams]](file.streams#filebuf.general)
### 31.10.3 Class template basic_filebuf [[filebuf]](filebuf#general)
#### 31.10.3.1 General [filebuf.general]
[🔗](#lib:basic_filebuf)
namespace std {template<class charT, class traits = char_traits<charT>>class basic_filebuf : public basic_streambuf<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using native_handle_type = *implementation-defined*; // see [[file.native]](file.native "31.10.2Native handles")// [[filebuf.cons]](filebuf.cons "31.10.3.2Constructors"), constructors/destructor basic_filebuf();
basic_filebuf(const basic_filebuf&) = delete;
basic_filebuf(basic_filebuf&& rhs); virtual ~basic_filebuf(); // [[filebuf.assign]](filebuf.assign "31.10.3.3Assignment and swap"), assignment and swap basic_filebuf& operator=(const basic_filebuf&) = delete;
basic_filebuf& operator=(basic_filebuf&& rhs); void swap(basic_filebuf& rhs); // [[filebuf.members]](filebuf.members "31.10.3.4Member functions"), membersbool is_open() const;
basic_filebuf* open(const char* s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path::value_type* s,
ios_base::openmode mode); // wide systems only; see [[fstream.syn]](fstream.syn "31.10.1Header <fstream> synopsis") basic_filebuf* open(const string& s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path& s, ios_base::openmode mode);
basic_filebuf* close();
native_handle_type native_handle() const noexcept; protected:// [[filebuf.virtuals]](filebuf.virtuals "31.10.3.5Overridden virtual functions"), overridden virtual functions streamsize showmanyc() override;
int_type underflow() override;
int_type uflow() override;
int_type pbackfail(int_type c = traits::eof()) override;
int_type overflow (int_type c = traits::eof()) override;
basic_streambuf<charT, traits>* setbuf(char_type* s, streamsize n) override;
pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out) override;
pos_type seekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out) override; int sync() override; void imbue(const locale& loc) override; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11028)
The classbasic_filebuf<charT, traits> associates both the input sequence and the output
sequence with a file[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11034)
The restrictions on reading and writing a sequence controlled by an
object of classbasic_filebuf<charT, traits> are the same as for reading and writing with the C standard libraryFILEs[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11041)
In particular:
- [(3.1)](#3.1)
If the file is not open for reading the input sequence
cannot be read[.](#3.1.sentence-1)
- [(3.2)](#3.2)
If the file is not open for writing the output
sequence cannot be written[.](#3.2.sentence-1)
- [(3.3)](#3.3)
A joint file position is maintained for both the input sequence and
the output sequence[.](#3.3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11055)
An instance ofbasic_filebuf behaves as described in [[filebuf]](filebuf "31.10.3Class template basic_­filebuf") providedtraits::pos_type isfpos<traits::state_type>[.](#4.sentence-1)
Otherwise the behavior is undefined[.](#4.sentence-2)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11064)
The file associated with a basic_filebuf has
an associated value of type native_handle_type,
called the native handle ([[file.native]](file.native "31.10.2Native handles")) of that file[.](#5.sentence-1)
This native handle can be obtained by calling
the member function native_handle[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11071)
For any opened basic_filebuf f,
the native handle returned by f.native_handle() is
invalidated when f.close() is called, or f is destroyed[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L11076)
In order to support file I/O and multibyte/wide character conversion,
conversions are performed using members of a facet, referred to asa_codecvt in following subclauses, obtained as if byconst codecvt<charT, char, typename traits::state_type>& a_codecvt = use_facet<codecvt<charT, char, typename traits::state_type>>(getloc());