.\" ident @(#)basic_streambuf.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH basic_streambuf 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2basic_streambuf\fP, \f2streambuf\fP, \f2wstreambuf\fP \ - Abstract base class for deriving various stream buffers to facilitate control of character sequences. .SH SYNOPSIS .br #include .br template > .br class basic_streambuf; .SH DESCRIPTION The class template basic_streambuf serves as an abstract base class for deriving various stream buffers to facilitate control of character sequences such as: .HP .5i \(bu A character input sequence; .HP .5i \(bu A character output sequence. .HP 0 Each sequence is associated with three pointers (as described below), which, if non-null, all point into the same \f2charT\fP array object. The array object represents, at any moment, a segment of characters from the sequence. Operations performed on a sequence alter the values pointed to by 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 segment to sequence relationship. The three pointers are: .HP .5i \(bu The beginning pointer, or lowest element address in the array; .HP .5i \(bu The next pointer, or next element address that is a current candidate for reading or writing; .HP .5i \(bu The end pointer, or first element address beyond the end of the array. .HP 0 Stream buffers can impose various constraints on the sequences they control, including: .HP .5i \(bu The controlled input sequence may be unreadable; .HP .5i \(bu The controlled output sequence may be unwriteable; .HP .5i \(bu The controlled sequences can be associated with the contents of other representations for character sequences, such as external files; .HP .5i \(bu The controlled sequences can impose limitations on how the program can read characters from a sequence, write characters to a sequence, put characters back into an input sequence, or alter the stream position. .HP 0 .SH INTERFACE .br template > .br class basic_streambuf { .br .br public: .RE .RS 5 .RE .RS 0 typedef charT char_type; .br typedef traits traits_type; .br .br typedef typename traits::int_type int_type; .br typedef typename traits::pos_type pos_type; .br typedef typename traits::off_type off_type; .br .br .br virtual ~basic_streambuf(); .br .br locale pubimbue( const locale& loc); .br locale getloc() const; .br .br basic_streambuf * .RE .RS 2 pubsetbuf(char_type *s, streamsize n); .RE .RS 0 .br pos_type pubseekoff(off_type off, ios_base::seekdir way, .RE .RS 20 ios_base::openmode which = .br ios_base::in | ios_base::out); .RE .RS 0 .br pos_type pubseekpos(pos_type sp, ios_base::openmode which = .RE .RS 20 ios_base::in | ios_base::out); .RE .RS 0 .br int pubsync(); .RE .RS 1 .RE .RS 0 ios_base::openmode which_open_mode(); .RE .RS 1 .RE .RS 0 streamsize in_avail(); .br int_type snextc(); .br int_type sbumpc(); .br int_type sgetc(); .br streamsize sgetn(char_type *s, streamsize n); .br .br int_type sputbackc(char_type c); .br int sungetc(); .br .br int_type sputc(char_type c); .br streamsize sputn(const char_type *s, streamsize n); .br .br protected: .br .br basic_streambuf(); .RE .RS 5 .RE .RS 0 char_type *eback() const; .br char_type *gptr() const; .br char_type *egptr() const; .br .br void gbump(int n); .br void setg(char_type *gbeg_arg,char_type *gnext_arg, .RE .RS 10 char_type *gend_arg); .RE .RS 0 .br char_type *pbase() const; .br char_type *pptr() const; .br char_type *epptr() const; .br void pbump(int n); .br void setp(char_type *pbeg_arg,char_type *pend_arg); .br .br virtual void imbue( const locale& loc); .br .br virtual basic_streambuf* .RE .RS 2 setbuf(char_type *s, streamsize n); .RE .RS 0 .br virtual pos_type seekoff(off_type off, .RE .RS 25 ios_base::seekdir way, .br ios_base::openmode which = .br ios_base::in | ios_base::out); .RE .RS 0 .br virtual pos_type seekpos(pos_type sp, .RE .RS 25 ios_base::openmode which = .br ios_base::in | ios_base::out); .RE .RS 0 .br virtual int showmanyc(); .br virtual streamsize xsgetn(char_type *s, streamsize n); .br .br virtual int_type underflow(); .br virtual int_type uflow(); .br .br virtual int_type pbackfail(int_type c = traits::eof()); .br virtual streamsize xsputn(const char_type *s, .RE .RS 26 streamsize n); .RE .RS 0 virtual int_type overflow(int_type c = traits::eof()); .RE .RS 1 .RE .RS 0 virtual int sync(); .br .br }; .SH TYPES .br char_type .RE .RS 3 The type \f2char_type\fP is a synonym for the template parameter \f2charT\fP. .RE .br int_type .RE .RS 3 The type \f2int_type\fP is a synonym of type \f2traits::in_type\fP. .RE .br off_type .RE .RS 3 The type\f2 off_type\fP is a synonym of type \f2traits::off_type\fP. .RE .br pos_type .RE .RS 3 The type \f2pos_type\fP is a synonym of type \f2traits::pos_type\fP. .RE .br streambuf .RE .RS 3 The type \f2streambuf\fP is an instantiation of class \f2basic_streambuf\fP on type \f2char\fP: \f2typedef basic_streambuf streambuf;\fP .RE .br traits_type .RE .RS 3 The type \f2traits_type\fP is a synonym for the template parameter \f2traits\fP. .RE .br wstreambuf .RE .RS 3 The type \f2wstreambuf\fP is an instantiation of class \f2basic_streambuf\fP on type \f2wchar_t\fP: \f2typedef basic_streambuf wstreambuf;\fP .RE .SH PUBLIC CONSTRUCTORS .br basic_streambuf(); .RE .RS 3 Constructs an object of class \f2basic_streambuf\fP. Initializes all its pointer member objects to null pointers, and initializes the \f2getloc()\fP member function to return the value of \f2locale::locale()\fP. .RE .SH PUBLIC DESTRUCTORS .br virtual ~basic_streambuf(); .RE .RS 3 Destroys an object of class \f2basic_streambuf\fP. .RE .SH PUBLIC MEMBER FUNCTIONS .br locale .br getloc() const; .RE .RS 3 If \f2pubimbue()\fP has ever been called, returns the last value of \f2loc\fP supplied. Otherwise, it returns the default (global) locale \f2locale::locale()\fP in effect at the time of construction. .RE .br streamsize .br in_avail(); .RE .RS 3 If a read position is available, returns the number of available characters in the input sequence. Otherwise calls the protected function \f2showmanyc()\fP. .RE .br locale .br pubimbue(const locale& loc); .RE .RS 3 Calls the protected function \f2imbue(loc)\fP. .RE .br pos_type .br pubseekoff(off_type off, ios_base::seekdir way, .RE .RS 10 ios_base::openmode which = .br ios_base::in | ios_base::out ); .RE .RS 3 Calls the protected function \f2seekoff(off,way,which)\fP. .RE .RE .RS 0 pos_type .br pubseekpos(pos_type sp, ios_base::openmode which= .RE .RS 10 ios_base::in | ios_base::out ); .RE .RS 3 Calls the protected function \f2seekpos(sp,which)\fP. .RE .RE .RS 0 basic_streambuf* .br pubsetbuf(char_type* s,streamsize n); .RE .RS 3 Calls the protected function \f2setbuf(s,n)\fP . .RE .br int .br pubsync(); .RE .RS 3 Calls the protected function\f2 sync()\fP. .RE .br int_type .br sbumpc(); .RE .RS 3 If the input sequence read position is not available, calls the function \f2uflow()\fP. Otherwise it returns \f2*gptr()\fP and increments the next pointer for the input sequence. .RE .br int_type .br sgetc(); .RE .RS 3 If the input sequence read position is not available, calls the protected function \f2underflow()\fP. Otherwise it returns\f2 *gptr()\fP. .RE .br streamsize .br sgetn(char_type* s, streamsize n); .RE .RS 3 Calls the protected function \f2xsgetn(s,n)\fP. .RE .br int_type .br snextc(); .RE .RS 3 Calls the function \f2sbumpc()\fP and if it returns \f2traits::eof()\fP, returns \f2traits::eof()\fP. Otherwise it calls the function \f2sgetc()\fP. .RE .br int_type .br sputbackc(char_type c); .RE .RS 3 If the input sequence putback position is not available or if \f2traits::eq(c,gptr() [-1])\fP returns \f2false\fP, calls the protected function \f2pbackfail(c)\fP. Otherwise it decrements the next pointer for the input sequence and returns \f2*gptr()\fP. .RE .br int_type .br sputc(char_type c); .RE .RS 3 If the output sequence write position is not available, calls the protected function \f2overflow(traits::to_int_type( c ))\fP. Otherwise, it stores \f2c\fP at the next pointer for the output sequence, increments the pointer, and returns \f2*pptr()\fP. .RE .br streamsize .br sputn(const char_type* s, streamsize n); .RE .RS 3 Calls the protected function \f2xsputn(s,n)\fP. .RE .br int_type .br sungetc(); .RE .RS 3 If the input sequence putback position is not available, calls the protected function \f2pbackfail().\fP Otherwise it decrements the next pointer for the input sequence and returns \f2*gptr()\fP. .RE .br ios_base::openmode .br which_open_mode(); .RE .RS 3 Returns the mode in which the stream buffer is opened. This function is not described in the C++ standard. .RE .SH PROTECTED MEMBER FUNCTIONS .br char_type* .br eback() const; .RE .RS 3 Returns the beginning pointer for the input sequence. .RE .br char_type* .br egptr() const; .RE .RS 3 Returns the end pointer for the input sequence. .RE .br char_type* .br epptr() const; .RE .RS 3 Returns the end pointer for the output sequence. .RE .br void .br gbump(int n); .RE .RS 3 Advances the next pointer for the input sequence by \f2n\fP. .RE .br char_type* .br gptr() const; .RE .RS 3 Returns the next pointer for the input sequence. .RE .br void .br imbue(const locale&); .RE .RS 3 Changes any translations based on locale. The default behavior is to do nothing. This function has to be overloaded in the classes derived from \f2basic_streambuf\fP. The purpose of this function is to allow the derived class to be informed of changes in locale at the time they occur. The new imbued locale object is only used by the stream buffer; it does not affect the stream itself. .RE .br int_type .br overflow(int_type c = traits::eof() ); .RE .RS 3 The member functions \f2sputc()\fP and \f2sputn()\fP call this function when not enough room can be found in the put buffer to accommodate the argument character sequence. The function returns\f2 traits::eof()\fP if it fails to make more room available or if it fails to empty the buffer by writing the characters to their output device. .RE .br int_type .br pbackfail(int_type c = traits::eof() ); .RE .RS 3 If \f2c\fP is equal to \f2traits::eof()\fP, \f2gptr()\fP is moved back one position. Otherwise \f2c\fP is prepended. The function returns \f2traits::eof()\fP to indicate failure. .RE .br char_type* .br pbase() const; .RE .RS 3 Returns the beginning pointer for the output sequence. .RE .br void .br pbump(int n); .RE .RS 3 Advances the next pointer for the output sequence by \f2n\fP. .RE .br char_type* .br pptr() const; .RE .RS 3 Returns the next pointer for the output sequence. .RE .br pos_type .br seekoff(off_type off, ios_base::seekdir way, .RE .RS 7 ios_base::openmode which = .br ios_base::in | ios_base::out ); .RE .RS 3 Alters the stream positions within one or more of the controlled sequences in a way that is defined separately for each class derived from \f2basic_streambuf\fP. The default behavior is to return an object of type \f2pos_type\fP that stores an invalid stream position. .RE .RE .RS 0 pos_type .br seekpos(pos_type sp, ios_base::openmode which= .RE .RS 7 ios_base::in | ios_base::out ); .RE .RS 3 Alters the stream positions within one or more of the controlled sequences in a way that is defined separately for each class derived from \f2basic_streambuf\fP. The default behavior is to return an object of class \f2pos_type\fP that stores an invalid stream position. .RE .RE .RS 0 basic_streambuf* .br setbuf(char_type* s, streamsize n); .RE .RS 3 Performs an operation that is defined separately for each class derived from \f2basic_streambuf\fP. The purpose of this function is to allow the user to provide his own buffer or to resize the current buffer. .RE .br void .br setg(char_type* gbeg, char_type* gnext, char_type* gend); .RE .RS 3 Sets up a private member for the following to be \f2true\fP: .RE .RS 2 eback() == gbeg, gptr() == gnext and egptr() == gend .RE .RE .RS 0 void .br setp(char_type* pbeg, char_type* pend); .RE .RS 3 Sets up a private member for the following to be \f2true\fP: .RE .RS 2 pbase() == pbeg, pptr() == pbeg and epptr() == pend .RE .RE .RS 0 int .br showmanyc(); .RE .RS 3 Returns the number of characters available in the internal buffer, or returns \f2-1\fP. .RE .br int .br sync(); .RE .RS 3 Synchronizes the controlled sequences with the internal buffer, in a way that is defined separately for each class derived from \f2basic_streambuf\fP. The default behavior is to do nothing. On failure the return value is \f2-1\fP. .RE .br int_type .br underflow(); .RE .RS 3 The public members of \f2basic_streambuf\fP call this function only if \f2gptr() \fPis null or \f2gptr() >= egptr()\fP. This function returns the character pointed to by \f2gptr()\fP, if \f2gptr() \fPis not null and if \f2gptr() < egptr()\fP. Otherwise the function tries to read character into the buffer. If it fails, it returns \f2traits::eof()\fP. .RE .br int_type .br uflow(); .RE .RS 3 Calls \f2underflow()\fP and if \f2underflow()\fP returns \f2traits::eof()\fP, returns \f2traits::eof()\fP. Otherwise, does \f2gbump(1)\fP and returns the value of \f2*gptr()\fP. .RE .br streamsize .br xsgetn(char_type* s, streamsize n); .RE .RS 3 Assigns up to \f2n\fP characters to successive elements of the array whose first element is designated by \f2s\fP. The characters are read from the input sequence. Assigning stops when either \f2n\fP characters have been assigned or a call to \f2sbumpc()\fP would return \f2traits::eof()\fP. The function returns the number of characters read. .RE .br streamsize .br xsputn(const char_type* s, streamsize n); .RE .RS 3 Writes up to \f2n\fP characters to the output sequence. The characters written are obtained from successive elements of the array whose first element is designated by \f2s\fP. Writing stops when either \f2n\fP characters have been written or a call to \f2sputc()\fP would return \f2traits::eof()\fP. The function returns the number of characters written. .RE .SH SEE ALSO char_traits(3C++), basic_filebuf(3C++), basic_stringbuf(3C++), strstreambuf(3C++) Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Section 27.5.2 .SH STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee