nlib
nn::nlib::MemoryOutputStream Class Referencefinal

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

#include "nn/nlib/MemoryOutputStream.h"

+ Inheritance diagram for nn::nlib::MemoryOutputStream:

Public Member Functions

const void * data () const noexcept
 Gets a pointer to the start of the output data. More...
 
void Init (void *buf, size_t n) noexcept
 Initializes MemoryOuputStream and makes it available for use. More...
 
template<class T , size_t N>
void Init (T(&buf)[N]) noexcept
 Initializes MemoryOuputStream and makes it available for use. More...
 
Basic Member Functions
 MemoryOutputStream () noexcept
 Instantiates the object with default parameters (default constructor). You must call the Init function before using this function.
 
 MemoryOutputStream (void *buf, size_t n) noexcept
 Constructs and initializes MemoryOutputStream. More...
 
template<class T , size_t N>
 MemoryOutputStream (T(&buf)[N]) noexcept
 Constructs and initializes MemoryOutputStream. More...
 
virtual ~MemoryOutputStream () noexcept override
 Destructor.
 
- 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...
 
bool IsOk () const noexcept
 Checks that no error has occurred. More...
 
BufferingMode GetBufferingMode () const noexcept
 Gets the buffering mode.
 
 operator bool () const
 Returns true if no internal error has occurred.
 
constexpr OutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
virtual ~OutputStream () noexcept
 Destructor. Does not do anything.
 

Additional Inherited Members

- Public Types inherited from nn::nlib::OutputStream
enum  BufferingMode {
  BUFFERINGMODE_BLOCKBUFFERED = 0,
  BUFFERINGMODE_LINEBUFFERED,
  BUFFERINGMODE_UNBUFFERED
}
 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 class for creating an output 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 MemoryOutputStream.
using nexi::MemoryOutputStream;
unsigned char buf[SIZE];
MemoryOutputStream os1(&buf[0], SIZE);
os3.Init(&buf[0], SIZE);
os4.Init(buf);
Examples:
exi/script/script.cpp, exi/simple1/simple1.cpp, exi/simple2/simple2.cpp, and misc/stringutils/stringutils.cpp.

Definition at line 10 of file MemoryOutputStream.h.

Constructor & Destructor Documentation

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

Constructs and initializes MemoryOutputStream.

Parameters
[out]bufA pointer to a memory region.
[in]nThe size of the memory region.
template<class T , size_t N>
nn::nlib::MemoryOutputStream::MemoryOutputStream ( T(&)  buf[N])
inlineexplicitnoexcept

Constructs and initializes MemoryOutputStream.

Parameters
[out]bufThe array to use as the output buffer.

Definition at line 15 of file MemoryOutputStream.h.

Member Function Documentation

nn::nlib::MemoryOutputStream::data ( ) const
inlinenoexcept

Gets a pointer to the start of the output data.

Returns
The pointer to the start of the output buffer.

Definition at line 20 of file MemoryOutputStream.h.

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

Initializes MemoryOuputStream and makes it available for use.

Parameters
[out]bufA pointer to a memory region.
[in]nThe size of the memory region.
template<class T , size_t N>
nn::nlib::MemoryOutputStream::Init ( T(&)  buf[N])
inlinenoexcept

Initializes MemoryOuputStream and makes it available for use.

Parameters
[out]bufThe array that is the backing store.

Definition at line 23 of file MemoryOutputStream.h.


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