nlib
nn::nlib::InputConverterStream Class Reference

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

#include "nn/nlib/InputConverterStream.h"

+ Inheritance diagram for nn::nlib::InputConverterStream:

Public Member Functions

errno_t SetStream (InputStream *istr) noexcept
 Sets the input stream for reading the pre-converted data. More...
 
InputStreamGetStream () const noexcept
 Gets the input stream for reading the pre-converted data. More...
 
- Public Member Functions inherited from nn::nlib::InputStream
errno_t GetErrorValue () const noexcept
 Gets the error value. More...
 
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 value. More...
 
bool IsEos () noexcept
 Returns true if the stream is finished being read through to the end. If the stream has not been read through to the end, or if an error occurs, the function returns false. More...
 
int Read () noexcept
 Reads one byte of data from the stream. More...
 
int Peek () noexcept
 Reads the next byte without consuming the stream. More...
 
size_t Skip (size_t nbytes) noexcept
 Skips over the number of bytes specified by nbytes. More...
 
size_t Read (void *ptr, size_t nbytes) noexcept
 Reads the number of bytes of data specified by nbytes into the memory region specified by ptr. More...
 
template<size_t N>
size_t Read (nlib_byte_t(&buf)[N]) noexcept
 A template overload of the above function.
 
bool Close () noexcept
 Closes the stream. Returns true if successful. More...
 
bool Mark (size_t readlimit) noexcept
 This function provides settings that allow you to return to the current load position using GoBackToMark(). More...
 
bool GoBackToMark () noexcept
 This function allows you to return to the load position that the last Mark() has been executed at. More...
 
bool IsMarkSupported () const noexcept
 This function returns true if this stream supports Mark() and GoBackToMark().
 
 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 InputStream () noexcept
 Instantiates the object with default parameters (default constructor). This function is called from the derived class.
 
virtual ~InputStream () noexcept
 Destructor. This function is called from the derived class.
 

Additional Inherited Members

- Protected Member Functions inherited from nn::nlib::InputStream
void SetBuffer (void *p, size_t nbytes, bool is_mark_supported, bool is_buf_readonly) noexcept
 Sets the buffer held by InputStream. More...
 
void SetError (errno_t e) const noexcept
 Sets an error to InputStream. More...
 

Detailed Description

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

Description
If you use the SetStream function to set an input stream and read the data, the data conversion result can be read using the InputStream interface. 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 InputTransform::GetWorkBuffer() function registers a buffer that InputStream will use. InputStream retrieves data from this buffer and provides it to the user. The InputTransform::Transform() function reads data from InputStream and writes that data in the converted format. The InputTransform::OnSetStream() function writes a process to be performed when InputConverterStream::SetStream() is called. The InputTransform::OnClose() function is called when a stream is closed.
Finally, instantiating the InputConverterStreamTempl class template with a derived class of InputTransform allows you to define an input stream that internally converts data.
class NoInputTransform : public nlib_ns::InputTransform {
public:
NoInputTransform() {}
virtual errno_t Transform(nlib_ns::InputStream* is, void* p, size_t size, size_t* nbytes) override {
*nbytes = is->Read(p, size);
if (*nbytes == 0) return is->GetErrorValue();
return 0;
}
virtual void* GetWorkBuffer(size_t* n) override {
*n = 128;
return buf_;
}
virtual errno_t OnSetStream(nlib_ns::InputStream*) override {
return 0;
}
virtual errno_t OnClose() override {
return 0;
}
private:
unsigned char buf_[128];
NLIB_DISALLOW_COPY_AND_ASSIGN(NoInputTransform);
};

Definition at line 48 of file InputConverterStream.h.

Member Function Documentation

◆ GetStream()

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

Gets the input stream for reading the pre-converted data.

Returns
The pointer to the input stream.

Definition at line 56 of file InputConverterStream.h.

◆ SetStream()

nn::nlib::InputConverterStream::SetStream ( InputStream istr)
noexcept

Sets the input stream for reading the pre-converted data.

Parameters
[in]istrThe pointer to the stream for reading the pre-converted data.
Return values
0No error has occurred.
EEXISTThe stream is already set.
EINVAListr 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: