HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_StringStreamBuffer Class Reference

#include <UT_StringStream.h>

+ Inheritance diagram for UT_StringStreamBuffer:

Public Member Functions

 UT_StringStreamBuffer (std::ios_base::openmode mode=(std::ios_base::in|std::ios_base::out), const char *buf=nullptr, exint len=-1)
 
const char * buffer () const
 
exint length () const
 
int64 getMemoryUsage (bool inclusive) const
 
void reset ()
 
const UT_WorkBufferstr ()
 
void swap (UT_WorkBuffer &buf)
 
void stealIntoString (UT_String &s)
 
void stealIntoStringHolder (UT_StringHolder &s)
 

Detailed Description

An a string buffer based on UT_WorkBuffer. Supports both input and output. Provides cleaner semantics than UT_OStrStream, which is based on the obsolete std::strstream class. Unlike UT_OStrStream, it is not necessary to manage the stream's memory externally, if it was dynamically allocated, or add a null byte termination. For example, this code:

SomeClass::save(os); // write things to os.
os << std::ends;
fprintf(stderr, "Buffer: %s", os.str());
os.rdbuf()->freeze(false);

Turns into:

SomeClass::save(os); // write things to os.
fprintf(stderr, "Buffer: %s", os.str());

Note that the explicit requirement for null termination, and the call to freeze to relinquish the buffer use, are both gone.

However, the downside is that you cannot pass explicit buffers to the stream. On the other hand, you should not be using fixed-sized buffers for output streams in the first place.

There's also support for input and input/output buffers, using UT_IStringStream and UT_StringStream. Class for the memory storage and stream buffering.

std::streambuf provides buffered reading and writing to an underlying stream. A UT_WorkBuffer is used for the underlying storage. Like a file, seeking past the end of the existing data is allowed.

The get buffer (reading) is defined by the eback(), gptr(), and egptr() pointers. These pointers are all nullptr iff the stream does not allow reading. myGPos >= 0 when seeked past the end of the existing data. In this situation, eback() == egptr() to prevent methods from pulling values from the get buffer.

The put buffer (writing) is defined by the pbase(), pptr(), and epptr() pointers. These pointers are all nullptr iff the stream does not allow writing. myPPos >= 0 when seeked past the end of the existing data. In this situation, pbase() == epptr() to prevent methods from putting values into the put buffer.

Definition at line 65 of file UT_StringStream.h.

Constructor & Destructor Documentation

UT_StringStreamBuffer::UT_StringStreamBuffer ( std::ios_base::openmode  mode = (std::ios_base::in | std::ios_base::out),
const char *  buf = nullptr,
exint  len = -1 
)
inline

Definition at line 24 of file UT_StringStreamImpl.h.

Member Function Documentation

const char* UT_StringStreamBuffer::buffer ( ) const
inline

Definition at line 73 of file UT_StringStream.h.

int64 UT_StringStreamBuffer::getMemoryUsage ( bool  inclusive) const
inline

Definition at line 76 of file UT_StringStream.h.

exint UT_StringStreamBuffer::length ( void  ) const
inline

Definition at line 74 of file UT_StringStream.h.

void UT_StringStreamBuffer::reset ( void  )
inline

Definition at line 59 of file UT_StringStreamImpl.h.

void UT_StringStreamBuffer::stealIntoString ( UT_String s)
inline

Definition at line 81 of file UT_StringStreamImpl.h.

void UT_StringStreamBuffer::stealIntoStringHolder ( UT_StringHolder s)
inline

Definition at line 89 of file UT_StringStreamImpl.h.

const UT_WorkBuffer & UT_StringStreamBuffer::str ( )
inline

Definition at line 66 of file UT_StringStreamImpl.h.

void UT_StringStreamBuffer::swap ( UT_WorkBuffer buf)
inline
Examples:
SIM/SNOW_Solver.C.

Definition at line 73 of file UT_StringStreamImpl.h.


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