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...
 
NLIB_CHECK_RESULT 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...
 
bool Close () noexcept
 Closes the stream. Returns true if successful. More...
 
 operator bool () const
 Returns true if no internal error has occurred.
 
constexpr InputStream () noexcept
 Instantiates the object. 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 ResetBuffer (void *p, size_t nbytes) 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.
class NoInputTransform : public InputTransform {
public:
NoInputTransform() {}
virtual errno_t Transform(InputStream* is, void* p, size_t size, size_t* nbytes) {
// Reads the pre-conversed data from 'is,' (converts the data) and sets it in memory.
*nBytes = is->Read(p, size);
if (*nBytes == 0) return is->GetErrorValue();
return 0;
}
virtual void* GetWorkBuffer(size_t* n) {
// Registers the required working memory.
// The InputStream base class, the input stream that the user takes values from, of
// InputConverterStream should take data from this working memory.
*n = 128;
return buf_;
}
virtual errno_t OnSetStream(InputStream* is) {
// This codes the process when the stream has been configured.
return 0;
}
virtual errno_t OnClose() {
// Post-processing when the stream is closed.
return 0;
}
Private:
unsigned char buf_[128]; //
NLIB_DISALLOW_COPY_AND_ASSIGN(NoInputTransform);
};
//
typedef InputConverterStreamTempl<NoInputTransform> NoConvertInputStream;

Definition at line 35 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 40 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: