nlib
nn::nlib::OutputConverterStream Class Reference

The base class for classes that act internally like OutputStream to convert data. More...

#include "nn/nlib/OutputConverterStream.h"

+ Inheritance diagram for nn::nlib::OutputConverterStream:

Public Member Functions

errno_t SetStream (OutputStream *ostr) noexcept
 Sets an output stream as the base stream. More...
 
OutputStreamGetStream () const noexcept
 Gets the input stream that will be the base stream. More...
 
- Public Member Functions inherited from nn::nlib::OutputStream
size_t Pos () const noexcept
 Returns the current position in the stream. More...
 
uint64_t Pos64 () const noexcept
 Returns the current position in the stream as a 64-bit integer. More...
 
bool Write (int b) noexcept
 Writes one byte of data to the stream. More...
 
bool Write (const void *p, size_t n) noexcept
 Writes n bytes of data to the stream. More...
 
bool WriteGather (const nlib_fd_iovec *iov, int iovcnt) noexcept
 Writes data from multiple non-continuous buffers to a stream. More...
 
bool Flush () noexcept
 Flushes the stream. More...
 
bool Close () noexcept
 Closes the stream after it has been flushed. Returns true if successful. More...
 
errno_t GetErrorValue () const noexcept
 Gets the error value. More...
 
BufferingMode GetBufferingMode () const noexcept
 Gets the buffering mode.
 
 operator bool () const
 Returns true if the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside.
 
constexpr OutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
virtual ~OutputStream () noexcept
 Destructor.
 

Additional Inherited Members

- Public Types inherited from nn::nlib::OutputStream
enum  BufferingMode {
  kBufferingModeBlockBuffered = 0,
  kBufferingModeLineBuffered,
  kBufferingModeUnbuffered
}
 The buffering mode for OutputStream. More...
 
- Protected Member Functions inherited from nn::nlib::OutputStream
void ResetBuffer (void *p, size_t nbytes) noexcept
 Sets the buffer held by OutputStream. More...
 
void SetError (errno_t e) const noexcept
 Sets an error to OutputStream. More...
 
- Protected Attributes inherited from nn::nlib::OutputStream
BufferingMode m_BufferingMode
 Stores the buffering mode. More...
 

Detailed Description

The base class for classes that act internally like OutputStream to convert data.

Description
If you use the SetStream function to set an output stream and use the OutputStream interface to write the data, the data is converted in an internal process and written to the output stream. Users normally do not make direct use of this feature.
The simplest coding for data conversion (where nothing is converted) looks something like the following.
The OutputTransform::GetWorkBuffer() function registers a buffer that OutputStream will use. OutputStream places data provided by the user in this buffer. The OutputTransform::Transform() function reads data from OutputStream and writes that data in the converted format. The OutputTransform::OnSetStream() function writes a process to be performed when OutputConverterStream::SetStream() is called. The OutputTransform::OnClose() function is called when a stream is closed.
Finally, instantiating the OutputConverterStreamTempl class template with a derived class of OutputTransform allows you to define an input stream that internally converts data.
class NoOutputTransform : public nlib_ns::OutputTransform {
public:
NoOutputTransform() {}
virtual errno_t Transform(nlib_ns::OutputStream* os, const void* p, size_t nbytes, bool do_flush) override {
if (!os->Write(p, nbytes)) { return os->GetErrorValue(); }
if (do_flush) {
if (!os->Flush()) { return os->GetErrorValue(); }
}
return 0;
}
virtual void* GetWorkBuffer(size_t* n) override {
*n = 128;
return buf_;
}
virtual errno_t OnSetStream(nlib_ns::OutputStream*) override {
return 0;
}
virtual errno_t OnClose(nlib_ns::OutputStream*) override {
return 0;
}
private:
unsigned char buf_[128];
NLIB_DISALLOW_COPY_AND_ASSIGN(NoOutputTransform);
};

Definition at line 40 of file OutputConverterStream.h.

Member Function Documentation

◆ GetStream()

nn::nlib::OutputConverterStream::GetStream ( ) const
inlinenoexcept

Gets the input stream that will be the base stream.

Returns
Returns the pointer to the output stream.

Definition at line 47 of file OutputConverterStream.h.

◆ SetStream()

nn::nlib::OutputConverterStream::SetStream ( OutputStream ostr)
noexcept

Sets an output stream as the base stream.

Parameters
[in]ostrA pointer to the base string.
Return values
0No error has occurred.
EEXISTThe stream is already set.
EINVALostr was set to NULL.
EBADFThe SetTransform function has not executed.
ENOMEMAllocation of working memory failed.

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