27 Input/output library [input.output]

27.6 Stream buffers [stream.buffers]

27.6.3 Class template basic_streambuf<charT,traits> [streambuf]

27.6.3.4 basic_streambuf virtual functions [streambuf.virtuals]

27.6.3.4.3 Get area [streambuf.virt.get]

streamsize showmanyc();307

Returns: An estimate of the number of characters available in the sequence, or -1. If it returns a positive value, then successive calls to underflow() will not return traits::eof() until at least that number of characters have been extracted from the stream. If showmanyc() returns -1, then calls to underflow() or uflow() will fail.308

Default behavior: Returns zero.

Remarks: Uses traits::eof().

streamsize xsgetn(char_type* s, streamsize n);

Effects: Assigns up to n characters to successive elements of the array whose first element is designated by s. The characters assigned are read from the input sequence as if by repeated calls to sbumpc(). Assigning stops when either n characters have been assigned or a call to sbumpc() would return traits::eof().

Returns: The number of characters assigned.309

Remarks: Uses traits::eof().

int_type underflow();

Remarks: The public members of basic_streambuf call this virtual function only if gptr() is null or gptr() >= egptr()

Returns: traits::to_int_type(c), where c is the first character of the pending sequence, without moving the input sequence position past it. If the pending sequence is null then the function returns traits::eof() to indicate failure.

The pending sequence of characters is defined as the concatenation of:

  1. If gptr() is non- NULL, then the egptr() - gptr() characters starting at gptr(), otherwise the empty sequence.

  2. Some sequence (possibly empty) of characters read from the input sequence.

The result character is

  1. If the pending sequence is non-empty, the first character of the sequence.

  2. If the pending sequence is empty then the next character that would be read from the input sequence.

The backup sequence is defined as the concatenation of:

  1. If eback() is null then empty,

  2. Otherwise the gptr() - eback() characters beginning at eback().

Effects: The function sets up the gptr() and egptr() satisfying one of:

  1. If the pending sequence is non-empty, egptr() is non-null and egptr() - gptr() characters starting at gptr() are the characters in the pending sequence

  2. If the pending sequence is empty, either gptr() is null or gptr() and egptr() are set to the same non-NULL pointer.

If eback() and gptr() are non-null then the function is not constrained as to their contents, but the “usual backup condition” is that either:

  1. If the backup sequence contains at least gptr() - eback() characters, then the gptr() - eback() characters starting at eback() agree with the last gptr() - eback() characters of the backup sequence.

  2. Or the n characters starting at gptr() - n agree with the backup sequence (where n is the length of the backup sequence)

Default behavior: Returns traits::eof().

int_type uflow();

Requires: The constraints are the same as for underflow(), except that the result character shall be transferred from the pending sequence to the backup sequence, and the pending sequence shall not be empty before the transfer.

Default behavior: Calls underflow(). If underflow() returns traits::eof(), returns traits::eof(). Otherwise, returns the value of traits::to_int_type(*gptr()) and increment the value of the next pointer for the input sequence.

Returns: traits::eof() to indicate failure.

The morphemes of showmanyc are “es-how-many-see”, not “show-manic”.

underflow or uflow might fail by throwing an exception prematurely. The intention is not only that the calls will not return eof() but that they will return “immediately.”

Classes derived from basic_streambuf can provide more efficient ways to implement xsgetn() and xsputn() by overriding these definitions from the base class.