std::basic_streambuf
Defined in header <streambuf>
|
||
template< class CharT, |
||
The class basic_streambuf controls input and output to a character sequence. It includes and provides access to the controlled character sequence (the buffer) and, optionally, the associated character sequence (file, I/O stream, TCP socket, etc).
It supports the following constraints:
- the controlled input sequence may not be readable.
- the controlled output sequence may not be writeable.
- the character representation and encoding in the controlled sequence may be different from the character representations in the associated sequence (a std::codecvt locale facet may be necessary to perform the conversion)
- the controlled sequence may be able to access the associated sequence directly.
- the controlled sequence may impose arbitrary limitations on reading, writing, seeking, or ungetting characters.
The controlled character sequence (the buffer) is an array of CharT which, at all times, represents a subsequence, or a "window" into the associated character sequence. Its state is described by three pointers:
1) The beginning pointer, always points at the lowest element of the buffer
2) The next pointer, points at the element that is the next candidate for reading or writing
3) The end pointer, points one past the end of the buffer.
If the next pointer is less than the end pointer in an output sequence, a write position is available. The next pointer can be dereferenced and assigned to.
If the next pointer is less than the end pointer in an input sequence, a read position is available. The next pointer can be dereferenced and read from.
If the next pointer is greater than the beginning pointer in an input sequence, a putback position is available, and the next pointer may be decremented, dereferenced, and assigned to, in order to put a character back into the input sequence.
A basic_streambuf object may support an input sequence (in which case the buffer described by the beginning, next, and end pointers is called get area), an output sequence (put area), or an input/output sequence. In latter case, six pointers are tracked, which may all point to elements of the same character array or two individual arrays.
Typical implementation of the std::basic_streambuf base class holds only these six CharT* pointers and a copy of std::locale as data members. The buffers themselves are implemented by the derived classes such as std::basic_filebuf or std::basic_stringbuf.
This section is incomplete Reason: Consistent terminology across the pages. Probably input/output sequence, get/put area, etc. |
Two convenience typedefs are provided by the standard library
Defined in header <streambuf>
| |
Type | Definition |
streambuf | basic_streambuf<char> |
wstreambuf | basic_streambuf<wchar_t> |
The I/O stream objects std::basic_istream, std::basic_ostream, and derived, are implemented entirely in terms of std::basic_streambuf.
Contents |
[edit] Member types
Member type | Definition |
char_type | CharT |
traits_type | Traits |
int_type | Traits::int_type |
pos_type | Traits::pos_type |
off_type | Traits::off_type |
[edit] Member functions
[virtual] |
destructs the basic_streambuf object (virtual public member function) |
Locales | |
invokes imbue() (public member function) | |
obtains a copy of the associated locale (public member function) | |
Positioning | |
invokes setbuf() (public member function) | |
invokes seekoff() (public member function) | |
invokes seekpos() (public member function) | |
invokes sync() (public member function) | |
Get area | |
obtains the number of characters immediately available in the get area (public member function) | |
advances the input sequence, then reads one character without advancing again (public member function) | |
reads one character from the input sequence and advances the sequence (public member function) | |
stossc (deprecated) |
advances the input sequence as if by calling sbumpc() and discarding the result (public member function) |
reads one character from the input sequence without advancing the sequence (public member function) | |
invokes xsgetn() (public member function) | |
Put area | |
writes one character to the put area and advances the next pointer (public member function) | |
invokes xsputn() (public member function) | |
Putback | |
puts one character back in the input sequence (public member function) | |
moves the next pointer in the input sequence back by one (public member function) | |
Protected member functions | |
constructs a basic_streambuf object (protected member function) | |
(C++11) |
replaces a basic_streambuf object (protected member function) |
(C++11) |
swaps two basic_streambuf objects (protected member function) |
Locales | |
[virtual] |
changes the associated locale (virtual protected member function) |
Positioning | |
[virtual] |
replaces the buffer with user-defined array, if permitted (virtual protected member function) |
[virtual] |
repositions the next pointer in the input sequence, output sequence, or both, using relative addressing (virtual protected member function) |
[virtual] |
repositions the next pointer in the input sequence, output sequence, or both using absolute addressing (virtual protected member function) |
[virtual] |
synchronizes the buffers with the associated character sequence (virtual protected member function) |
Get area | |
[virtual] |
obtains the number of characters available for input in the associated input sequence, if known (virtual protected member function) |
[virtual] |
reads characters from the associated input sequence to the get area (virtual protected member function) |
[virtual] |
reads characters from the associated input sequence to the get area and advances the next pointer (virtual protected member function) |
[virtual] |
reads multiple characters from the input sequence (virtual protected member function) |
returns a pointer to the beginning, current character and the end of the get area (protected member function) | |
advances the next pointer in the input sequence (protected member function) | |
repositions the beginning, next, and end pointers of the input sequence (protected member function) | |
Put area | |
[virtual] |
writes multiple characters to the output sequence (virtual protected member function) |
[virtual] |
writes characters to the associated output sequence from the put area (virtual protected member function) |
returns a pointer to the beginning, current character and the end of the put area (protected member function) | |
advances the next pointer of the output sequence (protected member function) | |
repositions the beginning, next, and end pointers of the output sequence (protected member function) | |
Putback | |
[virtual] |
puts a character back into the input sequence, possibly modifying the input sequence (virtual protected member function) |