ocharstream Class Reference

Similar to std::ostringstream, but with the ability to swap character content. Has some similarity to std::ospanstream (C++23) More...

Inheritance diagram for ocharstream:
Collaboration diagram for ocharstream:

Public Member Functions

 ocharstream ()
 Default construct - empty. More...
 
 ocharstream (List< char > &&buffer)
 Move construct from List. More...
 
template<int SizeMin>
 ocharstream (DynamicList< char, SizeMin > &&buffer)
 Move construct from DynamicList. More...
 
std::streampos output_pos () const
 The current output position within the buffer (tellp) More...
 
std::streamsize capacity () const
 The put buffer capacity. More...
 
void reserve (const std::streamsize n)
 Reserve output space for at least this amount. More...
 
void rewind ()
 Rewind the stream, clearing any old errors. More...
 
UList< char > list () const
 Span of the current output characters (is modifiable!) More...
 
auto view () const -> decltype(buffer_type::view())
 A string_view (c++17) or span view (older c++) of buffer contents. More...
 
std::string str () const
 For ostringstream compatibility, return the buffer as string copy. More...
 
void swap (List< char > &other)
 Exchange stream content and parameter contents, reset positions. More...
 
template<int SizeMin>
void swap (DynamicList< char, SizeMin > &other)
 Exchange stream content and parameter contents, reset positions. More...
 
DynamicList< char > release ()
 Reset buffer and return contents. More...
 
void debug_info (Ostream &os) const
 Some information about the output buffer position/capacity. More...
 

Additional Inherited Members

- Protected Member Functions inherited from memorybuf::out_dynamic
virtual int overflow (int_type c=traits_type::eof())
 Handle overflow. More...
 
virtual std::streamsize xsputn (const char *s, std::streamsize n)
 Put sequence of characters. More...
 
 out_dynamic (size_t nbytes=512)
 Default construct with initial reserved number of bytes. More...
 
 out_dynamic (::Foam::List< char > &&buffer)
 Move construct from List. More...
 
template<int SizeMin>
 out_dynamic (::Foam::DynamicList< char, SizeMin > &&buffer)
 Move construct from DynamicList (uses entire capacity) More...
 
void reserve (const std::streamsize len)
 Increment capacity (if needed) and adjust buffer pointers. More...
 
void sync_pbuffer ()
 Sync put buffer pointers to agree with list dimensions. More...
 
void clearStorage ()
 Clear storage. More...
 
void shrink ()
 Shrink storage to addressed storage. More...
 
void swap (List< char > &other)
 Exchange buffer content and parameter contents, reset positions. More...
 
template<int SizeMin>
void swap (DynamicList< char, SizeMin > &other)
 Exchange buffer content and parameter contents, reset positions. More...
 
DynamicList< char > release ()
 Reset buffer and return contents as a DynamicList. The list size corresponds to the region of output. More...
 
 out_base ()=default
 Default construct. More...
 
 out_base (char *s, std::streamsize n)
 Construct for character array (can be nullptr) and number of bytes. More...
 
void resetp (char *s, std::streamsize n)
 Reset put buffer with character data (can be nullptr) and count. More...
 
std::streamsize span_tellp () const
 The current buffer put position. More...
 
std::streamsize span_capacity () const
 The put buffer capacity. More...
 
char * data_bytes () const
 The span data (start of output characters) More...
 
std::streamsize size_bytes () const
 The span size (size of output buffer) More...
 
stdFoam::span< const char > view () const
 
void info (Ostream &os) const
 Some information about the output buffer position/capacity. More...
 
- Protected Member Functions inherited from memorybuf
virtual std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out)
 Set position pointer to relative position. More...
 
virtual std::streampos seekpos (std::streampos pos, std::ios_base::openmode which=std::ios_base::in|std::ios_base::out)
 Set position pointer to absolute position. More...
 

Detailed Description

Similar to std::ostringstream, but with the ability to swap character content. Has some similarity to std::ospanstream (C++23)

Definition at line 64 of file OCharStream.H.

Constructor & Destructor Documentation

◆ ocharstream() [1/3]

ocharstream ( )
inline

Default construct - empty.

Definition at line 80 of file OCharStream.H.

◆ ocharstream() [2/3]

ocharstream ( List< char > &&  buffer)
inline

Move construct from List.

Definition at line 89 of file OCharStream.H.

References ocharstream::swap().

Here is the call graph for this function:

◆ ocharstream() [3/3]

ocharstream ( DynamicList< char, SizeMin > &&  buffer)
inline

Move construct from DynamicList.

Definition at line 100 of file OCharStream.H.

References ocharstream::swap().

Here is the call graph for this function:

Member Function Documentation

◆ output_pos()

std::streampos output_pos ( ) const
inline

The current output position within the buffer (tellp)

Definition at line 113 of file OCharStream.H.

References memorybuf::out_base::span_tellp().

Referenced by ocharstream::debug_info(), OCharStream::output_pos(), OCharStream::size(), and OCharStream::tellp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacity()

std::streamsize capacity ( ) const
inline

The put buffer capacity.

Definition at line 121 of file OCharStream.H.

References memorybuf::out_base::span_capacity().

Referenced by OCharStream::capacity(), and ocharstream::debug_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reserve()

void reserve ( const std::streamsize  n)
inline

Reserve output space for at least this amount.

Definition at line 129 of file OCharStream.H.

References n, and memorybuf::out_dynamic::reserve().

Referenced by OCharStream::reserve().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewind()

void rewind ( )
inline

Rewind the stream, clearing any old errors.

Definition at line 137 of file OCharStream.H.

References clear().

Referenced by OCharStream::rewind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ list()

UList<char> list ( ) const
inline

Span of the current output characters (is modifiable!)

Definition at line 146 of file OCharStream.H.

References memorybuf::out_base::data_bytes(), and memorybuf::out_base::size_bytes().

Referenced by OCharStream::list().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view()

auto view ( ) const -> decltype(buffer_type::view())
inline

A string_view (c++17) or span view (older c++) of buffer contents.

Definition at line 158 of file OCharStream.H.

References memorybuf::out_base::view().

Referenced by OCharStream::view().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str()

std::string str ( ) const
inline

For ostringstream compatibility, return the buffer as string copy.

Use sparingly - it creates a full copy!!

Definition at line 168 of file OCharStream.H.

References memorybuf::out_base::data_bytes(), and memorybuf::out_base::size_bytes().

Referenced by OCharStream::str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap() [1/2]

void swap ( List< char > &  other)
inline

Exchange stream content and parameter contents, reset positions.

Definition at line 180 of file OCharStream.H.

References clear(), and memorybuf::out_dynamic::swap().

Referenced by ocharstream::ocharstream(), OCharStream::OCharStream(), and OCharStream::swap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap() [2/2]

void swap ( DynamicList< char, SizeMin > &  other)
inline

Exchange stream content and parameter contents, reset positions.

Definition at line 190 of file OCharStream.H.

References clear(), and memorybuf::out_dynamic::swap().

Here is the call graph for this function:

◆ release()

DynamicList<char> release ( )
inline

Reset buffer and return contents.

Definition at line 199 of file OCharStream.H.

References clear(), and memorybuf::out_dynamic::release().

Referenced by OCharStream::release().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ debug_info()

void debug_info ( Ostream os) const
inline

Some information about the output buffer position/capacity.

Definition at line 209 of file OCharStream.H.

References ocharstream::capacity(), os(), and ocharstream::output_pos().

Here is the call graph for this function:

The documentation for this class was generated from the following file: