util::stream
This module provides classes to format text strings from data. The class simplifies printing textual data into output streams.
util::stream::Std(in/out)Stream
Classes util::stream::StdinStream
and util::stream::StdoutStream
are tightly connected to
the byte-by-byte input and output functions getByteFromStdin()
and putByteToStdout()
that
in turn are architecture-dependent, i.e. their implementation is found in corresponding BSP.
StdoutStream cut;
cut.write(::estd::make_str("Test"));
util::stream::NormalizeLfOutputStream
The util::stream::NormalizeLfOutputStream
class is implemented using the decorator design
pattern. It inherits from the util::stream::IOutputStream
interface and aggregates an instance
of util::stream::StdoutStream
. The write()
function of this class also checks newline symbols
(Windows, Linux) to ensure proper output formatting.
declare::StringBufferOutputStream<40> stream;
NormalizeLfOutputStream cut(stream, "[CRLF]");
cut.write('a');
cut.write('\n');
// The symbol of new line is replaced by CR/LF:
assert("a[CRLF]" == std::string(stream.getString()));
util::stream::NullOutputStream
The class is also inheriting from util::stream::NormalizeLfOutputStream
and providing dummy
write()
methods implementations.
NullOutputStream stream;
assert(stream.isEof());
util::stream::StringBufferOutputStream
The util::stream::StringBufferOutputStream
class is useful for outputting data into a string
buffer instead of printing it to the terminal. This class inherits from
util::stream::ISharedOutputStream
and provides the same interface methods (write()
,
isEof()
, etc.) as other output stream classes.
char buffer[10];
memset(buffer, 0x17, 10);
stream::StringBufferOutputStream cut(::estd::make_slice(buffer).subslice(9));
cut.write(::estd::make_str("abc"));
cut.write(::estd::make_str("def"));
assert("abcdef" == cut.getString());