basic_streambuf Class
Describes an abstract base class for deriving a stream buffer, which controls the transmission of elements to and from a specific representation of a stream.
template<class Elem, class Tr = char_traits<Elem> >
class basic_streambuf;
Parameters
Elem
A char_type.Tr
The character traits_type.
Remarks
The template class describes an abstract base class for deriving a stream buffer, which controls the transmission of elements to and from a specific representation of a stream. An object of class basic_streambuf helps control a stream with elements of type Tr, also known as char_type, whose character traits are determined by the class char_traits, also known as traits_type.
Every stream buffer conceptually controls two independent streams: one for extractions (input) and one for insertions (output). A specific representation may, however, make either or both of these streams inaccessible. It typically maintains some relationship between the two streams. What you insert into the output stream of a basic_stringbuf<Elem, Tr> object, for example, is what you later extract from its input stream. When you position one stream of a basic_filebuf<Elem, Tr> object, you position the other stream in tandem.
The public interface to template class basic_streambuf supplies the operations that are common to all stream buffers, however specialized. The protected interface supplies the operations needed for a specific representation of a stream to do its work. The protected virtual member functions let you tailor the behavior of a derived stream buffer for a specific representation of a stream. Each derived stream buffer in this library describes how it specializes the behavior of its protected virtual member functions. The default behavior for the base class, which is often to do nothing, is described in this topic.
The remaining protected member functions control copying to and from any storage supplied to buffer transmissions to and from streams. An input buffer, for example, is characterized by:
eback, a pointer to the beginning of the buffer.
gptr, a pointer to the next element to read.
egptr, a pointer just past the end of the buffer.
Similarly, an output buffer is characterized by:
pbase, a pointer to the beginning of the buffer.
pptr, a pointer to the next element to write.
epptr, a pointer just past the end of the buffer.
For any buffer, the following protocol is used:
If the next pointer is null, no buffer exists. Otherwise, all three pointers point into the same sequence. They can be safely compared for order.
For an output buffer, if the next pointer compares less than the end pointer, you can store an element at the write position designated by the next pointer.
For an input buffer, if the next pointer compares less than the end pointer, you can read an element at the read position designated by the next pointer.
For an input buffer, if the beginning pointer compares less than the next pointer, you can put back an element at the putback position designated by the decremented next pointer.
Any protected virtual member functions you write for a class derived from basic_streambuf<Elem, Tr> must cooperate in maintaining this protocol.
An object of class basic_streambuf<Elem, Tr> stores the six pointers previously described. It also stores a locale object in an object of type locale for potential use by a derived stream buffer.
Constructors
Constructs an object of type basic_streambuf. |
Typedefs
Associates a type name with the Elem template parameter. |
|
Associates a type name within basic_streambuf scope with the Elem template parameter. |
|
Associates a type name within basic_streambuf scope with the Elem template parameter. |
|
Associates a type name within basic_streambuf scope with the Elem template parameter. |
|
Associates a type name with the Tr template parameter. |
Member Functions
A protected function that returns a pointer to the beginning of the input buffer. |
|
A protected function that returns a pointer just past the end of the input buffer. |
|
A protected function that returns a pointer just past the end of the output buffer. |
|
A protected function that adds _Count to the next pointer for the input buffer. |
|
Gets the basic_streambuf object's locale. |
|
A protected function that returns a pointer to the next element of the input buffer. |
|
A protected, virtual function called by pubimbue. |
|
Returns the number of elements that are ready to be read from the buffer. |
|
A protected virtual function that can be called when a new character is inserted into a full buffer. |
|
A protected virtual member function that tries to put back an element into the input stream, then make it the current element (pointed to by the next pointer). |
|
A protected function that returns a pointer to the beginning of the output buffer. |
|
A protected function that adds count to the next pointer for the output buffer. |
|
A protected function that returns a pointer to the next element of the output buffer. |
|
Sets the basic_streambuf object's locale. |
|
Calls seekoff, a protected virtual function that is overridden in a derived class. |
|
Calls seekpos, a protected virtual function that is overridden in a derived class and resets the current pointer position. |
|
Calls setbuf, a protected virtual function that is overridden in a derived class. |
|
Calls sync, a protected virtual function that is overridden in a derived class and updates the external stream associated with this buffer. |
|
Reads and returns the current element, moving the stream pointer. |
|
The protected virtual member function tries to alter the current positions for the controlled streams. |
|
The protected virtual member function tries to alter the current positions for the controlled streams. |
|
The protected virtual member function performs an operation particular to each derived stream buffer. |
|
A protected function that stores _Gbeg in the beginning pointer, _Gnext in the next pointer, and _Gend in the end pointer for the input buffer. |
|
A protected function that stores _Pbeg in the beginning pointer and _Pend in the end pointer for the output buffer. |
|
Returns current element without changing position in the stream. |
|
Returns the number of elements read. |
|
Protected virtual member function that returns a count of the number of characters that can be extracted from the input stream and ensure that the program will not be subject to an indefinite wait. |
|
Reads the current element and returns the following element. |
|
Puts a char_type in the stream. |
|
Puts a character into the stream. |
|
Puts a character string into the stream. |
|
Move past the current element in the stream. |
|
Gets a character from the stream. |
|
Exchanges the values in this object for the values in the provided basic_streambuf object parameter. |
|
A protected virtual function that tries to synchronize the controlled streams with any associated external streams. |
|
A protected virtual function that extracts the current element from the input stream. |
|
A protected virtual function that extracts the current element from the input stream. |
|
A protected virtual function that extracts elements from the input stream. |
|
A protected virtual function that inserts elements into the output stream. |
Operators
Assigns the values of this object from another basic_streambuf object. |
Requirements
Header: <streambuf>
Namespace: std