nlib
nn::nlib::MemoryInputStream Class Referencefinal

The class for creating an input stream that makes use of memory. More...

#include "nn/nlib/MemoryInputStream.h"

+ Inheritance diagram for nn::nlib::MemoryInputStream:

Public Member Functions

template<class T , size_t N>
void Init (const T(&buf)[N]) noexcept
 Initializes MemoryInputStream and makes it available for use. More...
 
void Init (const void *buf, size_t n) noexcept
 Initializes MemoryInputStream and makes it available for use. More...
 
Basic Member Functions
 MemoryInputStream () noexcept
 Instantiates the object with default parameters (default constructor). You must call the Init function before using this function.
 
virtual ~MemoryInputStream () noexcept override
 Destructor.
 
template<class T , size_t N>
 MemoryInputStream (const T(&buf)[N]) noexcept
 Constructs and initializes MemoryInputStream. More...
 
 MemoryInputStream (const void *buf, size_t n) noexcept
 Constructs and initializes MemoryInputStream. More...
 
- Public Member Functions inherited from nn::nlib::InputStream
bool IsOk () const noexcept
 Checks that no error has occurred. More...
 
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 class for creating an input stream that makes use of memory.

Description
A memory region is allocated as a backing store by the user at initialization.
The following sample code shows how to construct MemoryInputStream.
using nexi::MemoryInputStream;
unsigned char buf[SIZE];
// Use code like the following to construct a memory stream using buf.
MemoryInputStream is1(&buf[0], SIZE);
is3.Init(&buf[0], SIZE);
is4.Init(buf);
Examples:
exi/multithread/multithread.cpp, exi/script/script.cpp, exi/serializer/serializer.cpp, exi/simple1/simple1.cpp, exi/simple2/simple2.cpp, exi/textparser/textparser.cpp, misc/stringutils/stringutils.cpp, misc/usezlib/usezlib.cpp, msgpack/msgpack2/msgpack2.cpp, and msgpack/usertype/usertype.cpp.

Definition at line 10 of file MemoryInputStream.h.

Constructor & Destructor Documentation

template<class T , size_t N>
nn::nlib::MemoryInputStream::MemoryInputStream ( const T(&)  buf[N])
inlineexplicitnoexcept

Constructs and initializes MemoryInputStream.

Parameters
[in]bufThe array that is referenced from the stream.

Definition at line 15 of file MemoryInputStream.h.

nn::nlib::MemoryInputStream::MemoryInputStream ( const void *  buf,
size_t  n 
)
noexcept

Constructs and initializes MemoryInputStream.

Parameters
[in]bufA pointer to a memory region.
[in]nThe size of the memory region.

Member Function Documentation

template<class T , size_t N>
nn::nlib::MemoryInputStream::Init ( const T(&)  buf[N])
inlinenoexcept

Initializes MemoryInputStream and makes it available for use.

Parameters
[in]bufThe array that is referenced from the stream.
Description
Initializes MemoryInputStream, specifying an array.

Definition at line 19 of file MemoryInputStream.h.

nn::nlib::MemoryInputStream::Init ( const void *  buf,
size_t  n 
)
noexcept

Initializes MemoryInputStream and makes it available for use.

Parameters
[in]bufA pointer to a memory region.
[in]nThe size of the memory region.
Description
Initializes MemoryInputStream with a pointer to a memory region and its size specified.

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