STD::WSTREAMBUF(3)
std::basic_streambuf< _CharT, _Traits > β Library Functions Manual π
okay bestie, welcome to the manual page for std::basic_streambuf< _CharT, _Traits >. This is from the Library Functions Manual, section 3. She's the blueprint, the main character energy behind all your input/output stream buffer situations. Let's get into it.
β¨ NAME β¨
std::basic_streambuf< _CharT, _Traits > β the actual work of input and output (interface). No cap.
π¦ SYNOPSIS π¦
#include <streambuf>
Inherited by std::basic_filebuf< wchar_t >, std::basic_stringbuf< wchar_t >, __gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, _Traits >, std::basic_stringbuf< _CharT, _Traits, _Alloc >, and std::wbuffer_convert< _Codecvt, _Elem, _Tr >.
π Public Types π
typedef _CharT char_typetypedef _Traits traits_typetypedef traits_type::int_type int_typetypedef traits_type::pos_type pos_typetypedef traits_type::off_type off_typetypedef basic_streambuf< char_type, traits_type > __streambuf_typeβ this is a non-standard type, bestie.
πΈ Public Member Functions πΈ
virtual ~basic_streambuf ()β destructor deallocates no buffer space. she leaves no mess, iconic.locale getloc () constβ locale access.streamsize in_avail ()β looking ahead into the stream.locale pubimbue (const locale &__loc)β entry point forimbue().int_type sbumpc ()β getting the next character.int_type sgetc ()β getting the next character.streamsize sgetn (char_type *__s, streamsize __n)β entry point forxsgetn.int_type snextc ()β getting the next character.int_type sputbackc (char_type __c)β pushing characters back into the input stream.int_type sputc (char_type __c)β entry point for all single-character output functions.streamsize sputn (const char_type *__s, streamsize __n)β entry point for all single-character output functions.int_type sungetc ()β moving backwards in the input stream.basic_streambuf * pubsetbuf (char_type *__s, streamsize __n)β entry points for derived buffer functions.pos_type pubseekoff (off_type __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)β alters the stream position.pos_type pubseekpos (pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)β alters the stream position.int pubsync ()β calls virtual sync function.
π₯ Protected Member Functions π₯
basic_streambuf ()β base constructor.basic_streambuf (const basic_streambuf &)void __safe_gbump (streamsize __n)void __safe_pbump (streamsize __n)void gbump (int __n)β moving the read position.virtual void imbue (const locale &__loc)β changes translations.basic_streambuf & operator= (const basic_streambuf &)virtual int_type overflow (int_type __c=traits_type::eof())β consumes data from the buffer; writes to the controlled sequence.virtual int_type pbackfail (int_type __c=traits_type::eof())β tries to back up the input sequence.void pbump (int __n)β moving the write position.virtual pos_type seekoff (off_type, ios_base::seekdir, ios_base::openmode=ios_base::in|ios_base::out)β alters the stream positions.virtual pos_type seekpos (pos_type, ios_base::openmode=ios_base::in|ios_base::out)β alters the stream positions.virtual basic_streambuf< char_type, _Traits > * setbuf (char_type *, streamsize)β manipulates the buffer.void setg (char_type *__gbeg, char_type *__gnext, char_type *__gend)β setting the three read area pointers.void setp (char_type *__pbeg, char_type *__pend)β setting the three write area pointers.virtual streamsize showmanyc ()β investigating the data available.void swap (basic_streambuf &__sb)virtual int sync ()β synchronizes the buffer arrays with the controlled sequences.virtual int_type uflow ()β fetches more data from the controlled sequence.virtual int_type underflow ()β fetches more data from the controlled sequence.virtual streamsize xsgetn (char_type *__s, streamsize __n)β multiple character extraction.virtual streamsize xsputn (const char_type *__s, streamsize __n)β multiple character insertion.char_type * eback () constβ access to the get area.char_type * gptr () constβ access to the get area.char_type * egptr () constβ access to the get area.char_type * pbase () constβ access to the put area.char_type * pptr () constβ access to the put area.char_type * epptr () constβ access to the put area.
π Protected Attributes π
locale _M_buf_localeβ current locale setting.char_type * _M_in_begβ start of get area.char_type * _M_in_curβ current read area.char_type * _M_in_endβ end of get area.char_type * _M_out_begβ start of put area.char_type * _M_out_curβ current put area.char_type * _M_out_endβ end of put area.
π Friends π
She's got some very specific besties. Here's the whole VIP list, exactly as written:
template<bool _IsMove, typename _CharT2> __gnu_cxx::__enable_if<
__is_char< _CharT2 >::__value, _CharT2 * >::__type __copy_move_a2
(istreambuf_iterator< _CharT2 >, istreambuf_iterator< _CharT2 >,
_CharT2 *)
streamsize __copy_streambufs_eof (basic_streambuf *__sbin,
basic_streambuf *__sbout, bool &__ineof)
void __istream_extract (istream &, char *, streamsize)
template<typename _CharT2, typename _Distance> __gnu_cxx::__enable_if<
__is_char< _CharT2 >::__value, void >::__type advance
(istreambuf_iterator< _CharT2 > &, _Distance)
class basic_ios< char_type, traits_type >
class basic_istream< char_type, traits_type >
class basic_ostream< char_type, traits_type >
template<typename _CharT2> __gnu_cxx::__enable_if< __is_char< _CharT2
>::__value, istreambuf_iterator< _CharT2 > >::__type find
(istreambuf_iterator< _CharT2 >, istreambuf_iterator< _CharT2 >,
const _CharT2 &)
template<typename _CharT2, typename _Traits2, typename _Alloc>
basic_istream< _CharT2, _Traits2 > & getline (basic_istream<
_CharT2, _Traits2 > &, basic_string< _CharT2, _Traits2, _Alloc > &,
_CharT2)
class istreambuf_iterator< char_type, traits_type >
template<typename _CharT2, typename _Traits2, typename _Alloc>
basic_istream< _CharT2, _Traits2 > & operator>> (basic_istream<
_CharT2, _Traits2 > &, basic_string< _CharT2, _Traits2, _Alloc > &)
class ostreambuf_iterator< char_type, traits_type >
π Detailed Description π
template<typename _CharT, typename _Traits>
class std::basic_streambuf< _CharT, _Traits >"The actual work of input
and output (interface).
π Template Parameters π
_CharTβ type of character stream._Traitsβ traits for character type, defaults tochar_traits<_CharT>.
This is a base class, bestie. Derived stream buffers each control a pair of character sequences: one for input, and one for output. Periodt.
Section [27.5.1] of the standard describes the requirements and behavior of stream buffer classes. That section (three paragraphs, yes ma'am) is reproduced here, for simplicity and accuracy. We're keeping it 100.
- Stream buffers can impose various constraints on the sequences they control. Some constraints are:
- The controlled input sequence can be not readable.
- The controlled output sequence can be not writable.
- The controlled sequences can be associated with the contents of other representations for character sequences, such as external files.
- The controlled sequences can support operations directly to or from associated sequences.
- 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.
- Each sequence is characterized by three pointers which, if non-null, all point into the same
charTarray 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 beginning pointer, or lowest element address in the array (called
xbeghere); - the next pointer, or next element address that is a current candidate for reading or writing (called
xnexthere); - the end pointer, or first element address beyond the end of the array (called
xendhere).
- the beginning pointer, or lowest element address in the array (called
- The following semantic constraints shall always apply for any set of three pointers for a sequence, using the pointer names given immediately above:
- If
xnextis not a null pointer, thenxbegandxendshall also be non-null pointers into the samecharTarray, as described above; otherwise,xbegandxendshall also be null. - If
xnextis not a null pointer andxnext < xendfor an output sequence, then a write position is available. In this case,*xnextshall be assignable as the next element to write (to put, or to store a character value, into the sequence). - If
xnextis not a null pointer andxbeg < xnextfor an input sequence, then a putback position is available. In this case,xnext[-1]shall have a defined value and is the next (preceding) element to store a character that is put back into the input sequence. - If
xnextis not a null pointer andxnext< xendfor an input sequence, then a read position is available. In this case,*xnextshall have a defined value and is the next element to read (to get, or to obtain a character value, from the sequence).
- If
β¨ Member Typedef Documentation β¨
__streambuf_typeβ okay so</p>typedef basic_streambuf<char_type, traits_type> std::basic_streambuf< _CharT, _Traits >::__streambuf_typeβ bestie, this one is a non-standard type. Not official, just vibes. πchar_typeβtypedef _CharT std::basic_streambuf< _CharT, _Traits >::char_typeβ these are the standard types, and the whole point of them is that they give you a standardized way of referring to names of (or names dependent on) the template parameters, which are specific to the implementation. iconic, honestly.int_typeβtypedef traits_type::int_type std::basic_streambuf< _CharT, _Traits >::int_typeβ same deal: standard types, giving you a standardized way of referring to names of (or names dependent on) the template parameters, which are specific to the implementation. πoff_typeβtypedef traits_type::off_type std::basic_streambuf< _CharT, _Traits >::off_typeβ yep, another standard type, and again: a standardized way of referring to names of (or names dependent on) the template parameters, which are specific to the implementation. β¨pos_typeβtypedef traits_type::pos_type std::basic_streambuf< _CharT, _Traits >::pos_typeβ standard type behavior, you know the drill: standardized way of referring to names of (or names dependent on) the template parameters, which are specific to the implementation. π¦traits_typeβtypedef _Traits std::basic_streambuf< _CharT, _Traits >::traits_typeβ last one, also a standard type, also providing that standardized way of referring to names of (or names dependent on) the template parameters, which are specific to the implementation. periodt. π
β¨ Constructor & Destructor Documentation β¨
virtual std::basic_streambuf< _CharT, _Traits >::~basic_streambuf ()[inline],[virtual]β the destructor, and listen: it deallocates no buffer space. That's it. That's the whole thing. π«Άstd::basic_streambuf< _CharT, _Traits >::basic_streambuf ()[inline],[protected]β the base constructor, only called from derived constructors. It sets up all the buffer data to zero, including the pointers described in thebasic_streambufclass description. And heads up, because of that:- the class starts with no read nor write positions available, and
- this is not an error. like, it's fine. it's normal. relax. π
β¨ Member Function Documentation β¨
char_type * std::basic_streambuf< _CharT, _Traits >::eback () const[inline],[protected]β access to the get area, and these functions are only available to other protected functions, including derived classes. Here's the little trio you need to know:eback()returns the beginning pointer for the input sequencegptr()returns the next pointer for the input sequenceegptr()returns the end pointer for the input sequence
Referenced by std::basic_filebuf< char_type, traits_type >::_M_destroy_pback(), std::basic_filebuf< _CharT, _Traits >::imbue(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_filebuf< _CharT, _Traits >::pbackfail(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::pbackfail(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekpos(), std::basic_streambuf< char_type, traits_type >::sputbackc(), std::basic_streambuf< char_type, traits_type >::sungetc(), std::basic_filebuf< _CharT, _Traits >::underflow(), and std::basic_filebuf< _CharT, _Traits >::xsgetn(). that's a whole friend group right there π
char_type * std::basic_streambuf< _CharT, _Traits >::egptr () const[inline],[protected]β access to the get area again, still only available to other protected functions, including derived classes:eback()returns the beginning pointer for the input sequencegptr()returns the next pointer for the input sequenceegptr()returns the end pointer for the input sequence
Referenced by std::basic_filebuf< char_type, traits_type >::_M_create_pback(), std::basic_streambuf< char_type, traits_type >::in_avail(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_streambuf< char_type, traits_type >::sbumpc(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekpos(), std::basic_streambuf< char_type, traits_type >::sgetc(), std::basic_filebuf< _CharT, _Traits >::showmanyc(), std::basic_stringbuf< char >::showmanyc(), std::basic_filebuf< _CharT, _Traits >::underflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::underflow(), std::wbuffer_convert< _Codecvt, _Elem, _Tr >::underflow(), std::basic_filebuf< _CharT, _Traits >::xsgetn(), and xsgetn(). π₯
char_type * std::basic_streambuf< _CharT, _Traits >::epptr () const[inline],[protected]β now we're on the put area, and same rule: only available to other protected functions, including derived classes:pbase()returns the beginning pointer for the output sequencepptr()returns the next pointer for the output sequenceepptr()returns the end pointer for the output sequence
Referenced by std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekpos(), std::basic_streambuf< char_type, traits_type >::sputc(), std::basic_filebuf< _CharT, _Traits >::xsputn(), and xsputn(). β¨
void std::basic_streambuf< _CharT, _Traits >::gbump (int __n)[inline],[protected]β moving the read position!
Parameters
__nβ the delta by which to move.
And that's literally all it does: this just advances the read position without returning any data.
Referenced by std::basic_filebuf< _CharT, _Traits >::pbackfail(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::pbackfail(), std::basic_streambuf< char_type, traits_type >::sbumpc(), std::basic_streambuf< char_type, traits_type >::sputbackc(), std::basic_streambuf< char_type, traits_type >::sungetc(), std::basic_streambuf< char_type, traits_type >::uflow(), and std::basic_filebuf< _CharT, _Traits >::xsgetn(). πΈ
locale std::basic_streambuf< _CharT, _Traits >::getloc () const[inline]β locale access, bestie. π
Returns the current locale in effect.
So if pubimbue(loc) has been called, then the most recent loc is returned. Otherwise the global locale in effect at the time of construction is returned.
Referenced by std::basic_streambuf< char_type, traits_type >::pubimbue(). π
char_type * std::basic_streambuf< _CharT, _Traits >::gptr () const[inline],[protected]β back to the get area, and once more with feeling, these are only available to other protected functions, including derived classes:eback()returns the beginning pointer for the input sequencegptr()returns the next pointer for the input sequenceegptr()returns the end pointer for the input sequence
Referenced by std::basic_filebuf< char_type, traits_type >::_M_create_pback(), std::basic_filebuf< char_type, traits_type >::_M_destroy_pback(), std::basic_filebuf< _CharT, _Traits >::imbue(), std::basic_streambuf< char_type, traits_type >::in_avail(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_filebuf< _CharT, _Traits >::pbackfail(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::pbackfail(), std::basic_streambuf< char_type, traits_type >::sbumpc(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_streambuf< char_type, traits_type >::sgetc(), std::basic_filebuf< _CharT, _Traits >::showmanyc(), std::basic_stringbuf< char >::showmanyc(), std::basic_streambuf< char_type, traits_type >::sputbackc(), std::basic_streambuf< char_type, traits_type >::sungetc(), std::basic_streambuf< char_type, traits_type >::uflow(), std::basic_filebuf< _CharT, _Traits >::underflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::underflow(), std::wbuffer_convert< _Codecvt, _Elem, _Tr >::underflow(), std::basic_filebuf< _CharT, _Traits >::xsgetn(), and xsgetn(). the way this list just keeps GOING π
virtual void std::basic_streambuf< _CharT, _Traits >::imbue (const locale & __loc)[inline],[protected],[virtual]β changes translations. π§
Parameters
__locβ a new locale.
Translations done during I/O which depend on the current locale are changed by this call. And the standard adds: Between invocations of this function a class derived from streambuf can safely cache results of calls to locale functions and to members of facets so obtained.
Note: the base class version does nothing. literally just sits there. respect.
Reimplemented in std::basic_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >, std::basic_filebuf< _CharT, std::char_traits< _CharT > >, std::basic_filebuf< char >, std::basic_filebuf< char_type, traits_type >, and std::basic_filebuf< wchar_t >.
Referenced by std::basic_streambuf< char_type, traits_type >::pubimbue(). π
streamsize std::basic_streambuf< _CharT, _Traits >::in_avail ()[inline]β looking ahead into the stream. π
Returns the number of characters available.
So: if a read position is available, it returns the number of characters available for reading before the buffer must be refilled. Otherwise it returns the derived showmanyc(). simple as that, no cap. π
virtual int_type std::basic_streambuf< _CharT, _Traits >::overflow (int_type __c = traits_type::eof())[inline],[protected],[virtual]β consumes data from the buffer; writes to the controlled sequence. π₯
Parameters
__cβ an additional character to consume.
Returns eof() to indicate failure, something else (usually __c, or not_eof()).
Informally: this function is called when the output buffer is full (or does not exist, as buffering need not actually be done). If a buffer exists, it is consumed, with some effect on the controlled sequence. (Typically, the buffer is written out to the sequence verbatim.) In either case, the character c is also written out, if __c is not eof().
For a formal definition of this function, see a good text such as Langer & Kreft, or [27.5.2.4.5]/3-7. π
And a functioning output streambuf can be created by overriding only this function (no buffer area will be used). one function!! that's it!! main character energy fr fr
Note: the base class version does nothing, returns eof(). π
Reimplemented in __gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >, std::basic_filebuf< char >, std::basic_filebuf< char_type, traits_type >, std::basic_filebuf< wchar_t >, std::basic_stringbuf< _CharT, _Traits, _Alloc >, std::basic_stringbuf< char >, std::basic_stringbuf< wchar_t >, and std::wbuffer_convert< _Codecvt, _Elem, _Tr >.
Referenced by std::basic_streambuf< char_type, traits_type >::sputc(), and xsputn().
π
pbackfail β the rewind queen π
template<typename _CharT, typename _Traits> virtual int_type
std::basic_streambuf< _CharT, _Traits >::pbackfail (int_type __c = traits_type::eof()) [inline], [protected], [virtual]
Bestie. This one tries to back up the input sequence. That's it, that's the whole job. Sometimes you gotta scoot backwards, you know? No cap.
Parameters
__cβ the character to be inserted back into the sequence. (Yeah, you're literally un-reading a character. It's giving time travel. π°οΈ)
Returns
eof()on failure, some other value on success β¨
Postcondition
- The constraints of
gptr(),eback(), andpptr()are the same as forunderflow(). πΈ
Note: the base class version does nothing, and returns eof(). So like, if you don't override it, it's just sitting there being unhelpful. π
Reimplemented in __gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >, std::basic_filebuf< char >, std::basic_filebuf< char_type, traits_type >, std::basic_filebuf< wchar_t >, std::basic_stringbuf< _CharT, _Traits, _Alloc >, std::basic_stringbuf< char >, and std::basic_stringbuf< wchar_t >.
Referenced by std::basic_streambuf< char_type, traits_type >::sputbackc(), and std::basic_streambuf< char_type, traits_type >::sungetc().
π pbase β put area pointer number one π«Ά
template<typename _CharT, typename _Traits> char_type *
std::basic_streambuf< _CharT, _Traits >::pbase () const [inline], [protected]
Access to the put area, bestie. And okay here's the thing β these functions are only available to other protected functions, including derived classes. So it's a members-only situation. iykyk. π
The put-area trio, since they all come as a set:
pbase()returns the beginning pointer for the output sequence πpptr()returns the next pointer for the output sequence β¨epptr()returns the end pointer for the output sequence π
Referenced by std::basic_filebuf< _CharT, _Traits >::overflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_filebuf< _CharT, _Traits >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekpos(), std::basic_stringbuf< char >::str(), std::basic_filebuf< _CharT, _Traits >::sync(), and std::basic_filebuf< _CharT, _Traits >::xsputn().
π¦ pbump β scoot the write position forward β¨
template<typename _CharT, typename _Traits> void std::basic_streambuf<
_CharT, _Traits >::pbump (int __n) [inline], [protected]
Moving the write position. That's the whole vibe.
Parameters
__nβ the delta by which to move. πββοΈπ¨
And listen: this just advances the write position without returning any data. It moves, it does not give. Very mysterious of it, honestly. π
Referenced by std::basic_filebuf< _CharT, _Traits >::overflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), and std::basic_streambuf< char_type, traits_type >::sputc().
πΈ pptr β put area pointer number two π
template<typename _CharT, typename _Traits> char_type *
std::basic_streambuf< _CharT, _Traits >::pptr () const [inline], [protected]
Access to the put area, again. And same rules as before: these functions are only available to other protected functions, including derived classes. Protected girlies only. π«Ά
pbase()returns the beginning pointer for the output sequence πpptr()returns the next pointer for the output sequence β¨epptr()returns the end pointer for the output sequence π
Referenced by std::basic_filebuf< _CharT, _Traits >::overflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_filebuf< _CharT, _Traits >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_streambuf< char_type, traits_type >::sputc(), std::basic_filebuf< _CharT, _Traits >::sync(), std::basic_filebuf< _CharT, _Traits >::xsputn(), and xsputn().
π pubimbue β the public door to imbue() πͺ
template<typename _CharT, typename _Traits> locale std::basic_streambuf<
_CharT, _Traits >::pubimbue (const locale & __loc) [inline]
Entry point for imbue(). Very demure, very mindful, very locale. π
Parameters
__locβ the new locale. π
Returns
- The previous locale. (Yes, it hands you the old one back, iconic behaviour honestly.) β¨
Calls the derived imbue(__loc). π
β pubseekoff β public seek, offset edition π―
template<typename _CharT, typename _Traits> pos_type std::basic_streambuf<
_CharT, _Traits >::pubseekoff (off_type __off, ios_base::seekdir __way,
ios_base::openmode __mode = ios_base::in | ios_base::out) [inline]
Alters the stream position. β¨
Parameters
__offβ offset. π__wayβ value forios_base::seekdir. π__modeβ value forios_base::openmode. π¦
Calls virtual seekoff function. π
π pubseekpos β public seek, position edition π―
template<typename _CharT, typename _Traits> pos_type std::basic_streambuf<
_CharT, _Traits >::pubseekpos (pos_type __sp, ios_base::openmode __mode
= ios_base::in | ios_base::out) [inline]
Alters the stream position. Same energy, different flavour. β¨
Parameters
__spβ position. π__modeβ value forios_base::openmode. π¦
Calls virtual seekpos function. π
π§ pubsetbuf β entry points for derived buffer functions π«Ά
template<typename _CharT, typename _Traits> basic_streambuf *
std::basic_streambuf< _CharT, _Traits >::pubsetbuf (char_type * __s,
streamsize __n) [inline]
Okay so this is the tea on the whole pub-family: the public versions of pubfoo dispatch to the protected derived foo member functions, passing the arguments (if any) and returning the result unchanged. So pubsetbuf is basically the receptionist who forwards your call to the real one and then reads back their answer word for word. π
π pubsync β calls the virtual sync function β¨
template<typename _CharT, typename _Traits> int std::basic_streambuf<
_CharT, _Traits >::pubsync () [inline]
Calls virtual sync function. That's the whole description bestie, she's efficient. π«Ά
Referenced by std::basic_istream< _CharT, _Traits >::sync().
π₯ sbumpc β getting the next character πββοΈ
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::sbumpc () [inline]
Getting the next character. Main character energy, she moves. π
Returns
- The next character, or
eof. β¨
And here's how she works: if the input read position is available, returns that character and increments the read pointer, otherwise calls and returns uflow(). So either she's got it ready and she hands it over and walks forward, or she outsources the whole thing to uflow(). Either way, we get the character. Slay. π
Referenced by std::basic_istream< _CharT, _Traits >::ignore(), std::basic_streambuf< char_type, traits_type >::snextc(), and std::basic_istream< _CharT, char_traits< _CharT > >::unget().
π seekoff β alters the stream positions π―
template<typename _CharT, typename _Traits> virtual pos_type
std::basic_streambuf< _CharT, _Traits >::seekoff (off_type ,
ios_base::seekdir , ios_base::openmode = ios_base::in | ios_base::out)
[inline], [protected], [virtual]
Alters the stream positions. And each derived class provides its own appropriate behavior β so nobody's copying anybody's homework here, every subclass does it their own way. π
Note: the base class version does nothing, and returns a pos_type that represents an invalid stream position. So if you're calling this on the base and expecting a real answer... bestie, no. π
Reimplemented in std::basic_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >, std::basic_filebuf< char >, std::basic_filebuf< char_type, traits_type >, std::basic_filebuf< wchar_t >, std::basic_stringbuf< _CharT, _Traits, _Alloc >, std::basic_stringbuf< char >, and std::basic_stringbuf< wchar_t >.
Referenced by std::basic_streambuf< char_type, traits_type >::pubseekoff().
β seekpos β alters the stream positions, position style π
template<typename _CharT, typename _Traits> virtual pos_type
std::basic_streambuf< _CharT, _Traits >::seekpos (pos_type ,
ios_base::openmode = ios_base::in | ios_base::out) [inline],
[protected], [virtual]
Alters the stream positions. Again: each derived class provides its own appropriate behavior. π
Note: base class version does nothing, returns apos_typethat represents an invalid stream position. Same sad story asseekoff. π
Reimplemented in std::basic_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >, std::basic_filebuf< char >, std::basic_filebuf< char_type, traits_type >, std::basic_filebuf< wchar_t >, std::basic_stringbuf< _CharT, _Traits, _Alloc >, std::basic_stringbuf< char >, and std::basic_stringbuf< wchar_t >.
Referenced by std::basic_streambuf< char_type, traits_type >::pubseekpos().
π setbuf β manipulates the buffer π«Ά
template<typename _CharT, typename _Traits> virtual basic_streambuf<
char_type, _Traits > * std::basic_streambuf< _CharT, _Traits >::setbuf
(char_type * , streamsize ) [inline], [protected], [virtual]
Manipulates the buffer. And yeah, each derived class provides its own appropriate behavior. πΈ
Okay and here's your homework, bestie: see the next-to-last paragraph of https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering for more on this function. Go read it, it's giving lore. π
Note: the base class version does nothing, returns this. (At least she returns something, unlike her cousins up there. π)
Reimplemented in std::basic_filebuf< _CharT, _Traits >, std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >, std::basic_filebuf< _CharT, std::char_traits< _CharT > >, std::basic_filebuf< char >, std::basic_filebuf< char_type, traits_type >, std::basic_stringbuf< _CharT, _Traits, _Alloc >, and std::basic_stringbuf< char >.
Referenced by std::basic_streambuf< char_type, traits_type >::pubsetbuf().
π setg β setting the three read area pointers π―
template<typename _CharT, typename _Traits> void std::basic_streambuf<
_CharT, _Traits >::setg (char_type * __gbeg, char_type * __gnext,
char_type * __gend) [inline], [protected]
Setting the three read area pointers. Three pointers, one function, zero drama. β¨
Parameters
__gbegβ a pointer. π__gnextβ a pointer. π__gendβ a pointer. π
Postcondition
__gbeg == eback(),__gnext == gptr(), and__gend == egptr()π
Referenced by std::wbuffer_convert< _Codecvt, _Elem, _Tr >::wbuffer_convert(), std::basic_filebuf< char_type, traits_type >::_M_create_pback(), std::basic_filebuf< char_type, traits_type >::_M_destroy_pback(), std::basic_filebuf< char_type, traits_type >::_M_set_buffer(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekoff(), std::basic_stringbuf< _CharT, _Traits, _Alloc >::seekpos(), and std::basic_filebuf< _CharT, _Traits >::xsgetn().
π¦ setp β setting the three write area pointers π―
template<typename _CharT, typename _Traits> void std::basic_streambuf<
_CharT, _Traits >::setp (char_type * __pbeg, char_type * __pend)
[inline], [protected]
Setting the three write area pointers. The put-side twin of setg, and she's iconic. π
Parameters
__pbegβ a pointer. π__pendβ a pointer. π
Postcondition
__pbeg == pbase(),__pbeg == pptr(), and__pend == epptr()π
Referenced by std::wbuffer_convert< _Codecvt, _Elem, _Tr >::wbuffer_convert(), and std::basic_filebuf< char_type, traits_type >::_M_set_buffer().
β¨ sgetc β getting the next character (but make it β¨stationaryβ¨)
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::sgetc () [inline]
Getting the next character. Same mission as sbumpc, except this one does not move the read position after fetching the character. She looks, she does not touch. Very respectful. π
Returns
- The next character, or
eof. β¨
And the mechanics: if the input read position is available, returns that character, otherwise calls and returns underflow(). πΈ
Referenced by std::basic_istream< _CharT, _Traits >::get(), std::basic_istream< _CharT, _Traits >::get(), std::basic_istream< _CharT, _Traits >::ignore(), std::basic_istream< _CharT, char_traits< _CharT > >::readsome(), and std::basic_streambuf< char_type, traits_type >::snextc().
(Yes bestie, std::basic_istream< _CharT, _Traits >::get() really is listed twice up there. We don't question the source, we just report it. π)
π sgetn β entry point for xsgetn π«Ά
template<typename _CharT, typename _Traits> streamsize std::basic_streambuf<
_CharT, _Traits >::sgetn (char_type * __s, streamsize __n) [inline]
Entry point for xsgetn. Short and sweet, she's just the doorman. π
Parameters
__sβ a buffer area. π__nβ a count. π’
...and it just hands you back xsgetn(__s,__n). The whole vibe is: fill __s[0] through __s[__n-1] with characters from the input sequence, if it can. That's it, that's the function. π
β¨ showmanyc() β¨
template<typename _CharT, typename _Traits> virtual streamsize
std::basic_streambuf< _CharT, _Traits >::showmanyc () [inline],
[protected], [virtual]
Bestie, this one is literally "how many characters do we even have??" energy β investigating the data available π΅οΈββοΈ
Returns: an estimate of the number of characters available in the input sequence, or -1.
So here's the tea: if it returns a positive value, then successive calls to underflow() will not return traits::eof() until at least that many characters have been supplied. If showmanyc() returns -1, then calls to underflow() or uflow() will fail. That's [27.5.2.4.3]/1, periodt. π€
Note β the base class version does nothing and returns zero. Iconic behaviour honestly.
Note β the standard adds that the intention is not only that the calls (tounderfloworuflow) will not returneof()but that they will return immediately. No waiting around, no buffering drama, we move fast. β‘
Note β the standard also adds that the morphemes of showmanyc are es-how-many-see, not show-manic. Not me getting that wrong for years π the way it's actually pronounced is "es-how-many-see". iykyk.
Reimplemented in:
std::basic_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >std::basic_filebuf< _CharT, std::char_traits< _CharT > >std::basic_filebuf< char >std::basic_filebuf< char_type, traits_type >std::basic_filebuf< wchar_t >std::basic_stringbuf< _CharT, _Traits, _Alloc >std::basic_stringbuf< char >std::basic_stringbuf< wchar_t >
Referenced by std::basic_streambuf< char_type, traits_type >::in_avail().
π¦ snextc() π¦
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::snextc () [inline]
Getting the next character, slay. β¨
Returns: the next character, or eof.
Here's the move: it calls sbumpc(), and if that function returns traits::eof(), so does this function. Otherwise, it calls sgetc(). That's the whole routine, no notes. π
Referenced by std::basic_istream< _CharT, char_traits< _CharT > >::get(), std::basic_iostream< char_type, traits_type >::ignore(), and std::basic_istream< _CharT, char_traits< _CharT > >::readsome().
π sputbackc() π
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::sputbackc (char_type __c) [inline]
Pushing characters back into the input stream β yes we're rewinding, main character behaviour only. βͺ
Parameters
__cβ the character to push back.
Returns: the previous character, if possible.
It's similar to sungetc(), but __c is pushed onto the stream instead of the previous character. And if it works? The next character fetched from the input stream will be __c. Put it back, get it back, no cap. π«Ά
Referenced by std::basic_istream< _CharT, _Traits >::putback().
π sputc() π
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::sputc (char_type __c) [inline]
Entry point for all single-character output functions. The moment you've all been waiting for. π
Parameters
__cβ a character to output.
Returns: __c, if possible.
This is one of two public output functions. So: if a write position is available for the output sequence (i.e., the buffer is not full), it stores __c in that position, increments the position, and returns traits::to_int_type(__c). If a write position is not available, it returns overflow(__c). Simple as that bestie. β¨
Referenced by std::wbuffer_convert< _Codecvt, _Elem, _Tr >::overflow().
πΈ sputn() πΈ
template<typename _CharT, typename _Traits> streamsize std::basic_streambuf<
_CharT, _Traits >::sputn (const char_type * __s, streamsize __n)
[inline]
(Yes, the description says "Entry point for all single-character output functions" β even though this is the multi-character one. The docs said what the docs said and I am not editing the docs. π)
Parameters
__sβ a buffer read area.__nβ a count.
One of the two public output functions, okay?
Returns: xsputn(__s,__n). The effect is to write __s[0] through __s[__n-1] to the output sequence, if possible. Boom, that's the whole thing. π₯
π§ sungetc() π§
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::sungetc () [inline]
Moving backwards in the input stream. Yes, we're going back, it's giving rewind. π
Returns: the previous character, if possible.
If a putback position is available, this function decrements the input pointer and returns that character. Otherwise, it calls and returns pbackfail(). The effect is to unget the last character gotten. So it's undoing the getting. Reversal of fortune, literally. β¨
Referenced by std::basic_istream< _CharT, _Traits >::unget().
π sync() π
template<typename _CharT, typename _Traits> virtual int
std::basic_streambuf< _CharT, _Traits >::sync () [inline], [protected],
[virtual]
Synchronizes the buffer arrays with the controlled sequences. Syncing is self-care bestie, fr fr. π§ββοΈ
Returns: -1 on failure.
Each derived class provides its own appropriate behavior, including the definition of failure. So like, failure is a vibe each subclass defines for itself. π
Note β the base class version does nothing, returns zero. Minimal effort, maximal peace.
Reimplemented in:
__gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >std::basic_filebuf< _CharT, std::char_traits< _CharT > >std::basic_filebuf< char >std::basic_filebuf< char_type, traits_type >std::basic_filebuf< wchar_t >std::wbuffer_convert< _Codecvt, _Elem, _Tr >
Referenced by std::basic_streambuf< char_type, traits_type >::pubsync().
β uflow() β
template<typename _CharT, typename _Traits> virtual int_type
std::basic_streambuf< _CharT, _Traits >::uflow () [inline],
[protected], [virtual]
Fetches more data from the controlled sequence. More data, always more data. π₯
Returns: the first character from the pending sequence.
Informally, this function does the same thing as underflow(), and in fact is required to call that function. It also returns the new character, like underflow() does. BUT β and here's the plot twist β this function also moves the read position forward by one. So it's underflow() but with commitment. π₯
Reimplemented in __gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >.
Referenced by std::basic_streambuf< char_type, traits_type >::sbumpc(), and xsgetn().
π underflow() π
template<typename _CharT, typename _Traits> virtual int_type
std::basic_streambuf< _CharT, _Traits >::underflow () [inline],
[protected], [virtual]
Fetches more data from the controlled sequence. The classic. The blueprint. The blueprint classic. π
Returns: the first character from the pending sequence.
Informally, this function is called when the input buffer is exhausted (or does not exist, as buffering need not actually be done β honestly, buffering is optional and that's so real of it). If a buffer exists, it is refilled. In either case, the next available character is returned, or traits::eof() to indicate a null pending sequence.
For a formal definition of the pending sequence, see a good text such as Langer & Kreft, or [27.5.2.4.3]/7-14. (Academic queen behaviour, we love to see it. π)
A functioning input streambuf can be created by overriding only this function β no buffer area will be used. For an example, see https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html
Note β the base class version does nothing, returns eof(). It's giving "I have no data and I'm at peace with that."
Reimplemented in:
__gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >std::basic_filebuf< _CharT, std::char_traits< _CharT > >std::basic_filebuf< char >std::basic_filebuf< char_type, traits_type >std::basic_filebuf< wchar_t >std::basic_stringbuf< _CharT, _Traits, _Alloc >std::basic_stringbuf< char >std::basic_stringbuf< wchar_t >std::wbuffer_convert< _Codecvt, _Elem, _Tr >
Referenced by std::basic_streambuf< char_type, traits_type >::sgetc(), and std::basic_streambuf< char_type, traits_type >::uflow().
π xsgetn() π
template<typename _CharT, typename _Traits> streamsize std::basic_streambuf<
_CharT, _Traits >::xsgetn (char_type * __s, streamsize __n) [protected],
[virtual]
Multiple character extraction. Bulk mode activated. π¦
Parameters
__sβ a buffer area.__nβ maximum number of characters to assign.
Returns: the number of characters assigned.
It fills __s[0] through __s[__n-1] with characters from the input sequence, as if by sbumpc(). It stops when either __n characters have been copied, or when traits::eof() would be copied. Two exit conditions, no exceptions, no notes. β
It is expected that derived classes provide a more efficient implementation by overriding this definition. So like, the base version works but it's not the moment β subclasses are supposed to do better. π
Reimplemented in:
std::basic_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >std::basic_filebuf< _CharT, std::char_traits< _CharT > >std::basic_filebuf< char >std::basic_filebuf< char_type, traits_type >
References egptr(), gptr(), std::min(), and uflow().
Referenced by std::basic_streambuf< char_type, traits_type >::sgetn().
π xsputn() π
template<typename _CharT, typename _Traits> streamsize std::basic_streambuf<
_CharT, _Traits >::xsputn (const char_type * __s, streamsize __n)
[protected], [virtual]
Multiple character insertion. The put-side twin, and yes she ate. π₯
Parameters
__sβ a buffer area.__nβ maximum number of characters to write.
Returns: the number of characters written.
It writes __s[0] through __s[__n-1] to the output sequence, as if by sputc(). It stops when either n characters have been copied, or when sputc() would return traits::eof(). (Note: the docs literally say n here and not __n. I am preserving the lore exactly as it was written. π)
It is expected that derived classes provide a more efficient implementation by overriding this definition. Same deal as xsgetn() β base is fine, subclass is faster, that's the whole point. β¨
Reimplemented in:
std::basic_filebuf< _CharT, _Traits >std::basic_filebuf< _CharT, encoding_char_traits< _CharT > >std::basic_filebuf< _CharT, std::char_traits< _CharT > >std::basic_filebuf< char >std::basic_filebuf< char_type, traits_type >
References epptr(), std::min(), overflow(), and pptr().
Referenced by std::basic_streambuf< char_type, traits_type >::sputn().
π«Ά MEMBER DATA DOCUMENTATION π«Ά
Okay bestie, this is where the actual guts live. The protected data members. The behind-the-scenes girls. None of them are doing it for the fame, but the whole streambuf would fall apart without them. π
π _M_buf_locale
template<typename _CharT, typename _Traits> locale std::basic_streambuf<
_CharT, _Traits >::_M_buf_locale [protected]
Current locale setting. She's protected, she's a locale, she's running the whole cultural vibe of the buffer. π
Referenced by std::basic_filebuf< _CharT, _Traits >::basic_filebuf().
π¦ _M_in_beg
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_in_beg [protected]
Start of get area. The beginning of the beginning. Where reading starts. β¨
π _M_in_cur
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_in_cur [protected]
Current read area. This is where we are right now in the reading journey. Present tense, main character energy. π
πΈ _M_in_end
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_in_end [protected]
End of get area. The boundary. Past this point we have to go fetch more. π
π _M_out_beg
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_out_beg [protected]
Start of put area. Where the writing begins. The blank page era. π¨
π _M_out_cur
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_out_cur [protected]
Current put area. Where we're writing now. βοΈ
β _M_out_end
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_out_end [protected]
End of put area. When we hit this one the buffer is full and overflow() gets summoned. π₯
π AUTHOR π
Generated automatically by Doxygen for libstdc++ from the source code. So technically the author is a robot and I respect that immensely, she's doing great. π€β¨
And that's a wrap on the whole page bestie!! We did it!! ππ
π«Ά This absolute unit of a manpage was generated by Doxygen for libstdc++ straight from the source code, and that footer stamp is libstdc++'s own signature β the source/version tag and date living at the bottom like a little "made with love by the build system" note. Go forth and subclass responsibly, and remember: es-how-many-see, not show-manic. π¦β¨π
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms