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...
 
errno_t Init (void *buf, size_t n) noexcept
 Initializes MemoryOuputStream and makes it available for use. More...
 
template<class T , size_t N>
errno_t Init (T(&buf)[N]) noexcept
 Initializes MemoryOuputStream and makes it available for use. More...
 
Basic Member Functions
constexpr MemoryOutputStream () noexcept
 Instantiates the object with default parameters (default constructor). You must call the Init function before using this function.
 
constexpr MemoryOutputStream (void *buf, size_t n) noexcept
 Constructs and initializes MemoryOutputStream. More...
 
template<class T , size_t N>
constexpr 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...
 
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 {
  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 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);
The transition of the object state.
The overview of the object state transitions is described below:
dot_inline_dotgraph_9.png
Examples:
exi/script/script.cpp, exi/simple1/simple1.cpp, exi/simple2/simple2.cpp, misc/stringutils/stringutils.cpp, and msgpack/json/json.cpp.

Definition at line 23 of file MemoryOutputStream.h.

Constructor & Destructor Documentation

◆ MemoryOutputStream() [1/2]

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

Constructs and initializes MemoryOutputStream.

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

Definition at line 26 of file MemoryOutputStream.h.

◆ MemoryOutputStream() [2/2]

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 29 of file MemoryOutputStream.h.

Member Function Documentation

◆ data()

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 34 of file MemoryOutputStream.h.

◆ Init() [1/2]

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

Initializes MemoryOuputStream and makes it available for use.

Parameters
[out]bufA pointer to a memory region.
[in]nThe size of the memory region.
Returns
Returns 0 on success.

Definition at line 36 of file MemoryOutputStream.h.

◆ Init() [2/2]

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.
Returns
Returns 0 on success.

Definition at line 40 of file MemoryOutputStream.h.


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