<streambuf>
Include the iostreams
standard header <streambuf>
to define
class streambuf
,
which is basic to the operation of the iostreams classes.
(This header is typically included for you by another
of the iostreams headers. You seldom have occasion to include it
directly.)
// DECLARATIONS class streambuf; // END OF DECLARATIONS
streambuf
streambuf
· char_type
· eback
· egptr
· epptr
· gbump
· getloc
· gptr
· imbue
· in_avail
· int_type
· off_type
· overflow
· pbackfail
· pbase
· pbump
· pos_type
· pptr
· pubimbue
· pubseekoff
· pubseekpos
· pubsetbuf
· pubsync
· sbumpc
· seekoff
· seekpos
· setbuf
· setg
· setp
· sgetc
· sgetn
· showmanyc
· snextc
· sputbackc
· sputc
· sputn
· stossc
· sungetc
· sync
· traits_type
· uflow
· underflow
· xsgetn
· xsputn
class streambuf { public: typedef char char_type; typedef char_traits traits_type; typedef traits_type::int_type int_type; typedef traits_type::pos_type pos_type; typedef traits_type::off_type off_type; virtual ~streambuf(); locale pubimbue(const locale& loc); locale getloc() const; streambuf *pubsetbuf(char_type *buffer, streamsize count); pos_type pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out); pos_type pubseekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out); int pubsync(); streamsize in_avail(); int_type snextc(); int_type sbumpc(); int_type sgetc(); void stossc(); [optional] streamsize sgetn(char_type *ptr, streamsize count); int_type sputbackc(char_type ch); int_type sungetc(); int_type sputc(char_type ch); streamsize sputn(const char_type *ptr, streamsize count); protected: streambuf(); char_type *eback() const; char_type *gptr() const; char_type *egptr() const; void gbump(int count); void setg(char_type *gbeg, char_type *gnext, char_type *gend); char_type *pbase() const; char_type *pptr() const; char_type *epptr() const; void pbump(int count); void setp(char_type *pbeg, char_type *pend); virtual void imbue(const locale &loc); virtual streambuf *setbuf(char_type *buffer, streamsize count); virtual pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out); virtual pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out); virtual int sync(); virtual streamsize showmanyc(); virtual streamsize xsgetn(char_type *ptr, streamsize count); virtual int_type underflow(); virtual int_type uflow(); virtual int_type pbackfail(int_type meta = traits_type::eof()); virtual streamsize xsputn(const char_type *ptr, streamsize count); virtual int_type overflow(int_type meta = traits_type::eof()); };
The 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
streambuf
helps control
a stream with elements of type char, 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, in fact, 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
stringbuf
object, for example, is what you later extract from its input stream.
And when you position one stream of a
filebuf
object, you position the other stream in tandem.
The public interface to template class
streambuf
supplies the operations 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 of the derived stream buffers
in this library describes how it specializes the
behavior of its protected virtual member functions. Documented
here is the default behavior for the base class,
which is often to do nothing.
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 protocol is:
Any protected virtual member functions you write for a
class derived from streambuf
must cooperate in maintaining this protocol.
An object of class streambuf
stores the six pointers described above.
streambuf::streambuf
streambuf();
The protected constructor stores a null pointer in all the pointers controlling the input buffer and the output buffer.
streambuf::char_type
typedef char char_type;
The type is a synonym for char.
streambuf::eback
char_type *eback() const;
The member function returns a pointer to the beginning of the input buffer.
streambuf::egptr
char_type *egptr() const;
The member function returns a pointer just past the end of the input buffer.
streambuf::epptr
char_type *epptr() const;
The member function returns a pointer just past the end of the output buffer.
streambuf::gbump
void gbump(int count);
The member function adds count
to the next pointer for the
input buffer.
streambuf::getloc
locale getloc() const;
The member function returns the stored locale object.
streambuf::gptr
char_type *gptr() const;
The member function returns a pointer to the next element of the input buffer.
streambuf::imbue
virtual void imbue(const locale &loc);
The default behavior is to do nothing.
streambuf::in_avail
streamsize in_avail();
If a read position is available,
the member function returns
egptr() -
gptr()
.
Otherwise, it returns
showmanyc()
.
streambuf::int_type
typedef traits_type::int_type int_type;
The type is a synonym for
traits_type::int_type
.
streambuf::off_type
typedef traits_type::off_type off_type;
The type is a synonym for
traits_type::off_type
.
streambuf::overflow
virtual int_type overflow(int_type meta = traits_type::eof());
If meta
does not compare equal to
traits_type::eof()
,
the protected virtual member function endeavors to insert the element
traits_type:: to_char_type(meta)
into the output stream. It can do so in various ways:
If the function cannot succeed, it returns
traits_type::eof()
or throws an exception.
Otherwise, it returns
traits_type::not_eof(meta)
.
The default behavior is to return traits_type::eof()
.
streambuf::pbackfail
virtual int_type pbackfail(int_type meta = traits_type::eof());
The protected virtual member function endeavors to put back an element
into the input stream, then make it the current element (pointed to
by the next pointer).
If meta
compares equal to
traits_type::eof()
,
the element to push back is effectively the one already in the stream
before the current element. Otherwise, that element is replaced by
traits_type::
to_char_type(meta)
.
The function can put back an element in various ways:
If the function cannot succeed, it returns
traits_type::eof()
or throws an exception. Otherwise,
it returns some other value.
The default behavior is to return traits_type::eof()
.
streambuf::pbase
char_type *pbase() const;
The member function returns a pointer to the beginning of the output buffer.
streambuf::pbump
void pbump(int count);
The member function adds count
to the next pointer for the
output buffer.
streambuf::pos_type
typedef traits_type::pos_type pos_type;
The type is a synonym for
traits_type::pos_type
.
streambuf::pptr
char_type *pptr() const;
The member function returns a pointer to the next element of the output buffer.
streambuf::pubimbue
locale pubimbue(const locale& loc);
The member function stores loc
in the
locale object, calls
imbue()
,
then returns the previous value stored in the locale object.
streambuf::pubseekoff
pos_type pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out);
The member function returns
seekoff(off, way,
which)
.
streambuf::pubseekpos
pos_type pubseekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out);
The member function returns
seekpos(sp, which)
.
streambuf::pubsetbuf
streambuf *pubsetbuf(char_type *buffer, streamsize count);
The member function returns
setbuf(buffer, count)
.
streambuf::pubsync
int pubsync();
The member function returns
sync()
.
streambuf::sbumpc
int_type sbumpc();
If a read position is available,
the member function returns
traits_type::to_int_type(
*gptr())
and increments the next pointer for the
input buffer.
Otherwise, it returns
uflow()
.
streambuf::seekoff
virtual pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out);
The protected virtual member function endeavors to alter the current positions for the controlled streams. The new position is determined as follows:
way ==
ios_base::beg
,
the new position is the beginning of the stream plus off
.
way ==
ios_base::cur
,
the new position is the current stream position plus off
.
way ==
ios_base::end
,
the new position is the end of the stream plus off
.
Typically, if
which & ios_base::in
is nonzero,
the input stream is affected, and if which & ios_base::out
is nonzero, the output stream is affected. Actual use of this parameter
varies among derived stream buffers, however.
If the function succeeds in altering the stream position(s), it returns the resultant stream position (or one of them). Otherwise, it returns an invalid stream position. The default behavior is to return an invalid stream position.
streambuf::seekpos
virtual pos_type seekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out);
The protected virtual member function endeavors to alter the current
positions for the controlled streams.
The new position is sp
.
Typically, if
which & ios_base::in
is nonzero,
the input stream is affected, and if which & ios_base::out
is nonzero, the output stream is affected. Actual use of this parameter
varies among derived stream buffers, however.
If the function succeeds in altering the stream position(s), it returns the resultant stream position (or one of them). Otherwise, it returns an invalid stream position. The default behavior is to return an invalid stream position.
streambuf::setbuf
virtual streambuf *setbuf(char_type *buffer, streamsize count);
The protected virtual member function performs an operation
particular to each derived stream buffer. (See, for example,
filebuf
.)
The default behavior is to return this
.
streambuf::setg
void setg(char_type *gbeg, char_type *gnext, char_type *gend);
The member function stores gbeg
in the beginning pointer,
gnext
in the next pointer,
and gend
in the end pointer for the
input buffer.
streambuf::setp
void setp(char_type *pbeg, char_type *pend);
The member function stores pbeg
in the beginning pointer,
pbeg
in the next pointer,
and pend
in the end pointer for the
output buffer.
streambuf::sgetc
int_type sgetc();
If a read position is available,
the member function returns
traits_type::to_int_type(
*gptr())
Otherwise, it returns
underflow()
.
streambuf::sgetn
streamsize sgetn(char_type *ptr, streamsize count);
The member function returns
xsgetn(ptr, count)
.
streambuf::showmanyc
virtual streamsize showmanyc();
The protected virtual member function returns a count of the number of characters that can be extracted from the input stream with no fear that the program will suffer an indefinite wait. The default behavior is to return zero.
streambuf::snextc
int_type snextc();
The member function calls
sbumpc()
and,
if that function returns
traits_type::eof()
,
returns traits_type::eof()
.
Otherwise, it returns
sgetc()
.
streambuf::sputbackc
int_type sputbackc(char_type ch);
If a putback position is available
and ch
compares equal to the character stored in that position,
the member function decrements the next pointer for the
input buffer and returns
traits_type::to_int_type(ch)
.
Otherwise, it returns
pbackfail(ch)
.
streambuf::sputc
int_type sputc(char_type ch);
If a write position is available,
the member function stores ch
in the write position,
increments the next pointer for the
output buffer, and returns
traits_type::to_int_type(ch)
.
Otherwise, it returns
overflow(ch)
.
streambuf::sputn
streamsize sputn(const char_type *ptr, streamsize count);
The member function returns
xsputn(ptr, count)
.
streambuf::stossc
void stossc(); [optional]
The member function calls
sbumpc()
.
Note that an implementation is not required to supply this member function.
streambuf::sungetc
int_type sungetc();
If a putback position is available,
the member function decrements the next pointer for the
input buffer and returns
traits_type::to_int_type(
*gptr())
.
Otherwise it returns
pbackfail()
.
streambuf::sync
virtual int sync();
The protected virtual member function endeavors to synchronize the controlled streams with any associated external streams. Typically, this involves writing out any elements between the beginning and next pointers for the output buffer. It does not involve putting back any elements between the next and end pointers for the input buffer. If the function cannot succeed, it returns -1. The default behavior is to return zero.
streambuf::traits_type
typedef char_traits traits_type;
The type is a synonym for
char_traits
.
streambuf::uflow
virtual int_type uflow();
The protected virtual member function endeavors to extract the current
element ch
from the input stream,
then advance the current stream position, and return the element as
traits_type::to_int_type(ch)
.
It can do so in various ways:
ch
as the element stored in the read position
and advances the next pointer for the
input buffer.
ch
.
If the function cannot succeed, it returns
traits_type::eof()
,
or throws an exception. Otherwise,
it returns the current element ch
in the input stream,
converted as described above, and advances the next pointer
for the input buffer. The default behavior is to call
underflow()
and, if that function returns traits_type::eof()
,
to return traits_type::eof()
. Otherwise, the function
returns the current element ch
in the input stream,
converted as described above, and advances the next pointer
for the input buffer.
streambuf::underflow
virtual int_type underflow();
The protected virtual member function endeavors to extract the current
element ch
from the input stream,
without advancing the current stream position, and return it as
traits_type::to_int_type(ch)
.
It can do so in various ways:
ch
is the element stored in the read position.
If the function cannot succeed, it returns
traits_type::eof()
,
or throws an exception. Otherwise,
it returns the current element in the input stream,
converted as described above.
The default behavior is to return traits_type::eof()
.
streambuf::xsgetn
virtual streamsize xsgetn(char_type *ptr, streamsize count);
The protected virtual member function extracts up to count
elements from the input stream, as if by repeated calls to
sbumpc
,
and stores them in the array beginning at ptr
.
It returns the number of elements actually extracted.
streambuf::xsputn
virtual streamsize xsputn(const char_type *ptr, streamsize count);
The protected virtual member function inserts up to count
elements into the output stream, as if by repeated calls to
sputc
,
from the array beginning at ptr
.
It returns the number of elements actually inserted.
See also the Table of Contents and the Index.
Copyright © 1992-2002 by P.J. Plauger. All rights reserved.