ospanstream Class Reference

Similar to std::ostringstream, but with an externally managed output buffer which makes it most similar to std::ospanstream (C++23) More...

Inheritance diagram for ospanstream:
Collaboration diagram for ospanstream:

Public Member Functions

 ospanstream ()
 Default construct - empty. More...
 
 ospanstream (char *buffer, size_t nbytes)
 Construct for character array and number of bytes. More...
 
std::streampos output_pos () const
 The current output position within the buffer (tellp) More...
 
std::streamsize count () const
 The number of bytes outputted. More...
 
std::streamsize capacity () const
 The put buffer capacity. More...
 
void rewind ()
 Rewind the stream, clearing any old errors. More...
 
void seek (std::streampos pos)
 Reposition the stream from the start. More...
 
auto view () const
 A string_view of buffer contents. More...
 
auto view (size_t pos, size_t len=std::string::npos) const
 A sub-slice string view of the buffer contents. More...
 
UList< char > list () const
 Span of the current output characters (is modifiable!) More...
 
std::string str () const
 For ostringstream compatibility, return the buffer as string copy. More...
 
void reset (char *buffer, size_t nbytes)
 Reset the put buffer area. More...
 
void reset (std::string &s)
 Reset the put buffer area to use the data area from a string. More...
 
void debug_info (Ostream &os) const
 Some information about the output buffer position/capacity. More...
 
void print (Ostream &os) const
 Information about stream. More...
 
void overwrite (std::streampos pos, char c)
 Overwrite a single character. More...
 
void overwrite (std::streampos pos, const char *data, std::streamsize count)
 Overwrite a sub-slice with character content. More...
 
const char * cdata_bytes () const
 The output data (start of output characters) More...
 
char * data_bytes ()
 The output data (start of output characters) More...
 
std::streamsize size_bytes () const
 The current number of output characters. More...
 

Additional Inherited Members

- Protected Member Functions inherited from memorybuf::out_base
virtual std::streamsize xsputn (const char *s, std::streamsize n)
 Put sequence of characters to a fixed region. 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...
 
bool in_range (std::streampos pos) const
 True if position is within the current output range. More...
 
auto view () const
 A string view of the current output region. More...
 
auto view (size_t pos, size_t len) const
 A sub-slice string view of the current output region. More...
 
void pop_back (int n=1)
 Decrease the put area by 1 or more elements. More...
 
void overwrite (std::streampos pos, const char *data, std::streamsize count)
 Overwrite a sub-slice with character content. More...
 
void overwrite (std::streampos pos, char c)
 Overwrite a single character. More...
 
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 an externally managed output buffer which makes it most similar to std::ospanstream (C++23)

Definition at line 102 of file OSpanStream.H.

Constructor & Destructor Documentation

◆ ospanstream() [1/2]

ospanstream ( )
inline

Default construct - empty.

Definition at line 118 of file OSpanStream.H.

◆ ospanstream() [2/2]

ospanstream ( char *  buffer,
size_t  nbytes 
)
inline

Construct for character array and number of bytes.

Definition at line 127 of file OSpanStream.H.

Member Function Documentation

◆ output_pos()

std::streampos output_pos ( ) const
inline

The current output position within the buffer (tellp)

Definition at line 139 of file OSpanStream.H.

References memorybuf::out_base::span_tellp().

Referenced by ospanstream::debug_info(), OSpanStream::output_pos(), and OSpanStream::tellp().

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

◆ count()

std::streamsize count ( ) const
inline

The number of bytes outputted.

Definition at line 147 of file OSpanStream.H.

References memorybuf::out_base::size_bytes().

Referenced by OSpanStream::count(), ospanstream::overwrite(), and OSpanStream::size().

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 155 of file OSpanStream.H.

References memorybuf::out_base::span_capacity().

Referenced by OSpanStream::capacity(), and ospanstream::debug_info().

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 163 of file OSpanStream.H.

References clear().

Referenced by OSpanStream::rewind().

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

◆ seek()

void seek ( std::streampos  pos)
inline

Reposition the stream from the start.

Definition at line 172 of file OSpanStream.H.

References clear(), memorybuf::out_base::in_range(), and Foam::pos().

Referenced by OSpanStream::seek().

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

◆ view() [1/2]

auto view ( ) const
inline

A string_view of buffer contents.

Definition at line 184 of file OSpanStream.H.

References memorybuf::out_base::view().

Referenced by OSpanStream::view().

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

◆ view() [2/2]

auto view ( size_t  pos,
size_t  len = std::string::npos 
) const
inline

A sub-slice string view of the buffer contents.

Definition at line 189 of file OSpanStream.H.

References Foam::pos(), and memorybuf::out_base::view().

Here is the call graph for this function:

◆ list()

UList<char> list ( ) const
inline

Span of the current output characters (is modifiable!)

Definition at line 197 of file OSpanStream.H.

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

Referenced by OSpanStream::list().

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 211 of file OSpanStream.H.

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

Referenced by OSpanStream::str().

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

◆ reset() [1/2]

void reset ( char *  buffer,
size_t  nbytes 
)
inline

Reset the put buffer area.

Definition at line 223 of file OSpanStream.H.

References clear(), and memorybuf::out_base::resetp().

Referenced by OSpanStream::OSpanStream(), and OSpanStream::reset().

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

◆ reset() [2/2]

void reset ( std::string &  s)
inline

Reset the put buffer area to use the data area from a string.

Definition at line 232 of file OSpanStream.H.

References clear(), memorybuf::out_base::resetp(), and s.

Here is the call graph for this function:

◆ debug_info()

void debug_info ( Ostream os) const
inline

Some information about the output buffer position/capacity.

Definition at line 242 of file OSpanStream.H.

References ospanstream::capacity(), and ospanstream::output_pos().

Referenced by ospanstream::print(), and OSpanStream::print().

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

◆ print()

void print ( Ostream os) const
inline

Information about stream.

Definition at line 250 of file OSpanStream.H.

References ospanstream::debug_info().

Here is the call graph for this function:

◆ overwrite() [1/2]

void overwrite ( std::streampos  pos,
char  c 
)
inline

Overwrite a single character.

Definition at line 258 of file OSpanStream.H.

References Foam::constant::universal::c, memorybuf::out_base::overwrite(), and Foam::pos().

Referenced by OSpanStream::overwrite().

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

◆ overwrite() [2/2]

void overwrite ( std::streampos  pos,
const char *  data,
std::streamsize  count 
)
inline

Overwrite a sub-slice with character content.

Definition at line 267 of file OSpanStream.H.

References ospanstream::count(), memorybuf::out_base::overwrite(), and Foam::pos().

Here is the call graph for this function:

◆ cdata_bytes()

const char* cdata_bytes ( ) const
inline

The output data (start of output characters)

Definition at line 279 of file OSpanStream.H.

References memorybuf::out_base::data_bytes().

Here is the call graph for this function:

◆ data_bytes()

char* data_bytes ( )
inline

The output data (start of output characters)

Definition at line 284 of file OSpanStream.H.

References memorybuf::out_base::data_bytes().

Here is the call graph for this function:

◆ size_bytes()

std::streamsize size_bytes ( ) const
inline

The current number of output characters.

Definition at line 289 of file OSpanStream.H.

References memorybuf::out_base::size_bytes().

Here is the call graph for this function:

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