STD::STRINGBUF(3)
π NAME π
std::basic_stringbuf< _CharT, _Traits, _Alloc > β the actual work of input and output (for std::string). π
(also hi bestie, this page lives in the Library Functions Manual, section (3), just so you know where you are π«Ά)
πΈ SYNOPSIS πΈ
#include <sstream>
Inherits std::basic_streambuf< _CharT, _Traits >. π
β¨ Public Types β¨
typedef __string_type::size_type __size_typetypedef basic_streambuf< char_type, traits_type > __streambuf_typetypedef basic_string< char_type, _Traits, _Alloc > __string_typetypedef _Alloc allocator_typetypedef _CharT char_typetypedef traits_type::int_type int_typetypedef traits_type::off_type off_typetypedef traits_type::pos_type pos_typetypedef _Traits traits_type
π Public Member Functions π
basic_stringbuf ()β starts with an empty string buffer. π«§basic_stringbuf (__string_type &&__s, ios_base::openmode __mode=ios_base::in|ios_base::out)basic_stringbuf (basic_stringbuf &&__rhs)basic_stringbuf (basic_stringbuf &&__rhs, const allocator_type &__a)basic_stringbuf (const __string_type &__str, ios_base::openmode __mode=ios_base::in|ios_base::out)β starts with an existing string buffer. π§Ίbasic_stringbuf (const allocator_type &__a)template<typename _SAlloc> basic_stringbuf (const basic_string< _CharT, _Traits, _SAlloc > &__s, const allocator_type &__a)template<typename _SAlloc> basic_stringbuf (const basic_string< _CharT, _Traits, _SAlloc > &__s, ios_base::openmode __mode, const allocator_type &__a)template<typename _SAlloc> basic_stringbuf (const basic_string< _CharT, _Traits, _SAlloc > &__s, ios_base::openmode __mode=ios_base::in|ios_base::out)basic_stringbuf (const basic_stringbuf &)=deletebasic_stringbuf (ios_base::openmode __mode)β starts with an empty string buffer. π«§basic_stringbuf (ios_base::openmode __mode, const allocator_type &__a)allocator_type get_allocator () const noexceptlocale getloc () constβ locale access. πstreamsize in_avail ()β looking ahead into the stream. πbasic_stringbuf & operator= (basic_stringbuf &&__rhs)basic_stringbuf & operator= (const basic_stringbuf &)=deletelocale 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.__string_type str () &&__string_type str () const &β copying out the string buffer. π€void str (__string_type &&__s)void str (const __string_type &__s)β setting a new buffer. π₯template<__allocator_like _SAlloc> basic_string< _CharT, _Traits, _SAlloc > str (const _SAlloc &__sa) consttemplate<__allocator_like _SAlloc> void str (const basic_string< _CharT, _Traits, _SAlloc > &__s)int_type sungetc ()β moving backwards in the input stream. βͺvoid swap (basic_stringbuf &__rhs) noexcept(_Noexcept_swap::value)basic_string_view< char_type, traits_type > view () const noexcept
and these inherited cuties too, nested under the same umbrella:
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 π
void __safe_gbump (streamsize __n)void __safe_pbump (streamsize __n)void _M_pbump (char_type *__pbeg, char_type *__pend, off_type __off)void _M_stringbuf_init (ios_base::openmode __mode)void _M_sync (char_type *__base, __size_type __i, __size_type __o)void _M_update_egptr ()void gbump (int __n)β moving the read position. πvirtual void imbue (const locale &__loc)β changes translations. π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 __off, ios_base::seekdir __way, ios_base::openmode __mode=ios_base::in|ios_base::out)β alters the stream positions.virtual pos_type seekpos (pos_type __sp, ios_base::openmode __mode=ios_base::in|ios_base::out)β alters the stream positions.virtual __streambuf_type * setbuf (char_type *__s, streamsize __n)β 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.
and the get/put area pointer trio, also protected, also inherited:
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.ios_base::openmode _M_modeβ place to stashin || out || in | outsettings for current stringbuf. ποΈ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.__string_type _M_string
π Detailed Description π
template<typename _CharT, typename _Traits, typename _Alloc>
class std::basic_stringbuf< _CharT, _Traits, _Alloc >
"The actual work of input and output (for std::string)." β yes bestie, that's the whole assignment. π
π¦ Template Parameters π¦
_CharTβ type of character stream._Traitsβ traits for character type, defaults tochar_traits<_CharT>._Allocβ allocator type, defaults toallocator<_CharT>.
This class associates either or both of its input and output sequences with a sequence of characters, which can be initialized from, or made available as, a std::basic_string. (Paraphrased from [27.7.1]/1.) π«Ά
For this class, open modes (of type ios_base::openmode) have in set if the input sequence can be read, and out set if the output sequence can be written. no cap. βοΈ
π§ Constructor & Destructor Documentation π§
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_stringbuf< _CharT, _Traits, _Alloc >::basic_stringbuf ()
[inline]
Starts with an empty string buffer. π«§ The default constructor initializes the parent class using its own default ctor.
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_stringbuf< _CharT, _Traits, _Alloc >::basic_stringbuf
(ios_base::openmode __mode) [inline], [explicit]
Starts with an empty string buffer. π«§
Parameters
__modeβ whether the buffer can read, or write, or both.
The default constructor initializes the parent class using its own default ctor.
template<typename _CharT, typename _Traits, typename _Alloc>
std::basic_stringbuf< _CharT, _Traits, _Alloc >::basic_stringbuf (const
__string_type & __str, ios_base::openmode __mode = ios_base::in |
ios_base::out) [inline], [explicit]
Starts with an existing string buffer. π§Ί
Parameters
__strβ a string to copy as a starting buffer.__modeβ whether the buffer can read, or write, or both.
This constructor initializes the parent class using its own default ctor.
π Member Function Documentation π
template<typename _CharT, typename _Traits> char_type *
std::basic_streambuf< _CharT, _Traits >::eback () const [inline],
[protected], [inherited]
Access to the get area. π These functions 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_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(). π«
template<typename _CharT, typename _Traits> char_type *
std::basic_streambuf< _CharT, _Traits >::egptr () const [inline],
[protected], [inherited]
Access to the get area. π These functions 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_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()xsgetn()
epptr() β put-area access, the finale π
template<typename _CharT, typename _Traits>
char_type * std::basic_streambuf< _CharT, _Traits >::epptr () const
[inline] [protected] [inherited]
okay so this is the put area access squad π and listen, these functions are only available to other protected functions, including derived classes. iykyk.
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()xsputn()
gbump() β moving the read position, lowkey β¨
template<typename _CharT, typename _Traits>
void std::basic_streambuf< _CharT, _Traits >::gbump (int __n)
[inline] [protected] [inherited]
Parameters
__nβ the delta by which to move.
fr this just advances the read position without returning any data. it's giving "scoot over, no thoughts, no output" π¦
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()std::basic_filebuf< _CharT, _Traits >::xsgetn()
getloc() β locale access bestie πΈ
template<typename _CharT, typename _Traits>
locale std::basic_streambuf< _CharT, _Traits >::getloc () const
[inline] [inherited]
Returns
The current locale in effect.
so here's the tea: if pubimbue(loc) has been called, then the most recent loc is returned. otherwise, the global locale in effect at the time of construction gets returned. periodt π
Referenced by:
std::basic_streambuf< char_type, traits_type >::pubimbue()
gptr() β get-area access, main character energy π
template<typename _CharT, typename _Traits>
char_type * std::basic_streambuf< _CharT, _Traits >::gptr () const
[inline] [protected] [inherited]
the get area trio, and again β these functions 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()xsgetn()
imbue() β changing up the translations π₯
template<typename _CharT, typename _Traits>
virtual void std::basic_streambuf< _CharT, _Traits >::imbue (const locale & __loc)
[inline] [protected] [virtual] [inherited]
Parameters
__locβ a new locale.
translations done during I/O that depend on the current locale get swapped out by this call. and the standard adds this lil gem: "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 nothing. it's giving empty. π
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 >
Referenced by:
std::basic_streambuf< char_type, traits_type >::pubimbue()
in_avail() β looking ahead into the stream π
template<typename _CharT, typename _Traits>
streamsize std::basic_streambuf< _CharT, _Traits >::in_avail ()
[inline] [inherited]
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(). bestie is peeking ahead fr fr π
overflow() β stringbuf edition, consuming data π
template<class _CharT, class _Traits, class _Alloc>
basic_stringbuf< _CharT, _Traits, _Alloc >::int_type
std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow (int_type __c = traits_type::eof())
[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 (and you know we love informally), this function is called when the output buffer is full β or doesn't even exist, since buffering need not actually be done. if a buffer exists, it gets 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(). slay π
for a formal definition of this function, see a good text such as Langer & Kreft, or [27.5.2.4.5]/3-7. (yes, they said "a good text", we're just relaying the vibes π )
a functioning output streambuf can be created by overriding only this function β no buffer area will be used. iconic.
Note β the base class version does nothing, returns eof().
Reimplemented from std::basic_streambuf< _CharT, _Traits >.
References
_M_modestd::basic_string< _CharT, _Traits, _Alloc >::assign()std::basic_streambuf< _CharT, _Traits >::eback()std::basic_streambuf< _CharT, _Traits >::egptr()std::basic_streambuf< _CharT, _Traits >::epptr()std::basic_streambuf< _CharT, _Traits >::gptr()std::ios_base::instd::max()std::min()std::ios_base::outstd::basic_streambuf< _CharT, _Traits >::pbase()std::basic_streambuf< _CharT, _Traits >::pbump()std::basic_streambuf< _CharT, _Traits >::pptr()std::basic_string< _CharT, _Traits, _Alloc >::push_back()std::basic_string< _CharT, _Traits, _Alloc >::reserve()std::basic_streambuf< _CharT, _Traits >::setg()
pbackfail() β stringbuf edition, backing it up π
template<class _CharT, class _Traits, class _Alloc>
basic_stringbuf< _CharT, _Traits, _Alloc >::int_type
std::basic_stringbuf< _CharT, _Traits, _Alloc >::pbackfail (int_type __c = traits_type::eof())
[protected] [virtual]
Tries to back up the input sequence.
Parameters
__cβ the character to be inserted back into the sequence.
Returns
eof() on failure, some other value on success
Postcondition
the constraints of gptr(), eback(), and pptr() are the same as for underflow().
Note β the base class version does nothing, returns eof().
Reimplemented from std::basic_streambuf< _CharT, _Traits >.
References
_M_modestd::basic_streambuf< _CharT, _Traits >::eback()std::basic_streambuf< _CharT, _Traits >::gbump()std::basic_streambuf< _CharT, _Traits >::gptr()std::ios_base::out
pbase() β put-area access, the beginning β¨
template<typename _CharT, typename _Traits>
char_type * std::basic_streambuf< _CharT, _Traits >::pbase () const
[inline] [protected] [inherited]
put area access, and yep β these functions are 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_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()std::basic_filebuf< _CharT, _Traits >::xsputn()
pbump() β moving the write position πΈ
template<typename _CharT, typename _Traits>
void std::basic_streambuf< _CharT, _Traits >::pbump (int __n)
[inline] [protected] [inherited]
Parameters
__nβ the delta by which to move.
just advances the write position without returning any data. no output, just vibes π¦
Referenced by:
std::basic_filebuf< _CharT, _Traits >::overflow()std::basic_stringbuf< _CharT, _Traits, _Alloc >::overflow()std::basic_streambuf< char_type, traits_type >::sputc()
pptr() β put-area access, the next one π
template<typename _CharT, typename _Traits>
char_type * std::basic_streambuf< _CharT, _Traits >::pptr () const
[inline] [protected] [inherited]
put area access once more, and yes bestie β these functions are 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_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()xsputn()
pubimbue() β entry point for imbue() π
template<typename _CharT, typename _Traits>
locale std::basic_streambuf< _CharT, _Traits >::pubimbue (const locale & __loc)
[inline] [inherited]
Parameters
__locβ the new locale.
Returns
The previous locale.
this is the entry point for imbue() β it calls the derived imbue(__loc). middle-man behavior but make it fashion π
β¨ pubseekoff β the stream position glow-up π
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], [inherited]
Okay so bestie, this one alters the stream position π like it literally slides the lil cursor around in the stream.
Parameters β gotta know your inputs, periodt:
__offβ the offset. how far you're sliding, fr.__wayβ a value forios_base::seekdir. that's the direction vibe π__modeβ a value forios_base::openmode. defaults toios_base::in | ios_base::out, no cap.
And the tea β: it calls the virtual seekoff function. that's the whole point of it existing, iykyk.
β¨ pubseekpos β same energy, but with a position π
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], [inherited]
Again, alters the stream position π iconic behavior, honestly.
Parameters:
__spβ the position. like, the actual spot you wanna be at π―__modeβ a value forios_base::openmode. default isios_base::in | ios_base::out.
Calls the virtual seekpos function. that's it, that's the job.
β¨ 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], [inherited]
Entry points for derived buffer functions. okay so the lore here is chef's kiss π β the public versions of pubfoo dispatch to the protected derived foo member functions, passing the arguments (if any) and returning the result unchanged. it's giving middle-manager energy but make it iconic.
β¨ pubsync β sync it up π«
template<typename _CharT, typename _Traits>
int std::basic_streambuf<_CharT, _Traits>::pubsync()
[inline], [inherited]
Calls the virtual sync function. short king. π
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], [inherited]
Getting the next character. obsessed with this one ngl.
Returns β the next character, or eof.
So here's how it works bestie: if the input read position is available, it returns that character and increments the read pointer β¨. otherwise it calls and returns uflow(). simple as that.
Referenced by:
std::basic_istream< _CharT, _Traits >::ignore()std::basic_streambuf< char_type, traits_type >::snextc()std::basic_istream< _CharT, char_traits< _CharT > >::unget()
β¨ seekoff (the basic_stringbuf one) β each class does its own thing π§
template<class _CharT, class _Traits, class _Alloc>
basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
std::basic_stringbuf<_CharT, _Traits, _Alloc>::seekoff(
off_type,
ios_base::seekdir,
ios_base::openmode = ios_base::in | ios_base::out)
[protected], [virtual]
Alters the stream positions. Each derived class provides its own appropriate behavior. so like, this is the base-class blueprint and every derived class gets to do its own lil interpretation πΈ
Note β Base class version does nothing, and returns a pos_type that represents an invalid stream position. so don't come crying to base class bestie, she is NOT going to help you π
Reimplemented from std::basic_streambuf< _CharT, _Traits >.
References: _M_mode, std::ios_base::cur, std::basic_streambuf< _CharT, _Traits >::eback(), std::basic_streambuf< _CharT, _Traits >::egptr(), std::ios_base::end, std::basic_streambuf< _CharT, _Traits >::epptr(), std::basic_streambuf< _CharT, _Traits >::gptr(), std::ios_base::in, std::ios_base::out, std::basic_streambuf< _CharT, _Traits >::pbase(), std::basic_streambuf< _CharT, _Traits >::pptr(), and std::basic_streambuf< _CharT, _Traits >::setg().
β¨ seekpos (the basic_stringbuf one) β same but position-y π
template<class _CharT, class _Traits, class _Alloc>
basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
std::basic_stringbuf<_CharT, _Traits, _Alloc>::seekpos(
pos_type,
ios_base::openmode = ios_base::in | ios_base::out)
[protected], [virtual]
Alters the stream positions. Each derived class provides its own appropriate behavior. yup, same speech, different function π
Note β Base class version does nothing, returns a pos_type that represents an invalid stream position. again. base class bestie is useless here, no offense π«Ά
Reimplemented from std::basic_streambuf< _CharT, _Traits >.
References: _M_mode, std::basic_streambuf< _CharT, _Traits >::eback(), std::basic_streambuf< _CharT, _Traits >::egptr(), std::basic_streambuf< _CharT, _Traits >::epptr(), std::ios_base::in, std::ios_base::out, std::basic_streambuf< _CharT, _Traits >::pbase(), and std::basic_streambuf< _CharT, _Traits >::setg().
β¨ setbuf β manipulating the buffer, literally π¦
template<typename _CharT, typename _Traits, typename _Alloc>
virtual __streambuf_type* std::basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(
char_type* __s,
streamsize __n)
[inline], [protected], [virtual]
Manipulates the buffer. yes queen, do your thing β¨
Parameters:
__sβ pointer to a buffer area.__nβ size of__s.
Returns β this π
Okay so the important bit: if no buffer has already been created, and both __s and __n are non-zero, then __s is used as a buffer. for more, go read:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering
Reimplemented from std::basic_streambuf< _CharT, _Traits >.
β¨ 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], [inherited]
Setting the three read area pointers. three pointers, one function, zero stress π
Parameters:
__gbegβ a pointer.__gnextβ a pointer.__gendβ a pointer.
Postcondition β__gbeg == eback(),__gnext == gptr(), and__gend == egptr(). and that's the vibe check, bestie π
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()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], [inherited]
Setting the three write area pointers. yes, three. no, only two params. that's just the lore, don't question it π
Parameters:
__pbegβ a pointer.__pendβ a pointer.
Postcondition β__pbeg == pbase(),__pbeg == pptr(), and__pend == epptr(). not me pointing out that__pbegshows up twice in that list β that's exactly what it says, so we're keeping it verbatim π₯
Referenced by:
std::wbuffer_convert< _Codecvt, _Elem, _Tr >::wbuffer_convert()std::basic_filebuf< char_type, traits_type >::_M_set_buffer()
β¨ sgetc β peeking at the next character π
template<typename _CharT, typename _Traits>
int_type std::basic_streambuf<_CharT, _Traits>::sgetc()
[inline], [inherited]
Getting the next character.
Returns β the next character, or eof.
So: if the input read position is available, returns that character. otherwise it calls and returns underflow(). and here's the key detail, bestie β it does NOT move the read position after fetching the character. it's giving look-don't-touch π
β¨
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()std::basic_streambuf< char_type, traits_type >::snextc()
(yes, get() is listed twice up there β that's the original's whole vibe, we don't edit, we just deliver π«Ά)
β¨ sgetn β entry point for xsgetn πΈ
template<typename _CharT, typename _Traits>
streamsize std::basic_streambuf<_CharT, _Traits>::sgetn(
char_type* __s,
streamsize __n)
[inline], [inherited]
Entry point for xsgetn.
Parameters:
__sβ a buffer area.__nβ a count.
Returns xsgetn(__s,__n). and the effect, bestie, is that it fills __s[0] through __s[__n-1] with characters from the input sequence, if possible π if possible!! key phrase!! don't forget it!!
β¨ showmanyc β investigating the data available π΅οΈββοΈ
template<typename _CharT, typename _Traits, typename _Alloc>
virtual streamsize std::basic_stringbuf<_CharT, _Traits, _Alloc>::showmanyc()
[inline], [protected], [virtual]
Investigating the data available. detective mode, activated π
Returns β an estimate of the number of characters available in the input sequence, or -1.
And now the rules, listen up π’:
- If it returns a positive value, then successive calls to
underflow()will not returntraits::eof()until at least that number of characters have been supplied. β¨ - If
showmanyc()returns-1, then calls tounderflow()oruflow()will fail. π
Note β Base class version does nothing, returns zero. The standard adds that the intention is not only that the calls [tounderfloworuflow] will not returneof()but that they will return immediately. The standard adds that the morphemes ofshowmanycare es-how-many-see, not show-manic. π truly iconic etymology content, we love a pronunciation footnote.
Reimplemented from std::basic_streambuf< _CharT, _Traits >.
β¨ snextc β the next next character π¦
template<typename _CharT, typename _Traits>
int_type std::basic_streambuf<_CharT, _Traits>::snextc()
[inline], [inherited]
Getting the next character.
Returns β the next character, or eof.
Calls sbumpc(), and if that function returns traits::eof(), so does this function. Otherwise, sgetc(). it's a whole relay race and she's running it πββοΈπ¨
Referenced by:
std::basic_istream< _CharT, char_traits< _CharT > >::get()std::basic_iostream< char_type, traits_type >::ignore()std::basic_istream< _CharT, char_traits< _CharT > >::readsome()
β¨ sputbackc β pushing characters back into the input stream π
template<typename _CharT, typename _Traits>
int_type std::basic_streambuf<_CharT, _Traits>::sputbackc(char_type __c)
[inline], [inherited]
Pushing characters back into the input stream. it's giving "nvm take it back" energy π
Parameters:
__cβ the character to push back.
Returns β the previous character, if possible.
Similar to sungetc(), but here's the difference bestie: __c is pushed onto the stream instead of the previous character. and if successful, the next character fetched from the input stream will be __c β¨
Referenced by std::basic_istream< _CharT, _Traits >::putback().
β¨ sputc β entry point for all single-character output functions π₯
template<typename _CharT, typename _Traits>
int_type std::basic_streambuf<_CharT, _Traits>::sputc(char_type __c)
[inline], [inherited]
Entry point for all single-character output functions.
Parameters:
__cβ a character to output.
Returns β __c, if possible.
One of two public output functions. okay so the mechanics, no cap:
- If a write position is available for the output sequence (i.e., the buffer is not full) β stores
__cin that position, increments the position, and returnstraits::to_int_type(__c). π - If a write position is not available β returns
overflow(__c). π«Ά
Referenced by std::wbuffer_convert< _Codecvt, _Elem, _Tr >::overflow().
β¨ sputn β also entry point for all single-character output functions π
template<typename _CharT, typename _Traits>
streamsize std::basic_streambuf<_CharT, _Traits>::sputn(
const char_type* __s,
streamsize __n)
[inline], [inherited]
Entry point for all single-character output functions. (yes the description is the same as sputc's β that's literally what the page says, we do not editorialize the facts, only the vibes π)
Parameters:
__sβ a buffer read area.__nβ a count.
One of two public output functions.
Returns xsputn(__s,__n). and the effect is to write __s[0] through __s[__n-1] to the output sequence, if possible β¨ if possible strikes again!!
β¨ str (the const one) β copying out the string buffer π
template<typename _CharT, typename _Traits, typename _Alloc>
__string_type std::basic_stringbuf<_CharT, _Traits, _Alloc>::str() const &
[inline], [nodiscard]
Copying out the string buffer. note that [nodiscard] bestie β do NOT ignore this return value, she is talking to you π’
Returns β a copy of one of the underlying sequences.
And which one?? the rules:
- If the buffer is only created in input mode, the underlying character sequence is equal to the input sequence.
- Otherwise, it is equal to the output sequence.
[27.7.1.2]/1πΈ
β¨ str (the setter one) β setting a new buffer π
template<typename _CharT, typename _Traits, typename _Alloc>
void std::basic_stringbuf<_CharT, _Traits, _Alloc>::str(const __string_type& __s)
[inline]
Setting a new buffer.
Parameters:
__sβ the string to use as a new sequence.
Deallocates any previous stored sequence, then copies s to use as a new one. out with the old, in with the new, periodt π
β¨
sungetc()
template<typename _CharT, typename _Traits> int_type std::basic_streambuf<
_CharT, _Traits >::sungetc () [inline], [inherited]
okay so moving backwards in the input stream, bestie. 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. Referenced by std::basic_istream< _CharT, _Traits >::unget(). periodt π
sync()
template<typename _CharT, typename _Traits> virtual int
std::basic_streambuf< _CharT, _Traits >::sync () [inline], [protected],
[virtual], [inherited]
Synchronizes the buffer arrays with the controlled sequences. Returns: -1 on failure. Each derived class provides its own appropriate behavior, including the definition of failure.
Note: Base class version does nothing, returns zero.
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 >, and std::wbuffer_convert< _Codecvt, _Elem, _Tr >.
Referenced by std::basic_streambuf< char_type, traits_type >::pubsync(). no cap β¨
uflow()
template<typename _CharT, typename _Traits> virtual int_type
std::basic_streambuf< _CharT, _Traits >::uflow () [inline],
[protected], [virtual], [inherited]
Fetches more data from the controlled sequence. 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. However, this function also moves the read position forward by one. Reimplemented in __gnu_cxx::stdio_sync_filebuf< _CharT, _Traits >. Referenced by std::basic_streambuf< char_type, traits_type >::sbumpc(), and xsgetn(). it's giving underflow but with a lil scoot forward π¦
underflow()
template<class _CharT, class _Traits, class _Alloc> basic_stringbuf< _CharT,
_Traits, _Alloc >::int_type std::basic_stringbuf< _CharT, _Traits,
_Alloc >::underflow () [protected], [virtual]
Fetches more data from the controlled sequence. 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). 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. 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: Base class version does nothing, returns eof().
Reimplemented from std::basic_streambuf< _CharT, _Traits >. References _M_mode, std::basic_streambuf< _CharT, _Traits >::egptr(), std::basic_streambuf< _CharT, _Traits >::gptr(), and std::ios_base::in. the way this is the main character of input buffers ππ
xsgetn()
template<typename _CharT, typename _Traits> streamsize std::basic_streambuf<
_CharT, _Traits >::xsgetn (char_type * __s, streamsize __n) [protected],
[virtual], [inherited]
Multiple character extraction. Parameters:
__sβ A buffer area.__nβ Maximum number of characters to assign.
Returns: The number of characters assigned. Fills __s[0] through __s[__n-1] with characters from the input sequence, as if by sbumpc(). Stops when either __n characters have been copied, or when traits::eof() would be copied. It is expected that derived classes provide a more efficient implementation by overriding this definition. 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 >, and std::basic_filebuf< char_type, traits_type >. References egptr(), gptr(), std::min(), and uflow(). Referenced by std::basic_streambuf< char_type, traits_type >::sgetn(). slay extraction energy π
xsputn()
template<typename _CharT, typename _Traits> streamsize std::basic_streambuf<
_CharT, _Traits >::xsputn (const char_type * __s, streamsize __n)
[protected], [virtual], [inherited]
Multiple character insertion. Parameters:
__sβ A buffer area.__nβ Maximum number of characters to write.
Returns: The number of characters written. Writes __s[0] through __s[__n-1] to the output sequence, as if by sputc(). Stops when either n characters have been copied, or when sputc() would return traits::eof(). It is expected that derived classes provide a more efficient implementation by overriding this definition. 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 >, and std::basic_filebuf< char_type, traits_type >. References epptr(), std::min(), overflow(), and pptr(). Referenced by std::basic_streambuf< char_type, traits_type >::sputn(). putting characters out here looking iconic π
π Member Data Documentation π
_M_buf_locale
template<typename _CharT, typename _Traits> locale std::basic_streambuf<
_CharT, _Traits >::_M_buf_locale [protected], [inherited]
Current locale setting. Referenced by std::basic_filebuf< _CharT, _Traits >::basic_filebuf(). locale queen π
_M_in_beg
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_in_beg [protected], [inherited]
Start of get area.
_M_in_cur
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_in_cur [protected], [inherited]
Current read area.
_M_in_end
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_in_end [protected], [inherited]
End of get area.
_M_mode
template<typename _CharT, typename _Traits, typename _Alloc>
ios_base::openmode std::basic_stringbuf< _CharT, _Traits, _Alloc
>::_M_mode [protected]
Place to stash in || out || in | out settings for current stringbuf. Referenced by overflow(), pbackfail(), seekoff(), seekpos(), and underflow(). the mode stash, periodt π₯
_M_out_beg
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_out_beg [protected], [inherited]
Start of put area.
_M_out_cur
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_out_cur [protected], [inherited]
Current put area.
_M_out_end
template<typename _CharT, typename _Traits> char_type* std::basic_streambuf<
_CharT, _Traits >::_M_out_end [protected], [inherited]
End of put area.
β¨ Author β¨
Generated automatically by Doxygen for libstdc++ from the source code.
And that's the whole vibe, bestie π source/version is libstdc++, title is std::basic...s, _Alloc >(3), and the date slot in the footer is being iconic and mysterious. bye π«Ά
π¦ 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