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:
std::ostream
.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.
Definition at line 177 of file std_strings_iostream.hpp.
#include <std_strings_iostream.hpp>
Public Field Index: | |
::std::ostream * | ostream |
Public Method Index: | |
StringWriter () | |
::std::ostream * | GetStream () |
void | SetStream (::std::ostream *os) |
ALIB_API void | Write (const NString &src) |
ALIB_API void | Write (const WString &src) |
ALIB_API integer | WriteAndGetWideLength (const NString &src) |
ALIB_API integer | WriteAndGetWideLength (const WString &src) |
ALIB_API void | WriteChars (const nchar fillChar, integer count) |
Protected Field Index: | |
NAString | converter |
The string buffer used for conversion. | |
|
protected |
The string buffer used for conversion.
Definition at line 181 of file std_strings_iostream.hpp.
::std::ostream* ostream |
The output stream as provided with SetStream. Will be set to the std::cout
, respectively std::wcout
in the constructor.
Definition at line 186 of file std_strings_iostream.hpp.
|
inline |
Constructor. Invokes SetStream passing std::cout
.
Definition at line 193 of file std_strings_iostream.hpp.
|
inline |
Returns the output stream previously set with SetStream.
Definition at line 210 of file std_strings_iostream.hpp.
|
inline |
Sets the output stream.
os | Pointer to the output stream to write to. |
Definition at line 203 of file std_strings_iostream.hpp.
Write the given narrow string to the stream.
src | The string to write. |
Write the given wide string to the stream.
src | The string to write. |
Write the given narrow string to the stream and return the length of the string given if it was converted to wide characters.
src | The string to write. |
Write the given wide string to the stream and returns the length of the string given
src | The string to write. |
Write the given narrow character repeatedly to the stream.
fillChar | The character to write. |
count | The number of characters to write. |