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
·
sungetc
·
sync
·
traits_type
·
uflow
·
underflow
·
xsgetn
·
xsputn
template <class E, class T = char_traits<E> >
class basic_streambuf {
public:
typedef E char_type;
typedef T traits_type;
typedef T::int_type int_type;
typedef T::pos_type pos_type;
typedef T::off_type off_type;
virtual ~streambuf();
locale pubimbue(const locale& loc);
locale getloc() const;
basic_streambuf *pubsetbuf(E *s, streamsize n);
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();
streamsize sgetn(E *s, streamsize n);
int_type sputbackc(E c);
int_type sungetc();
int_type sputc(E c);
streamsize sputn(const E *s, streamsize n);
protected:
basic_streambuf();
E *eback() const;
E *gptr() const;
E *egptr() const;
void gbump(int n);
void setg(E *gbeg, E *gnext, E *gend);
E *pbase() const;
E *pptr() const;
E *epptr() const;
void pbump(int n);
void setp(E *pbeg, E *pend);
virtual void imbue(const locale &loc);
virtual basic_streambuf *setbuf(E *s, streamsize n);
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 int showmanyc();
virtual streamsize xsgetn(E *s, streamsize n);
virtual int_type underflow();
virtual int_type uflow();
virtual int_type pbackfail(int_type c = T::eof());
virtual streamsize xsputn(const E *s, streamsize n);
virtual int_type overflow(int_type c = T::eof());
};
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<E, T>
helps control
a stream with elements of type E
, whose character traits are determined by the class T
.
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
basic_stringbuf
<E, T>
object, for example, is what you later extract from its input stream. When you position
one stream of a basic_filebuf
<E, T>
object, you position the other stream in tandem.
The public interface to template class basic_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 the Standard C++ 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 basic_streambuf<E, T>
must cooperate
in maintaining this protocol.
An object of class basic_streambuf<E, T>
stores the six pointers described above. It also stores a locale object in
an object of type locale
for potential use by a derived stream buffer.