ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::compatibility::std::StringWriter Class Reference

Description:

This class is a simple helper-class that converts strings of the default character type to narrow strings as expected by std::ostream objects.

The basic goal of this class is to avoid preprocessor directives for code selection when the default string-type of ALib uses wide characters.

For example, to write string data into a file, the following approach is advised:

  1. Create an output stream of (derived) type std::ostream.
  2. Create an object of this class and pass the output stream via SetStream.
  3. Write string data stored in objects of platform-dependent type alias alib::AString by passing those to method Write.

Within step 3, the compiler chooses the right overloaded version of the method Write. Hence, the potentially necessary conversion of the string data is done transparently and only if needed.

See also
Class StringReader.

Definition at line 194 of file stdiostream.mpp.

Collaboration diagram for alib::strings::compatibility::std::StringWriter:
[legend]

Public Field Index:

::std::ostream * ostream
 

Public Method Index:

 StringWriter ()
 
::std::ostream * GetStream ()
 
void SetStream (::std::ostream *os)
 
ALIB_DLL void Write (const NString &src)
 
ALIB_DLL void Write (const WString &src)
 
ALIB_DLL integer WriteAndGetWideLength (const NString &src)
 
ALIB_DLL integer WriteAndGetWideLength (const WString &src)
 
ALIB_DLL void WriteChars (const nchar fillChar, integer count)
 

Protected Field Index:

NAString converter
 The string buffer used for conversion.
 

Field Details:

◆ converter

NAString alib::strings::compatibility::std::StringWriter::converter
protected

The string buffer used for conversion.

Definition at line 198 of file stdiostream.mpp.

◆ ostream

::std::ostream* alib::strings::compatibility::std::StringWriter::ostream

The output stream as provided with SetStream. Will be set to the std::cout, respectively std::wcout in the constructor.

Definition at line 203 of file stdiostream.mpp.

Constructor(s) / Destructor Details:

◆ StringWriter()

alib::strings::compatibility::std::StringWriter::StringWriter ( )
inline

Constructor. Invokes SetStream passing std::cout.

Definition at line 210 of file stdiostream.mpp.

Method Details:

◆ GetStream()

::std::ostream * alib::strings::compatibility::std::StringWriter::GetStream ( )
inline

Returns the output stream previously set with SetStream.

Returns
The output stream set with SetStream.

Definition at line 227 of file stdiostream.mpp.

◆ SetStream()

void alib::strings::compatibility::std::StringWriter::SetStream ( ::std::ostream * os)
inline

Sets the output stream.

Parameters
osPointer to the output stream to write to.

Definition at line 220 of file stdiostream.mpp.

◆ Write() [1/2]

ALIB_DLL void alib::strings::compatibility::std::StringWriter::Write ( const NString & src)

Write the given narrow string to the stream.

Parameters
srcThe string to write.

◆ Write() [2/2]

ALIB_DLL void alib::strings::compatibility::std::StringWriter::Write ( const WString & src)

Write the given wide string to the stream.

Parameters
srcThe string to write.

◆ WriteAndGetWideLength() [1/2]

ALIB_DLL integer alib::strings::compatibility::std::StringWriter::WriteAndGetWideLength ( const NString & src)

Write the given narrow string to the stream and return the length of the string given if it was converted to wide characters.

Note
The return value is the length of the given string if it was converted to wide string, even though in this overloaded version it is unnecessary to be converted. This is useful to determine the "real" output width when an output text is formatted. Of course, in many locales, this is still not the real output width because even uni-code characters are not guaranteed to represent exactly one printable character. But still, this value is already a much better approximation than the length of the given narrow string.
Parameters
srcThe string to write.
Returns
Returns the length of the given string as wide string.

◆ WriteAndGetWideLength() [2/2]

ALIB_DLL integer alib::strings::compatibility::std::StringWriter::WriteAndGetWideLength ( const WString & src)

Write the given wide string to the stream and returns the length of the string given

Parameters
srcThe string to write.
Returns
Returns the length of the given wide string.

◆ WriteChars()

ALIB_DLL void alib::strings::compatibility::std::StringWriter::WriteChars ( const nchar fillChar,
integer count )

Write the given narrow character repeatedly to the stream.

Parameters
fillCharThe character to write.
countThe number of characters to write.

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