| Table of Contents | Algorithms | Iterators | Numerics | ||
|---|---|---|---|---|---|
| Containers | Language Support | Strings | |||
| Diagnostics | Localization | Utilities | |||
| Index | Input/Output |
#include <streambuf.h>
<streambuf> defines types that control
input from and output to character sequences.
Each sequence is characterized by three pointers which, if non-null, all point into the same charT array object. The array object represents, at any moment, a (sub)sequence of characters from the sequence. Operations performed on a sequence alter the values stored in these pointers, perform reads and writes directly to or from associated sequences, and alter the stream position and conversion state as needed to maintain this subsequence relationship. The three pointers are:
The following semantic constraints shall always apply for any set of three pointers for a sequence, using the pointer names given immediately above:
basic_streambuf<charT,traits>
serves as an abstract base class for deriving various stream buffers
whose objects each control two character sequences:
Two specializations of this class has to be provided by the
implementation. The class streambuf which is an
instantiation of the template class basic_streambuf
specialized by the type char.The class wstreambuf
which is an instantiation of the template class
basic_streambuf specialized by the type wchar_t.
basic_streambuf are
implementation dependent. This implementation of the class has
six pointers. They are:
basic_streambuf();
basic_streambuf to assure that only objects for classes
derived from this class may be constructed. It constructs an object of
class basic_streambuf<charT, traits> and initializes
all its pointer member objects to null pointers and the
getloc() member to return value of
locale::classic().
locale pubimbue(const locale& loc);
This function calls imbue(loc) and resets the
basic_streambuf<charT, traits>::loc variable. It returns
the previous value of basic_streambuf<charT,
traits>::loc.
locale getloc() const;
pubimbue() has ever been called, then the last value
of loc supplied, otherwise classic "C" locale
locale::classic(). If called after
pubimbue() has been called but before
pubimbue() has returned(i.e from within the call of
imbue()) then it returns the previous value.
basic_streambuf<char_type,traits>*
pubsetbuf(char_type* s, streamsize n);
This function returns setbuf(s,n).
pos_type pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which=
seekoff(off,way, which).
pos_type pubseekpos(pos_type sp, ios_base::openmode which = ios_base::in |
seekpos(sp, which).
int pubsync();
sync().
streamsize in_avail();
showmanyc().
int_type snextc();
gnext) and then returns the value pointed to by
this pointer.
int_type sbumpc();
uflow(). Otherwise, returns
char_type(*gptr()) and increments the next pointer for the
input sequence(gnext), so that it points to the next
character in the input stream.
int_type sgetc();
underflow(). Otherwise, returns
char_type(*gptr()). This function does not increment the
next pointer for the input sequence(gnext).
streamsize sgetn(char_type* s, streamsize n);
xsgetn(s,n).
int_type sputbackc(char_type c);
gnext and gbeg are pointing to the same
position), or if c!=gptr()[-1], returns
pbackfail(c). Otherwise, decrements the next pointer for
the input sequence(gnext) and returns
*gptr().
int_type sungetc();
gnext and gbeg are pointing to the same
position), returns pbackfail(). Otherwise, decrements the
next pointer for the input sequence(gnext) and returns
*gptr().
int_type sputc(char_type c);
pnext and pend are pointing to the same
position), returns overflow(c). Otherwise, stores
c at the next pointer for the output
sequence(pnext), increments the pointer, and returns
*pptr().
int_type sputn(const char_type* s, streamsize n);
xsputn(s, n).
char_type* eback() const;
gbeg) for the input sequence.
char_type* gptr() const;
gnext) for the input sequence.
char_type* egptr() const;
gend) for the input sequence.
void gbump(int n);
gnext) for the input sequence
by n.
void setg(char_type* gbeg, char_type* gnext, char_type* gend);
gbeg, gnext and gend from the
arguments passed to it.
char_type* pbase() const;
pbeg).
char_type* pptr() const;
pnext).
char_type* epptr() const;
pend).
void pbump(int n);
pnext) for the output sequence
by n.
void setg(char_type* pbeg, char_type* pnext, char_type* pend);
pbeg,
pnext and pend from the arguments passed to
it.
void imbue(const locale&);
basic_streambuf* setbuf(char_type* s, streamsize n);
this.
pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which =
basic_streambuf. It returns an
object of class pos_type that stores an invalid
stream position(pos_type(-1)) by default.
pos_type seekpos(pos_type sp, ios_base::openmode which= in| out);
basic_streambuf in this clause. It returns an
object of class pos_type that stores an invalid stream
position.
int sync();
pbase() is non-null the cahracters between
pbase() and pptr() are written to the
controlled sequence, and if gptr() is non-null, the
characters between gptr() and egptr() are
restored to the input sequence. The pointers may then be reset
appropriately. It returns -1 on failure and 0 by default.
int showmanyc();
uflow() or underflow() returns
traits::eof(). A positive return value indicates that the
next such call will not return traits::eof(). It returns
zero by default.
streamsize xsgetn(char_type* s, streamsize n);
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().
It returns the number of characters assigned.
int_type underflow();
basic_streambuf call this
virtual function only if gptr() is null or
gptr()>=egptr().
The pending sequence of characters is defined as the concatenation of:
If gptr() is non-NULL, then the
egptr()-gptr() characters starting at gptr(),
otherwise the empty sequence.
Some sequence(possibly empty) of characters read from the input sequence.
The result character is
If the pending sequence is non-empty, the first character of the sequence.
If the pending sequence empty then the next character that would be read from the input sequence.
The backup sequence is defined as the concatenation of:
If eback() is null then empty.
Otherwise the gptr()-eback() characters beginning at
eback().
The function sets up the gptr() and egptr()
satisfying one of:
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.
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:
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.
Or the n characters starting at gptr()-n
agree with the backup sequence(where n is the length of
the backup sequence).
int_type uflow();
underflow(), except that the result character is
transferred from the pending sequence to the backup sequence, and the
pending sequence may not be empty before the transfer.
This function on default calls underflow(traits::eof()).
If underflow() returns traits::eof() returns
traits::eof(). Otherwise, does gbump(-1) and
returns *gptr().
int_type pbackfail(int c=traits::eof());
gptr() is null, gptr()==eback(), or
*gptr()!=c. Other calls shall also satisfy that
constraint.The pending sequence is defined as for
underflow(), with the modifications that
c==traits::eof() then the input sequence is
backed up one character before the pending sequence is determined.
c!=traits::eof() then c is
prepended. Whether the input sequence is backed up or modified in any
other way is unspecified.
This function returns traits::eof() to indicate failure.
Failure may occur because the input sequence could not be backed up, or
if for some other reason the pointers could not be set consistent with
the constraints. This function is called only when put back has
really failed. It returns some value other than
traits::eof() to indicate success.
streamsize xsputn(const char_type* s, streamsize n);
n characters to the output
sequence as if by repeated calls to sputc(c). The
characters written are obtained from successive elements of the array
whose first element is designated by s. Writing stops
when either n characters have been written or a call to
sputc(c) would return traits::eof(). This
function returns the number of characters written.
int_type overflow(int_type c=traits::eof());
if pbase() is NULL then the empty sequence otherwise,
pptr()-pbase() characters beginning at
pbase().
if c==traits::eof() then the empty sequence otherwise, the
sequence consisting of c.
The member functions sputc() and sputn() call
this function in case that no room can be found in the put buffer
enough to accommodate the argument character sequence.
This function requires every overriding definition of this virtual function shall obey the following constraints:
r be the number of characters in the pending
sequence not consumed. If r is non-zero then
pbase() and pptr() must be set so that:
pptr() - pbase()==r and the r characters
starting at pbase() are the associated output stream. In
case r is zero(all characters of the pending sequence have
been consumed) then either pbase() is set NULL, or
pbase() and pptr() are both set to the same
non-NULL value.
pbase() and pptr() according to the above
rules.
This function returns traits::eof() of throws an exception
if the function fails. Otherwise, returns some value other than
traits::eof() to indicate success.
Iostream Outline index Copyright © 1996. All rights reserved.
E-Mail KAI Technical Support E-Mail KAI Contact KAI
This file last updated on May 17, 1996.