- tmp/tmpuwgzuze3/{from.md → to.md} +403 -29
tmp/tmpuwgzuze3/{from.md → to.md}
RENAMED
|
@@ -1,53 +1,58 @@
|
|
| 1 |
-
###
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
template <class charT, class traits = char_traits<charT>>
|
| 6 |
class basic_filebuf : public basic_streambuf<charT, traits> {
|
| 7 |
public:
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
// [filebuf.cons]
|
| 15 |
basic_filebuf();
|
| 16 |
basic_filebuf(const basic_filebuf& rhs) = delete;
|
| 17 |
basic_filebuf(basic_filebuf&& rhs);
|
| 18 |
virtual ~basic_filebuf();
|
| 19 |
|
| 20 |
-
// [filebuf.assign]
|
| 21 |
basic_filebuf& operator=(const basic_filebuf& rhs) = delete;
|
| 22 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 23 |
void swap(basic_filebuf& rhs);
|
| 24 |
|
| 25 |
-
|
| 26 |
bool is_open() const;
|
| 27 |
-
basic_filebuf
|
|
|
|
|
|
|
|
|
|
| 28 |
ios_base::openmode mode);
|
| 29 |
-
basic_filebuf
|
| 30 |
ios_base::openmode mode);
|
| 31 |
-
basic_filebuf
|
| 32 |
|
| 33 |
protected:
|
| 34 |
-
// [filebuf.virtuals]
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
};
|
| 50 |
|
| 51 |
template <class charT, class traits>
|
| 52 |
void swap(basic_filebuf<charT, traits>& x,
|
| 53 |
basic_filebuf<charT, traits>& y);
|
|
@@ -57,28 +62,397 @@ namespace std {
|
|
| 57 |
The class `basic_filebuf<charT, traits>` associates both the input
|
| 58 |
sequence and the output sequence with a file.
|
| 59 |
|
| 60 |
The restrictions on reading and writing a sequence controlled by an
|
| 61 |
object of class `basic_filebuf<charT, traits>` are the same as for
|
| 62 |
-
reading and writing with the
|
| 63 |
|
| 64 |
In particular:
|
| 65 |
|
| 66 |
- If the file is not open for reading the input sequence cannot be read.
|
| 67 |
- If the file is not open for writing the output sequence cannot be
|
| 68 |
written.
|
| 69 |
- A joint file position is maintained for both the input sequence and
|
| 70 |
the output sequence.
|
| 71 |
|
| 72 |
An instance of `basic_filebuf` behaves as described in [[filebuf]]
|
| 73 |
-
provided `traits::pos_type` is `fpos<traits::state_type>`. Otherwise
|
| 74 |
-
behavior is undefined.
|
| 75 |
|
| 76 |
In order to support file I/O and multibyte/wide character conversion,
|
| 77 |
conversions are performed using members of a facet, referred to as
|
| 78 |
`a_codecvt` in following sections, obtained as if by
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
const codecvt<charT, char, typename traits::state_type>& a_codecvt =
|
| 82 |
use_facet<codecvt<charT, char, typename traits::state_type>>(getloc());
|
| 83 |
```
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Class template `basic_filebuf` <a id="filebuf">[[filebuf]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
template <class charT, class traits = char_traits<charT>>
|
| 6 |
class basic_filebuf : public basic_streambuf<charT, traits> {
|
| 7 |
public:
|
| 8 |
+
using char_type = charT;
|
| 9 |
+
using int_type = typename traits::int_type;
|
| 10 |
+
using pos_type = typename traits::pos_type;
|
| 11 |
+
using off_type = typename traits::off_type;
|
| 12 |
+
using traits_type = traits;
|
| 13 |
|
| 14 |
+
// [filebuf.cons], constructors/destructor
|
| 15 |
basic_filebuf();
|
| 16 |
basic_filebuf(const basic_filebuf& rhs) = delete;
|
| 17 |
basic_filebuf(basic_filebuf&& rhs);
|
| 18 |
virtual ~basic_filebuf();
|
| 19 |
|
| 20 |
+
// [filebuf.assign], assign and swap
|
| 21 |
basic_filebuf& operator=(const basic_filebuf& rhs) = delete;
|
| 22 |
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 23 |
void swap(basic_filebuf& rhs);
|
| 24 |
|
| 25 |
+
// [filebuf.members], members
|
| 26 |
bool is_open() const;
|
| 27 |
+
basic_filebuf* open(const char* s, ios_base::openmode mode);
|
| 28 |
+
basic_filebuf* open(const filesystem::path::value_type* s,
|
| 29 |
+
ios_base::openmode mode); // wide systems only; see [fstream.syn]
|
| 30 |
+
basic_filebuf* open(const string& s,
|
| 31 |
ios_base::openmode mode);
|
| 32 |
+
basic_filebuf* open(const filesystem::path& s,
|
| 33 |
ios_base::openmode mode);
|
| 34 |
+
basic_filebuf* close();
|
| 35 |
|
| 36 |
protected:
|
| 37 |
+
// [filebuf.virtuals], overridden virtual functions
|
| 38 |
+
streamsize showmanyc() override;
|
| 39 |
+
int_type underflow() override;
|
| 40 |
+
int_type uflow() override;
|
| 41 |
+
int_type pbackfail(int_type c = traits::eof()) override;
|
| 42 |
+
int_type overflow (int_type c = traits::eof()) override;
|
| 43 |
|
| 44 |
+
basic_streambuf<charT, traits>* setbuf(char_type* s,
|
| 45 |
+
streamsize n) override;
|
| 46 |
+
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 47 |
+
ios_base::openmode which
|
| 48 |
+
= ios_base::in | ios_base::out) override;
|
| 49 |
+
pos_type seekpos(pos_type sp,
|
| 50 |
+
ios_base::openmode which
|
| 51 |
+
= ios_base::in | ios_base::out) override;
|
| 52 |
+
int sync() override;
|
| 53 |
+
void imbue(const locale& loc) override;
|
| 54 |
};
|
| 55 |
|
| 56 |
template <class charT, class traits>
|
| 57 |
void swap(basic_filebuf<charT, traits>& x,
|
| 58 |
basic_filebuf<charT, traits>& y);
|
|
|
|
| 62 |
The class `basic_filebuf<charT, traits>` associates both the input
|
| 63 |
sequence and the output sequence with a file.
|
| 64 |
|
| 65 |
The restrictions on reading and writing a sequence controlled by an
|
| 66 |
object of class `basic_filebuf<charT, traits>` are the same as for
|
| 67 |
+
reading and writing with the C standard library `FILE`s.
|
| 68 |
|
| 69 |
In particular:
|
| 70 |
|
| 71 |
- If the file is not open for reading the input sequence cannot be read.
|
| 72 |
- If the file is not open for writing the output sequence cannot be
|
| 73 |
written.
|
| 74 |
- A joint file position is maintained for both the input sequence and
|
| 75 |
the output sequence.
|
| 76 |
|
| 77 |
An instance of `basic_filebuf` behaves as described in [[filebuf]]
|
| 78 |
+
provided `traits::pos_type` is `fpos<traits::{}state_type>`. Otherwise
|
| 79 |
+
the behavior is undefined.
|
| 80 |
|
| 81 |
In order to support file I/O and multibyte/wide character conversion,
|
| 82 |
conversions are performed using members of a facet, referred to as
|
| 83 |
`a_codecvt` in following sections, obtained as if by
|
| 84 |
|
| 85 |
``` cpp
|
| 86 |
const codecvt<charT, char, typename traits::state_type>& a_codecvt =
|
| 87 |
use_facet<codecvt<charT, char, typename traits::state_type>>(getloc());
|
| 88 |
```
|
| 89 |
|
| 90 |
+
#### `basic_filebuf` constructors <a id="filebuf.cons">[[filebuf.cons]]</a>
|
| 91 |
+
|
| 92 |
+
``` cpp
|
| 93 |
+
basic_filebuf();
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
*Effects:* Constructs an object of class `basic_filebuf<charT, traits>`,
|
| 97 |
+
initializing the base class with
|
| 98 |
+
`basic_streambuf<charT, traits>()` ([[streambuf.cons]]).
|
| 99 |
+
|
| 100 |
+
*Postconditions:* `is_open() == false`.
|
| 101 |
+
|
| 102 |
+
``` cpp
|
| 103 |
+
basic_filebuf(basic_filebuf&& rhs);
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
*Effects:* Move constructs from the rvalue `rhs`. It is
|
| 107 |
+
*implementation-defined* whether the sequence pointers in `*this`
|
| 108 |
+
(`eback()`, `gptr()`, `egptr()`, `pbase()`, `pptr()`, `epptr()`) obtain
|
| 109 |
+
the values which `rhs` had. Whether they do or not, `*this` and `rhs`
|
| 110 |
+
reference separate buffers (if any at all) after the construction.
|
| 111 |
+
Additionally `*this` references the file which `rhs` did before the
|
| 112 |
+
construction, and `rhs` references no file after the construction. The
|
| 113 |
+
openmode, locale and any other state of `rhs` is also copied.
|
| 114 |
+
|
| 115 |
+
*Postconditions:* Let `rhs_p` refer to the state of `rhs` just prior to
|
| 116 |
+
this construction and let `rhs_a` refer to the state of `rhs` just after
|
| 117 |
+
this construction.
|
| 118 |
+
|
| 119 |
+
- `is_open() == rhs_p.is_open()`
|
| 120 |
+
- `rhs_a.is_open() == false`
|
| 121 |
+
- `gptr() - eback() == rhs_p.gptr() - rhs_p.eback()`
|
| 122 |
+
- `egptr() - eback() == rhs_p.egptr() - rhs_p.eback()`
|
| 123 |
+
- `pptr() - pbase() == rhs_p.pptr() - rhs_p.pbase()`
|
| 124 |
+
- `epptr() - pbase() == rhs_p.epptr() - rhs_p.pbase()`
|
| 125 |
+
- `if (eback()) eback() != rhs_a.eback()`
|
| 126 |
+
- `if (gptr()) gptr() != rhs_a.gptr()`
|
| 127 |
+
- `if (egptr()) egptr() != rhs_a.egptr()`
|
| 128 |
+
- `if (pbase()) pbase() != rhs_a.pbase()`
|
| 129 |
+
- `if (pptr()) pptr() != rhs_a.pptr()`
|
| 130 |
+
- `if (epptr()) epptr() != rhs_a.epptr()`
|
| 131 |
+
|
| 132 |
+
``` cpp
|
| 133 |
+
virtual ~basic_filebuf();
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
*Effects:* Destroys an object of class `basic_filebuf<charT, traits>`.
|
| 137 |
+
Calls `close()`. If an exception occurs during the destruction of the
|
| 138 |
+
object, including the call to `close()`, the exception is caught but not
|
| 139 |
+
rethrown (see [[res.on.exception.handling]]).
|
| 140 |
+
|
| 141 |
+
#### Assign and swap <a id="filebuf.assign">[[filebuf.assign]]</a>
|
| 142 |
+
|
| 143 |
+
``` cpp
|
| 144 |
+
basic_filebuf& operator=(basic_filebuf&& rhs);
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
*Effects:* Calls `close()` then move assigns from `rhs`. After the move
|
| 148 |
+
assignment `*this` has the observable state it would have had if it had
|
| 149 |
+
been move constructed from `rhs` (see [[filebuf.cons]]).
|
| 150 |
+
|
| 151 |
+
*Returns:* `*this`.
|
| 152 |
+
|
| 153 |
+
``` cpp
|
| 154 |
+
void swap(basic_filebuf& rhs);
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
*Effects:* Exchanges the state of `*this` and `rhs`.
|
| 158 |
+
|
| 159 |
+
``` cpp
|
| 160 |
+
template <class charT, class traits>
|
| 161 |
+
void swap(basic_filebuf<charT, traits>& x,
|
| 162 |
+
basic_filebuf<charT, traits>& y);
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
*Effects:* As if by `x.swap(y)`.
|
| 166 |
+
|
| 167 |
+
#### Member functions <a id="filebuf.members">[[filebuf.members]]</a>
|
| 168 |
+
|
| 169 |
+
``` cpp
|
| 170 |
+
bool is_open() const;
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
*Returns:* `true` if a previous call to `open` succeeded (returned a
|
| 174 |
+
non-null value) and there has been no intervening call to close.
|
| 175 |
+
|
| 176 |
+
``` cpp
|
| 177 |
+
basic_filebuf* open(const char* s, ios_base::openmode mode);
|
| 178 |
+
basic_filebuf* open(const filesystem::path::value_type* s,
|
| 179 |
+
ios_base::openmode mode); // wide systems only; see [fstream.syn]
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
*Effects:* If `is_open() != false`, returns a null pointer. Otherwise,
|
| 183 |
+
initializes the `filebuf` as required. It then opens a file, if
|
| 184 |
+
possible, whose name is the NTBS`s` (as if by calling
|
| 185 |
+
`fopen(s, modstr)`). The NTBS`modstr` is determined from
|
| 186 |
+
`mode & ~ios_base::ate` as indicated in
|
| 187 |
+
Table [[tab:iostreams.file.open.modes]]. If `mode` is not some
|
| 188 |
+
combination of flags shown in the table then the open fails.
|
| 189 |
+
|
| 190 |
+
**Table: File open modes** <a id="tab:iostreams.file.open.modes">[tab:iostreams.file.open.modes]</a>
|
| 191 |
+
|
| 192 |
+
| `binary` | `in` | `out` | `trunc` | `app` | | `stdio` equivalent |
|
| 193 |
+
| -------- | ---- | ----- | ------- | ----- | --- | ------------------ |
|
| 194 |
+
| | | + | | | `"w"` |
|
| 195 |
+
| | | + | | + | `"a"` |
|
| 196 |
+
| | | | | + | `"a"` |
|
| 197 |
+
| | | + | + | | `"w"` |
|
| 198 |
+
| | + | | | | `"r"` |
|
| 199 |
+
| | + | + | | | `"r+"` |
|
| 200 |
+
| | + | + | + | | `"w+"` |
|
| 201 |
+
| | + | + | | + | `"a+"` |
|
| 202 |
+
| | + | | | + | `"a+"` + | | + | | | `"wb"` |
|
| 203 |
+
| + | | + | | + | `"ab"` |
|
| 204 |
+
| + | | | | + | `"ab"` |
|
| 205 |
+
| + | | + | + | | `"wb"` |
|
| 206 |
+
| + | + | | | | `"rb"` |
|
| 207 |
+
| + | + | + | | | `"r+b"` |
|
| 208 |
+
| + | + | + | + | | `"w+b"` |
|
| 209 |
+
| + | + | + | | + | `"a+b"` |
|
| 210 |
+
| + | + | | | + | `"a+b"` |
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
If the open operation succeeds and `(mode & ios_base::ate) != 0`,
|
| 214 |
+
positions the file to the end (as if by calling
|
| 215 |
+
`fseek(file, 0, SEEK_END)`).[^40]
|
| 216 |
+
|
| 217 |
+
If the repositioning operation fails, calls `close()` and returns a null
|
| 218 |
+
pointer to indicate failure.
|
| 219 |
+
|
| 220 |
+
*Returns:* `this` if successful, a null pointer otherwise.
|
| 221 |
+
|
| 222 |
+
``` cpp
|
| 223 |
+
basic_filebuf* open(const string& s, ios_base::openmode mode);
|
| 224 |
+
basic_filebuf* open(const filesystem::path& s, ios_base::openmode mode);
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
*Returns:* `open(s.c_str(), mode);`
|
| 228 |
+
|
| 229 |
+
``` cpp
|
| 230 |
+
basic_filebuf* close();
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
*Effects:* If `is_open() == false`, returns a null pointer. If a put
|
| 234 |
+
area exists, calls `overflow(traits::eof())` to flush characters. If the
|
| 235 |
+
last virtual member function called on `*this` (between `underflow`,
|
| 236 |
+
`overflow`, `seekoff`, and `seekpos`) was `overflow` then calls
|
| 237 |
+
`a_codecvt.unshift` (possibly several times) to determine a termination
|
| 238 |
+
sequence, inserts those characters and calls `overflow(traits::eof())`
|
| 239 |
+
again. Finally, regardless of whether any of the preceding calls fails
|
| 240 |
+
or throws an exception, the function closes the file (as if by calling
|
| 241 |
+
`fclose(file)`). If any of the calls made by the function, including
|
| 242 |
+
`fclose`, fails, `close` fails by returning a null pointer. If one of
|
| 243 |
+
these calls throws an exception, the exception is caught and rethrown
|
| 244 |
+
after closing the file.
|
| 245 |
+
|
| 246 |
+
*Returns:* `this` on success, a null pointer otherwise.
|
| 247 |
+
|
| 248 |
+
*Postconditions:* `is_open() == false`.
|
| 249 |
+
|
| 250 |
+
#### Overridden virtual functions <a id="filebuf.virtuals">[[filebuf.virtuals]]</a>
|
| 251 |
+
|
| 252 |
+
``` cpp
|
| 253 |
+
streamsize showmanyc() override;
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
*Effects:* Behaves the same as
|
| 257 |
+
`basic_streambuf::showmanyc()` ([[streambuf.virtuals]]).
|
| 258 |
+
|
| 259 |
+
*Remarks:* An implementation might well provide an overriding definition
|
| 260 |
+
for this function signature if it can determine that more characters can
|
| 261 |
+
be read from the input sequence.
|
| 262 |
+
|
| 263 |
+
``` cpp
|
| 264 |
+
int_type underflow() override;
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
*Effects:* Behaves according to the description of
|
| 268 |
+
`basic_streambuf<charT, traits>::underflow()`, with the specialization
|
| 269 |
+
that a sequence of characters is read from the input sequence as if by
|
| 270 |
+
reading from the associated file into an internal buffer (`extern_buf`)
|
| 271 |
+
and then as if by doing:
|
| 272 |
+
|
| 273 |
+
``` cpp
|
| 274 |
+
char extern_buf[XSIZE];
|
| 275 |
+
char* extern_end;
|
| 276 |
+
charT intern_buf[ISIZE];
|
| 277 |
+
charT* intern_end;
|
| 278 |
+
codecvt_base::result r =
|
| 279 |
+
a_codecvt.in(state, extern_buf, extern_buf+XSIZE, extern_end,
|
| 280 |
+
intern_buf, intern_buf+ISIZE, intern_end);
|
| 281 |
+
```
|
| 282 |
+
|
| 283 |
+
This shall be done in such a way that the class can recover the position
|
| 284 |
+
(`fpos_t`) corresponding to each character between `intern_buf` and
|
| 285 |
+
`intern_end`. If the value of `r` indicates that `a_codecvt.in()` ran
|
| 286 |
+
out of space in `intern_buf`, retry with a larger `intern_buf`.
|
| 287 |
+
|
| 288 |
+
``` cpp
|
| 289 |
+
int_type uflow() override;
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
*Effects:* Behaves according to the description of
|
| 293 |
+
`basic_streambuf<charT, traits>::uflow()`, with the specialization that
|
| 294 |
+
a sequence of characters is read from the input with the same method as
|
| 295 |
+
used by `underflow`.
|
| 296 |
+
|
| 297 |
+
``` cpp
|
| 298 |
+
int_type pbackfail(int_type c = traits::eof()) override;
|
| 299 |
+
```
|
| 300 |
+
|
| 301 |
+
*Effects:* Puts back the character designated by `c` to the input
|
| 302 |
+
sequence, if possible, in one of three ways:
|
| 303 |
+
|
| 304 |
+
- If `traits::eq_int_type(c, traits::eof())` returns `false` and if the
|
| 305 |
+
function makes a putback position available and if
|
| 306 |
+
`traits::eq(to_char_type(c), gptr()[-1])` returns `true`, decrements
|
| 307 |
+
the next pointer for the input sequence, `gptr()`. Returns: `c`.
|
| 308 |
+
- If `traits::eq_int_type(c, traits::eof())` returns `false` and if the
|
| 309 |
+
function makes a putback position available and if the function is
|
| 310 |
+
permitted to assign to the putback position, decrements the next
|
| 311 |
+
pointer for the input sequence, and stores `c` there. Returns: `c`.
|
| 312 |
+
- If `traits::eq_int_type(c, traits::eof())` returns `true`, and if
|
| 313 |
+
either the input sequence has a putback position available or the
|
| 314 |
+
function makes a putback position available, decrements the next
|
| 315 |
+
pointer for the input sequence, `gptr()`. Returns:
|
| 316 |
+
`traits::not_eof(c)`.
|
| 317 |
+
|
| 318 |
+
*Returns:* `traits::eof()` to indicate failure.
|
| 319 |
+
|
| 320 |
+
*Remarks:* If `is_open() == false`, the function always fails.
|
| 321 |
+
|
| 322 |
+
The function does not put back a character directly to the input
|
| 323 |
+
sequence.
|
| 324 |
+
|
| 325 |
+
If the function can succeed in more than one of these ways, it is
|
| 326 |
+
unspecified which way is chosen. The function can alter the number of
|
| 327 |
+
putback positions available as a result of any call.
|
| 328 |
+
|
| 329 |
+
``` cpp
|
| 330 |
+
int_type overflow(int_type c = traits::eof()) override;
|
| 331 |
+
```
|
| 332 |
+
|
| 333 |
+
*Effects:* Behaves according to the description of
|
| 334 |
+
`basic_streambuf<charT, traits>::overflow(c)`, except that the behavior
|
| 335 |
+
of “consuming characters” is performed by first converting as if by:
|
| 336 |
+
|
| 337 |
+
``` cpp
|
| 338 |
+
charT* b = pbase();
|
| 339 |
+
charT* p = pptr();
|
| 340 |
+
charT* end;
|
| 341 |
+
char xbuf[XSIZE];
|
| 342 |
+
char* xbuf_end;
|
| 343 |
+
codecvt_base::result r =
|
| 344 |
+
a_codecvt.out(state, b, p, end, xbuf, xbuf+XSIZE, xbuf_end);
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
and then
|
| 348 |
+
|
| 349 |
+
- If `r == codecvt_base::error` then fail.
|
| 350 |
+
- If `r == codecvt_base::noconv` then output characters from `b` up to
|
| 351 |
+
(and not including) `p`.
|
| 352 |
+
- If `r == codecvt_base::partial` then output to the file characters
|
| 353 |
+
from `xbuf` up to `xbuf_end`, and repeat using characters from `end`
|
| 354 |
+
to `p`. If output fails, fail (without repeating).
|
| 355 |
+
- Otherwise output from `xbuf` to `xbuf_end`, and fail if output fails.
|
| 356 |
+
At this point if `b != p` and `b == end` (`xbuf` isn’t large enough)
|
| 357 |
+
then increase `XSIZE` and repeat from the beginning.
|
| 358 |
+
|
| 359 |
+
*Returns:* `traits::not_eof(c)` to indicate success, and `traits::eof()`
|
| 360 |
+
to indicate failure. If `is_open() == false`, the function always fails.
|
| 361 |
+
|
| 362 |
+
``` cpp
|
| 363 |
+
basic_streambuf* setbuf(char_type* s, streamsize n) override;
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
*Effects:* If `setbuf(0, 0)` is called on a stream before any I/O has
|
| 367 |
+
occurred on that stream, the stream becomes unbuffered. Otherwise the
|
| 368 |
+
results are *implementation-defined*. “Unbuffered” means that `pbase()`
|
| 369 |
+
and `pptr()` always return null and output to the file should appear as
|
| 370 |
+
soon as possible.
|
| 371 |
+
|
| 372 |
+
``` cpp
|
| 373 |
+
pos_type seekoff(off_type off, ios_base::seekdir way,
|
| 374 |
+
ios_base::openmode which
|
| 375 |
+
= ios_base::in | ios_base::out) override;
|
| 376 |
+
```
|
| 377 |
+
|
| 378 |
+
*Effects:* Let `width` denote `a_codecvt.encoding()`. If
|
| 379 |
+
`is_open() == false`, or `off != 0 && width <= 0`, then the positioning
|
| 380 |
+
operation fails. Otherwise, if `way != basic_ios::cur` or `off != 0`,
|
| 381 |
+
and if the last operation was output, then update the output sequence
|
| 382 |
+
and write any unshift sequence. Next, seek to the new position: if
|
| 383 |
+
`width > 0`, call `fseek(file, width * off, whence)`, otherwise call
|
| 384 |
+
`fseek(file, 0, whence)`.
|
| 385 |
+
|
| 386 |
+
*Remarks:* “The last operation was output” means either the last virtual
|
| 387 |
+
operation was overflow or the put buffer is non-empty. “Write any
|
| 388 |
+
unshift sequence” means, if `width` if less than zero then call
|
| 389 |
+
`a_codecvt.unshift(state, xbuf, xbuf+XSIZE, xbuf_end)` and output the
|
| 390 |
+
resulting unshift sequence. The function determines one of three values
|
| 391 |
+
for the argument `whence`, of type `int`, as indicated in
|
| 392 |
+
Table [[tab:iostreams.seekoff.effects]].
|
| 393 |
+
|
| 394 |
+
**Table: `seekoff` effects** <a id="tab:iostreams.seekoff.effects">[tab:iostreams.seekoff.effects]</a>
|
| 395 |
+
|
| 396 |
+
| `way` Value | `stdio` Equivalent |
|
| 397 |
+
| ---------------- | ------------------ |
|
| 398 |
+
| `basic_ios::beg` | `SEEK_SET` |
|
| 399 |
+
| `basic_ios::cur` | `SEEK_CUR` |
|
| 400 |
+
| `basic_ios::end` | `SEEK_END` |
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
*Returns:* A newly constructed `pos_type` object that stores the
|
| 404 |
+
resultant stream position, if possible. If the positioning operation
|
| 405 |
+
fails, or if the object cannot represent the resultant stream position,
|
| 406 |
+
returns `pos_type(off_type(-1))`.
|
| 407 |
+
|
| 408 |
+
``` cpp
|
| 409 |
+
pos_type seekpos(pos_type sp,
|
| 410 |
+
ios_base::openmode which
|
| 411 |
+
= ios_base::in | ios_base::out) override;
|
| 412 |
+
```
|
| 413 |
+
|
| 414 |
+
Alters the file position, if possible, to correspond to the position
|
| 415 |
+
stored in `sp` (as described below). Altering the file position performs
|
| 416 |
+
as follows:
|
| 417 |
+
|
| 418 |
+
1. if `(om & ios_base::out) != 0`, then update the output sequence and
|
| 419 |
+
write any unshift sequence;
|
| 420 |
+
2. set the file position to `sp` as if by a call to `fsetpos`;
|
| 421 |
+
3. if `(om & ios_base::in) != 0`, then update the input sequence;
|
| 422 |
+
|
| 423 |
+
where `om` is the open mode passed to the last call to `open()`. The
|
| 424 |
+
operation fails if `is_open()` returns `false`.
|
| 425 |
+
|
| 426 |
+
If `sp` is an invalid stream position, or if the function positions
|
| 427 |
+
neither sequence, the positioning operation fails. If `sp` has not been
|
| 428 |
+
obtained by a previous successful call to one of the positioning
|
| 429 |
+
functions (`seekoff` or `seekpos`) on the same file the effects are
|
| 430 |
+
undefined.
|
| 431 |
+
|
| 432 |
+
*Returns:* `sp` on success. Otherwise returns `pos_type(off_type(-1))`.
|
| 433 |
+
|
| 434 |
+
``` cpp
|
| 435 |
+
int sync() override;
|
| 436 |
+
```
|
| 437 |
+
|
| 438 |
+
*Effects:* If a put area exists, calls `filebuf::overflow` to write the
|
| 439 |
+
characters to the file, then flushes the file as if by calling
|
| 440 |
+
`fflush(file)`. If a get area exists, the effect is
|
| 441 |
+
*implementation-defined*.
|
| 442 |
+
|
| 443 |
+
``` cpp
|
| 444 |
+
void imbue(const locale& loc) override;
|
| 445 |
+
```
|
| 446 |
+
|
| 447 |
+
*Requires:* If the file is not positioned at its beginning and the
|
| 448 |
+
encoding of the current locale as determined by `a_codecvt.encoding()`
|
| 449 |
+
is state-dependent ([[locale.codecvt.virtuals]]) then that facet is the
|
| 450 |
+
same as the corresponding facet of `loc`.
|
| 451 |
+
|
| 452 |
+
*Effects:* Causes characters inserted or extracted after this call to be
|
| 453 |
+
converted according to `loc` until another call of `imbue`.
|
| 454 |
+
|
| 455 |
+
*Remarks:* This may require reconversion of previously converted
|
| 456 |
+
characters. This in turn may require the implementation to be able to
|
| 457 |
+
reconstruct the original contents of the file.
|
| 458 |
+
|