[stringbuf.virtuals] (original) (raw)
31 Input/output library [input.output]
31.8 String-based streams [string.streams]
31.8.2 Class template basic_stringbuf [stringbuf]
31.8.2.5 Overridden virtual functions [stringbuf.virtuals]
int_type underflow() override;
Returns: If the input sequence has a read position available, returnstraits::to_int_type(*gptr()).
Otherwise, returnstraits::eof().
Any character in the underlying buffer which has been initialized is considered to be part of the input sequence.
int_type pbackfail(int_type c = traits::eof()) override;
Effects: Puts back the character designated by c to the input sequence, if possible, in one of three ways:
- Iftraits::eq_int_type(c, traits::eof())returnsfalseand if the input sequence has a putback position available, and iftraits::eq(to_char_type(c), gptr()[-1])returnstrue, assignsgptr() - 1togptr().
- Iftraits::eq_int_type(c, traits::eof())returnsfalseand if the input sequence has a putback position available, and if mode & ios_base::out is nonzero, assigns c to*--gptr().
- Iftraits::eq_int_type(c, traits::eof())returnstrueand if the input sequence has a putback position available, assignsgptr() - 1togptr().
Returns:traits::not_eof(c).
Returns: As specified above, ortraits::eof()to indicate failure.
Remarks: If the function can succeed in more than one of these ways, it is unspecified which way is chosen.
int_type overflow(int_type c = traits::eof()) override;
Effects: Appends the character designated by c to the output sequence, if possible, in one of two ways:
- Iftraits::eq_int_type(c, traits::eof())returnsfalseand if either the output sequence has a write position available or the function makes a write position available (as described below), the function callssputc(c).
Signals success by returning c. - Iftraits::eq_int_type(c, traits::eof())returnstrue, there is no character to append.
Signals success by returning a value other thantraits::eof().
Returns: As specified above, ortraits::eof()to indicate failure.
Remarks: The function can alter the number of write positions available as a result of any call.
The function can make a write position available only ifios_base::out is set in mode.
To make a write position available, the function reallocates (or initially allocates) an array object with a sufficient number of elements to hold the current array object (if any), plus at least one additional write position.
If ios_base::in is set in mode, the function alters the read end pointeregptr()to point just past the new write position.
pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which= ios_base::in | ios_base::out) override;
Effects: Alters the stream position within one of the controlled sequences, if possible, as indicated in Table 142.
Table 142 — seekoff positioning [tab:stringbuf.seekoff.pos]
ios_base::in is set in which | positions the input sequence |
---|---|
ios_base::out is set in which | positions the output sequence |
both ios_base::in and ios_base::out are set in which and eitherway == ios_base::beg orway == ios_base::end | positions both the input and the output sequences |
the positioning operation fails. |
For a sequence to be positioned, the function determines newoff as indicated in Table 143.
If the sequence's next pointer (eithergptr()orpptr()) is a null pointer and newoff is nonzero, the positioning operation fails.
Table 143 — newoff values [tab:stringbuf.seekoff.newoff]
the next pointer minus the beginning pointer (xnext - xbeg). |
---|
the high mark pointer minus the beginning pointer (high_mark - xbeg). |
If(newoff + off) < 0, or if newoff + off refers to an uninitialized character ([stringbuf.members]), the positioning operation fails.
Otherwise, the function assignsxbeg + newoff + offto the next pointer xnext.
Returns: pos_type(newoff), constructed from the resultant offset newoff(of typeoff_type), that stores the resultant stream position, if possible.
If the positioning operation fails, or if the constructed object cannot represent the resultant stream position, the return value ispos_type(off_type(-1)).
pos_type seekpos(pos_type sp, ios_base::openmode which= ios_base::in | ios_base::out) override;
Effects: Equivalent to seekoff(off_type(sp), ios_base::beg, which).
Returns: spto indicate success, orpos_type(off_type(-1))to indicate failure.
basic_streambuf<charT, traits>* setbuf(charT* s, streamsize n) override;
Effects: implementation-defined, except thatsetbuf(0, 0)has no effect.