From Jason Turner

[depr.strstreambuf]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5y9oudfi/{from.md → to.md} +0 -383
tmp/tmp5y9oudfi/{from.md → to.md} RENAMED
@@ -1,383 +0,0 @@
1
- ### Class `strstreambuf` <a id="depr.strstreambuf">[[depr.strstreambuf]]</a>
2
-
3
- #### General <a id="depr.strstreambuf.general">[[depr.strstreambuf.general]]</a>
4
-
5
- ``` cpp
6
- namespace std {
7
- class strstreambuf : public basic_streambuf<char> {
8
- public:
9
- strstreambuf() : strstreambuf(0) {}
10
- explicit strstreambuf(streamsize alsize_arg);
11
- strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
12
- strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
13
- strstreambuf(const char* gnext_arg, streamsize n);
14
-
15
- strstreambuf(signed char* gnext_arg, streamsize n,
16
- signed char* pbeg_arg = nullptr);
17
- strstreambuf(const signed char* gnext_arg, streamsize n);
18
- strstreambuf(unsigned char* gnext_arg, streamsize n,
19
- unsigned char* pbeg_arg = nullptr);
20
- strstreambuf(const unsigned char* gnext_arg, streamsize n);
21
-
22
- virtual ~strstreambuf();
23
-
24
- void freeze(bool freezefl = true);
25
- char* str();
26
- int pcount();
27
-
28
- protected:
29
- int_type overflow (int_type c = EOF) override;
30
- int_type pbackfail(int_type c = EOF) override;
31
- int_type underflow() override;
32
- pos_type seekoff(off_type off, ios_base::seekdir way,
33
- ios_base::openmode which = ios_base::in | ios_base::out) override;
34
- pos_type seekpos(pos_type sp,
35
- ios_base::openmode which = ios_base::in | ios_base::out) override;
36
- streambuf* setbuf(char* s, streamsize n) override;
37
-
38
- private:
39
- using strstate = T1; // exposition only
40
- static const strstate allocated; // exposition only
41
- static const strstate constant; // exposition only
42
- static const strstate dynamic; // exposition only
43
- static const strstate frozen; // exposition only
44
- strstate strmode; // exposition only
45
- streamsize alsize; // exposition only
46
- void* (*palloc)(size_t); // exposition only
47
- void (*pfree)(void*); // exposition only
48
- };
49
- }
50
- ```
51
-
52
- The class `strstreambuf` associates the input sequence, and possibly the
53
- output sequence, with an object of some *character* array type, whose
54
- elements store arbitrary values. The array object has several
55
- attributes.
56
-
57
- [*Note 1*:
58
-
59
- For the sake of exposition, these are represented as elements of a
60
- bitmask type (indicated here as `T1`) called `strstate`. The elements
61
- are:
62
-
63
- - `allocated`, set when a dynamic array object has been allocated, and
64
- hence will be freed by the destructor for the `strstreambuf` object;
65
- - `constant`, set when the array object has `const` elements, so the
66
- output sequence cannot be written;
67
- - `dynamic`, set when the array object is allocated (or reallocated) as
68
- necessary to hold a character sequence that can change in length;
69
- - `frozen`, set when the program has requested that the array object not
70
- be altered, reallocated, or freed.
71
-
72
- — *end note*]
73
-
74
- [*Note 2*:
75
-
76
- For the sake of exposition, the maintained data is presented here as:
77
-
78
- - `strstate strmode`, the attributes of the array object associated with
79
- the `strstreambuf` object;
80
- - `int alsize`, the suggested minimum size for a dynamic array object;
81
- - `void* (*palloc)(size_t)`, points to the function to call to allocate
82
- a dynamic array object;
83
- - `void (*pfree)(void*)`, points to the function to call to free a
84
- dynamic array object.
85
-
86
- — *end note*]
87
-
88
- Each object of class `strstreambuf` has a *seekable area*, delimited by
89
- the pointers `seeklow` and `seekhigh`. If `gnext` is a null pointer, the
90
- seekable area is undefined. Otherwise, `seeklow` equals `gbeg` and
91
- `seekhigh` is either `pend`, if `pend` is not a null pointer, or `gend`.
92
-
93
- #### `strstreambuf` constructors <a id="depr.strstreambuf.cons">[[depr.strstreambuf.cons]]</a>
94
-
95
- ``` cpp
96
- explicit strstreambuf(streamsize alsize_arg);
97
- ```
98
-
99
- *Effects:* Initializes the base class with `streambuf()`. The
100
- postconditions of this function are indicated in
101
- [[depr.strstreambuf.cons.sz]].
102
-
103
- **Table: `strstreambuf(streamsize)` effects** <a id="depr.strstreambuf.cons.sz">[depr.strstreambuf.cons.sz]</a>
104
-
105
- | Element | Value |
106
- | --------- | -------------- |
107
- | `strmode` | `dynamic` |
108
- | `alsize` | `alsize_arg` |
109
- | `palloc` | a null pointer |
110
- | `pfree` | a null pointer |
111
-
112
- ``` cpp
113
- strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
114
- ```
115
-
116
- *Effects:* Initializes the base class with `streambuf()`. The
117
- postconditions of this function are indicated in
118
- [[depr.strstreambuf.cons.alloc]].
119
-
120
- **Table: `strstreambuf(void* (*)(size_t), void (*)(void*))` effects** <a id="depr.strstreambuf.cons.alloc">[depr.strstreambuf.cons.alloc]</a>
121
-
122
- | Element | Value |
123
- | --------- | -------------------- |
124
- | `strmode` | `dynamic` |
125
- | `alsize` | an unspecified value |
126
- | `palloc` | `palloc_arg` |
127
- | `pfree` | `pfree_arg` |
128
-
129
- ``` cpp
130
- strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
131
- strstreambuf(signed char* gnext_arg, streamsize n,
132
- signed char* pbeg_arg = nullptr);
133
- strstreambuf(unsigned char* gnext_arg, streamsize n,
134
- unsigned char* pbeg_arg = nullptr);
135
- ```
136
-
137
- *Effects:* Initializes the base class with `streambuf()`. The
138
- postconditions of this function are indicated in
139
- [[depr.strstreambuf.cons.ptr]].
140
-
141
- **Table: `strstreambuf(charT*, streamsize, charT*)` effects** <a id="depr.strstreambuf.cons.ptr">[depr.strstreambuf.cons.ptr]</a>
142
-
143
- | Element | Value |
144
- | --------- | -------------------- |
145
- | `strmode` | 0 |
146
- | `alsize` | an unspecified value |
147
- | `palloc` | a null pointer |
148
- | `pfree` | a null pointer |
149
-
150
-
151
- `gnext_arg` shall point to the first element of an array object whose
152
- number of elements `N` is determined as follows:
153
-
154
- - If `n > 0`, `N` is `n`.
155
- - If `n == 0`, `N` is `std::strlen(gnext_arg)`.
156
- - If `n < 0`, `N` is `INT_MAX`.[^1]
157
-
158
- If `pbeg_arg` is a null pointer, the function executes:
159
-
160
- ``` cpp
161
- setg(gnext_arg, gnext_arg, gnext_arg + N);
162
- ```
163
-
164
- Otherwise, the function executes:
165
-
166
- ``` cpp
167
- setg(gnext_arg, gnext_arg, pbeg_arg);
168
- setp(pbeg_arg, pbeg_arg + N);
169
- ```
170
-
171
- ``` cpp
172
- strstreambuf(const char* gnext_arg, streamsize n);
173
- strstreambuf(const signed char* gnext_arg, streamsize n);
174
- strstreambuf(const unsigned char* gnext_arg, streamsize n);
175
- ```
176
-
177
- *Effects:* Behaves the same as `strstreambuf((char*)gnext_arg,n)`,
178
- except that the constructor also sets `constant` in `strmode`.
179
-
180
- ``` cpp
181
- virtual ~strstreambuf();
182
- ```
183
-
184
- *Effects:* Destroys an object of class `strstreambuf`. The function
185
- frees the dynamically allocated array object only if
186
- `(strmode & allocated) != 0` and `(strmode & frozen) == 0`.
187
- ([[depr.strstreambuf.virtuals]] describes how a dynamically allocated
188
- array object is freed.)
189
-
190
- #### Member functions <a id="depr.strstreambuf.members">[[depr.strstreambuf.members]]</a>
191
-
192
- ``` cpp
193
- void freeze(bool freezefl = true);
194
- ```
195
-
196
- *Effects:* If `strmode & dynamic` is nonzero, alters the freeze status
197
- of the dynamic array object as follows:
198
-
199
- - If `freezefl` is `true`, the function sets `frozen` in `strmode`.
200
- - Otherwise, it clears `frozen` in `strmode`.
201
-
202
- ``` cpp
203
- char* str();
204
- ```
205
-
206
- *Effects:* Calls `freeze()`, then returns the beginning pointer for the
207
- input sequence, `gbeg`.
208
-
209
- *Remarks:* The return value can be a null pointer.
210
-
211
- ``` cpp
212
- int pcount() const;
213
- ```
214
-
215
- *Effects:* If the next pointer for the output sequence, `pnext`, is a
216
- null pointer, returns zero. Otherwise, returns the current effective
217
- length of the array object as the next pointer minus the beginning
218
- pointer for the output sequence, `pnext - pbeg`.
219
-
220
- #### `strstreambuf` overridden virtual functions <a id="depr.strstreambuf.virtuals">[[depr.strstreambuf.virtuals]]</a>
221
-
222
- ``` cpp
223
- int_type overflow(int_type c = EOF) override;
224
- ```
225
-
226
- *Effects:* Appends the character designated by `c` to the output
227
- sequence, if possible, in one of two ways:
228
-
229
- - If `c != EOF` and if either the output sequence has a write position
230
- available or the function makes a write position available (as
231
- described below), assigns `c` to `*pnext++`. Returns
232
- `(unsigned char)c`.
233
- - If `c == EOF`, there is no character to append. Returns a value other
234
- than `EOF`.
235
-
236
- Returns `EOF` to indicate failure.
237
-
238
- *Remarks:* The function can alter the number of write positions
239
- available as a result of any call.
240
-
241
- To make a write position available, the function reallocates (or
242
- initially allocates) an array object with a sufficient number of
243
- elements `n` to hold the current array object (if any), plus at least
244
- one additional write position. How many additional write positions are
245
- made available is otherwise unspecified. If `palloc` is not a null
246
- pointer, the function calls `(*palloc)(n)` to allocate the new dynamic
247
- array object. Otherwise, it evaluates the expression `new charT[n]`. In
248
- either case, if the allocation fails, the function returns `EOF`.
249
- Otherwise, it sets `allocated` in `strmode`.
250
-
251
- To free a previously existing dynamic array object whose first element
252
- address is `p`: If `pfree` is not a null pointer, the function calls
253
- `(*pfree)(p)`. Otherwise, it evaluates the expression `delete[]p`.
254
-
255
- If `(strmode & dynamic) == 0`, or if `(strmode & frozen) != 0`, the
256
- function cannot extend the array (reallocate it with greater length) to
257
- make a write position available.
258
-
259
- *Recommended practice:* An implementation should consider `alsize` in
260
- making the decision how many additional write positions to make
261
- available.
262
-
263
- ``` cpp
264
- int_type pbackfail(int_type c = EOF) override;
265
- ```
266
-
267
- Puts back the character designated by `c` to the input sequence, if
268
- possible, in one of three ways:
269
-
270
- - If `c != EOF`, if the input sequence has a putback position available,
271
- and if `(char)c == gnext[-1]`, assigns `gnext - 1` to `gnext`. Returns
272
- `c`.
273
- - If `c != EOF`, if the input sequence has a putback position available,
274
- and if `strmode & constant` is zero, assigns `c` to `*–gnext`. Returns
275
- `c`.
276
- - If `c == EOF` and if the input sequence has a putback position
277
- available, assigns `gnext - 1` to `gnext`. Returns a value other than
278
- `EOF`.
279
-
280
- Returns `EOF` to indicate failure.
281
-
282
- *Remarks:* If the function can succeed in more than one of these ways,
283
- it is unspecified which way is chosen. The function can alter the number
284
- of putback positions available as a result of any call.
285
-
286
- ``` cpp
287
- int_type underflow() override;
288
- ```
289
-
290
- *Effects:* Reads a character from the *input sequence*, if possible,
291
- without moving the stream position past it, as follows:
292
-
293
- - If the input sequence has a read position available, the function
294
- signals success by returning `(unsigned char)*gnext`.
295
- - Otherwise, if the current write next pointer `pnext` is not a null
296
- pointer and is greater than the current read end pointer `gend`, makes
297
- a *read position* available by assigning to `gend` a value greater
298
- than `gnext` and no greater than `pnext`. Returns
299
- `(unsigned char)*gnext`.
300
-
301
- Returns `EOF` to indicate failure.
302
-
303
- *Remarks:* The function can alter the number of read positions available
304
- as a result of any call.
305
-
306
- ``` cpp
307
- pos_type seekoff(off_type off, seekdir way, openmode which = in | out) override;
308
- ```
309
-
310
- *Effects:* Alters the stream position within one of the controlled
311
- sequences, if possible, as indicated in
312
- [[depr.strstreambuf.seekoff.pos]].
313
-
314
- **Table: `seekoff` positioning** <a id="depr.strstreambuf.seekoff.pos">[depr.strstreambuf.seekoff.pos]</a>
315
-
316
- | Conditions | Result |
317
- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
318
- | `(which & ios::in) != 0` | positions the input sequence |
319
- | `(which & ios::out) != 0` | positions the output sequence |
320
- | `(which & (ios::in | ios::out)) ==`<br> `(ios::in | ios::out)` and either<br> `way == ios::beg` or `way == ios::end` | positions both the input and the output sequences |
321
- | Otherwise | the positioning operation fails. |
322
-
323
-
324
- For a sequence to be positioned, if its next pointer is a null pointer,
325
- the positioning operation fails. Otherwise, the function determines
326
- `newoff` as indicated in [[depr.strstreambuf.seekoff.newoff]].
327
-
328
- **Table: `newoff` values** <a id="depr.strstreambuf.seekoff.newoff">[depr.strstreambuf.seekoff.newoff]</a>
329
-
330
- | Condition | `newoff` Value |
331
- | ----------------- | -------------------------------------------------------------- |
332
- | `way == ios::beg` | 0 |
333
- | `way == ios::cur` | the next pointer minus the beginning pointer (`xnext - xbeg`). |
334
- | `way == ios::end` | `seekhigh` minus the beginning pointer (`seekhigh - xbeg`). |
335
-
336
-
337
- If `(newoff + off) < (seeklow - xbeg)` or
338
- `(seekhigh - xbeg) < (newoff + off)`, the positioning operation fails.
339
- Otherwise, the function assigns `xbeg + newoff + off` to the next
340
- pointer `xnext`.
341
-
342
- *Returns:* `pos_type(newoff)`, constructed from the resultant offset
343
- `newoff` (of type `off_type`), that stores the resultant stream
344
- position, if possible. If the positioning operation fails, or if the
345
- constructed object cannot represent the resultant stream position, the
346
- return value is `pos_type(off_type(-1))`.
347
-
348
- ``` cpp
349
- pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out) override;
350
- ```
351
-
352
- *Effects:* Alters the stream position within one of the controlled
353
- sequences, if possible, to correspond to the stream position stored in
354
- `sp` (as described below).
355
-
356
- - If `(which & ios::in) != 0`, positions the input sequence.
357
- - If `(which & ios::out) != 0`, positions the output sequence.
358
- - If the function positions neither sequence, the positioning operation
359
- fails.
360
-
361
- For a sequence to be positioned, if its next pointer is a null pointer,
362
- the positioning operation fails. Otherwise, the function determines
363
- `newoff` from `sp.offset()`:
364
-
365
- - If `newoff` is an invalid stream position, has a negative value, or
366
- has a value greater than (`seekhigh - seeklow`), the positioning
367
- operation fails
368
- - Otherwise, the function adds `newoff` to the beginning pointer `xbeg`
369
- and stores the result in the next pointer `xnext`.
370
-
371
- *Returns:* `pos_type(newoff)`, constructed from the resultant offset
372
- `newoff` (of type `off_type`), that stores the resultant stream
373
- position, if possible. If the positioning operation fails, or if the
374
- constructed object cannot represent the resultant stream position, the
375
- return value is `pos_type(off_type(-1))`.
376
-
377
- ``` cpp
378
- streambuf<char>* setbuf(char* s, streamsize n) override;
379
- ```
380
-
381
- *Effects:* Behavior is *implementation-defined*, except that
382
- `setbuf(0, 0)` has no effect.
383
-