.\" ident @(#)strstreambuf.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH strstreambuf 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2strstreambuf\fP \ - Associates either the input sequence or the output sequence with a tiny character array whose elements store arbitrary values. .SH SYNOPSIS .br #include .br class strstreambuf .br : public basic_streambuf .SH DESCRIPTION The class strstreambuf is derived from basic_streambuf specialized on type \f2char\fP to associate either the input sequence or the output sequence with a tiny character array whose elements store arbitrary values. Each object of type strstreambuf controls two character sequences: .HP .5i \(bu A character input sequence .HP .5i \(bu A character output sequence .HP 0 Note: see basic_streambuf. The two sequences are related to each other, but are manipulated separately. This means that you can read and write characters at different positions in objects of type strstreambuf without any conflict (in opposition to the basic_filebuf objects). The underlying array has several attributes: .HP .5i \(bu \f2allocated\fP, set when a dynamic array has been allocated, and hence should be freed by the destructor of the strstreambuf object. .HP .5i \(bu \f2constant\fP, set when the array has \f2const\fP elements, so the output sequence cannot be written. .HP .5i \(bu \f2dynamic\fP, set when the array object is allocated (or reallocated) as necessary to hold a character sequence that can change in length. .HP .5i \(bu \f2frozen\fP, set when the program has requested that the array not be altered, reallocated, or freed. .HP 0 This is a deprecated feature and might not be available in future versions. .SH INTERFACE .br class strstreambuf .br : public basic_streambuf { .br .br public: .br .RE .RS 1 typedef char_traits traits; .br typedef basic_ios ios_type; .RE .RS 0 .RE .RS 1 typedef char char_type; .br typedef typename traits::int_type int_type; .br typedef typename traits::pos_type pos_type; .br typedef typename traits::off_type off_type; .RE .RS 0 .RE .RS 1 explicit strstreambuf(streamsize alsize = 0); .br strstreambuf(void *(*palloc)(size_t), .RE .RS 14 void (*pfree)(void *)); .RE .RS 1 strstreambuf(char *gnext, streamsize n, char *pbeg = 0); .RE .RS 0 .RE .RS 1 strstreambuf(unsigned char *gnext, streamsize n, .RE .RS 14 unsigned char *pbeg = 0); .RE .RS 1 strstreambuf(signed char *gnext, streamsize n, .RE .RS 14 signed char *pbeg = 0); .RE .RS 0 .RE .RS 1 strstreambuf(const char *gnext, streamsize n); .br strstreambuf(const unsigned char *gnext, streamsize n); .br strstreambuf(const signed char *gnext, streamsize n); .RE .RS 0 .RE .RS 1 virtual ~strstreambuf(); .RE .RS 0 .RE .RS 1 void freeze(bool f = 1); .br char *str(); .br int pcount() const; .RE .RS 0 .br protected: .br .RE .RS 1 virtual int_type overflow(int_type c = traits::eof()); .br virtual int_type pbackfail(int_type c = traits::eof()); .br virtual int_type underflow(); .RE .RS 0 .RE .RS 1 virtual pos_type seekoff(off_type, ios_type::seekdir way, .RE .RS 26 ios_type::openmode which = .br ios_type::in | ios_type::out); .RE .RS 0 .RE .RS 1 virtual pos_type seekpos(pos_type sp, .RE .RS 23 ios_type::openmode which = .RE .RS 26 ios_type::in | ios_type::out); .RE .RS 0 .RE .RS 1 virtual streambuf* setbuf(char *s, streamsize n); .br virtual streamsize xsputn(const char_type* s, .RE .RS 27 streamsize n); .RE .RS 0 .br }; .SH TYPES .br char_type .RE .RS 3 The type \f2char_type\fP is a synonym of type \f2char\fP. .RE .br int_type .RE .RS 3 The type\f2 int_type \fPis a synonym of type \f2traits::in_type\fP. .RE .br ios_type .RE .RS 3 The type \f2ios_type\fP is an instantiation of class \f2basic_ios\fP on type \f2char\fP. .RE .br off_type .RE .RS 3 The type \f2off_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 traits .RE .RS 3 The type \f2traits\fP is a synonym of type \f2char_traits\fP. .RE .SH CONSTRUCTORS .br explicit strstreambuf(streamsize alsize = 0); .RE .RS 3 Constructs an object of class \f2strstreambuf\fP, initializing the base class with \f2streambuf()\fP. After initialization the \f2strstreambuf\fP object is in dynamic mode and its array object has a size of \f2alsize\fP. .RE .br strstreambuf(void* (*palloc)(size_t), .RE .RS 12 void (*pfree)(void*)); .RE .RS 3 Constructs an object of class \f2strstreambuf\fP, initializing the base class with \f2streambuf()\fP. After initialization the \f2strstreambuf\fP object is in dynamic mode. The function used to allocate memory is pointed to by \f2void*\fP \f2(*palloc)(size_t)\fP and the one used to free memory is pointed to by \f2void (*pfree)(void*)\fP. .RE .RE .RS 0 strstreambuf(char* gnext, streamsize n, .RE .RS 12 char* pbeg = 0); .RE .RS 0 strstreambuf(signed char* gnext, streamsize n, .RE .RS 12 signed char* pbeg = 0); .RE .RS 0 strstreambuf(unsigned char* gnext, streamsize n, .RE .RS 12 unsigned char* pbeg = 0); .RE .RS 3 Constructs an object of class \f2strstreambuf\fP, initializing the base class with \f2streambuf()\fP. The argument \f2gnext\fP points to the first element of an array object whose number of elements is: .RE .RS 2 n, if n > 0 .RE .RS 3 ::strlen(gnext), if n == 0 .RE .RS 2 INT_MAX, if n < 0 If \f2pbeg\fP is a null pointer, sets only the input sequence to \f2gnext\fP. Otherwise, also sets the output sequence to \f2pbeg\fP. .RE .RE .RS 0 strstreambuf(const char* gnext, streamsize n); .br strstreambuf(const signed char* gnext, streamsize n); .br strstreambuf(const unsigned char* gnext, streamsize n); .RE .RS 3 Constructs an object of class \f2strstreambuf\fP, initializing the base class with \f2streambuf()\fP. The argument \f2gnext\fP points to the first element of an array object whose number of elements is: .RE .RS 2 n, if n > 0 .RE .RS 3 ::strlen(gnext), if n == 0 .RE .RS 2 INT_MAX, if n < 0 Sets the input sequence to \f2gnext\fP and the mode to \f2constant\fP. .RE .SH DESTRUCTORS .RE .RS 0 virtual ~strstreambuf(); .RE .RS 3 Destroys an object of class \f2strstreambuf\fP. The function frees the dynamically allocated array object only if allocated is set and frozen is not set. .RE .SH MEMBER FUNCTIONS .br void .br freeze(bool freezefl = 1); .RE .RS 3 If the mode is dynamic, alters the \f2freeze\fP status of the dynamic array as follows: .RS .5i .HP .5i - If \f2freezefl\fP is \f2false\fP, the function sets the \f2freeze\fP status to \f2frozen\fP. .HP .5i - Otherwise, it clears the \f2freeze\fP status..RE .RE .RE .br int_type .br overflow( int_type c = traits::eof() ); .RS 3 If the output sequence has a put position available, and \f2c\fP is not \f2traits::eof()\fP, then writes \f2c\fP into it. If there is no position available, the function increases the size of the array object by allocating more memory, and then writes \f2c\fP at the new current put position. If dynamic is not set or if frozen is set, the operation fails. The function returns \f2traits::not_eof(c)\fP, except if it fails, in which case it returns\f2 traits::eof()\fP. .RE .br int_type .br pbackfail( int_type c = traits::eof() ); .RE .RS 3 Puts back the character designated by \f2c\fP into the input sequence. If \f2traits::eq_int_type(c,traits::eof())\fP returns \f2true\fP, move the input sequence one position backward. If the operation fails, the function returns \f2traits::eof()\fP. Otherwise it returns\f2 traits::not_eof(c)\fP. .RE .br int .br pcount() const; .RE .RS 3 Returns the size of 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 If the open mode is \f2in | out\fP, alters the stream position of both the input and the output sequence. If the open mode is \f2in\fP, alters the stream position of only the input sequence. If the open mode is \f2out\fP, alters the stream position of only the output sequence. The new position is calculated by combining the two parameters \f2off\fP (displacement) and \f2way\fP (reference point). If the current position of the sequence is invalid before repositioning, the operation fails and the return value is \f2pos_type(off_type(-1))\fP. Otherwise the function returns the current new 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 If the open mode is \f2in | out\fP, alters the stream position of both the input and the output sequence. If the open mode is \f2in\fP, alters the stream position of only the input sequence. If the open mode is \f2out\fP, alters the stream position of only the output sequence. If the current position of the sequence is invalid before repositioning, the operation fails and the return value is \f2pos_type(off_type(-1))\fP. Otherwise the function returns the current new position. .RE .RE .RS 0 strstreambuf* .br setbuf(char* s, streamsize n); .RE .RS 3 If \f2dynamic\fP is set and\f2 freeze \fPis not, proceed as follows: If \f2s\fP is not a null pointer and \f2n\fP is greater than the number of characters already in the current array, replaces it (copy its contents) by the array of size \f2n\fP pointed to by \f2s\fP. .RE .br char* .br str(); .RE .RS 3 Calls \f2freeze()\fP, then returns the beginning pointer for the input sequence. .RE .br int_type .br underflow(); .RE .RS 3 If the input sequence has a read position available, returns the content of this position. Otherwise tries to expand the input sequence to match the output sequence and if possible returns the content of the new current position. The function returns \f2traits::eof()\fP to indicate failure. In the case where \f2s\fP is a null pointer and \f2n\fP is greater than the number of characters already in the current array, resizes it to size \f2n\fP. If the function fails, it returns a null pointer. .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. The function returns the number of characters written. .RE .SH EXAMPLE .br // .br // stdlib/examples/manual/strstreambuf.cpp .br // .br #include .br #include .br #include .br .br void main ( ) .br { .RE .RS 1 using namespace std; .RE .RS 0 .RE .RS 2 // create a read/write strstream object .br // and attach it to an ostrstream object .RE .RS 1 ostrstream out; .RE .RS 0 .RE .RS 2 // tie the istream object to the ostrstream object .RE .RS 1 istream in(out.rdbuf()); .RE .RS 0 .RE .RS 2 // output to out .RE .RS 1 out << "anticonstitutionellement is a big word !!!"; .RE .RS 0 .RE .RS 2 // create a NTBS .RE .RS 1 const char *p ="Le rat des villes et le rat des champs"; .RE .RS 0 .RE .RS 2 // output the NTBS .RE .RS 1 out << p << endl; .RE .RS 0 .RE .RS 2 // resize the buffer .RE .RS 1 if ( out.rdbuf()->pubsetbuf(0,5000) ) .RE .RS 2 cout << endl << "Success in allocating the buffer" .RE .RS 8 << endl; .RE .RS 0 .RE .RS 2 // output the all buffer to stdout .RE .RS 1 cout << in.rdbuf( ); .RE .RS 0 .RE .RS 2 // output the decimal conversion of 100 in hex .br // with right padding and a width field of 200 .RE .RS 1 out << dec << setfill('!') << setw(200) << 0x100 << endl; .RE .RS 2 .br // output the content of the input sequence to stdout .RE .RS 1 cout << in.rdbuf( ) << endl; .RE .RS 0 .RE .RS 2 // number of elements in the output sequence .RE .RS 1 cout << out.rdbuf()->pcount() << endl; .RE .RS 0 .RE .RS 2 // resize the buffer to a minimum size .RE .RS 1 if ( out.rdbuf()->pubsetbuf(0,out.rdbuf()->pcount()) ) .RE .RS 2 cout << endl << "Success in resizing the buffer" << endl; .RE .RS 0 .RE .RS 2 // output the content of the all array object .RE .RS 1 cout << out.rdbuf()->str() << endl; .RE .RS 0 .RE .RS 1 } .SH SEE ALSO char_traits(3C++), ios_base(3C++), basic_ios(3C++), basic_streambuf(3C++), istrstream(3c++), ostrstream(3C++), strstream(3c++) Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Annex D Compatibility features Section D.5 .SH STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee