nlib
nn::nlib::FileOutputStream Class Referencefinal

The class for file output streams. More...

#include "nn/nlib/FileOutputStream.h"

+ Inheritance diagram for nn::nlib::FileOutputStream:

Public Member Functions

errno_t Init () noexcept
 Initializes the stream with the default settings. More...
 
NLIB_CHECK_RESULT errno_t Init (const FileOutputStreamSettings &settings) noexcept
 Initializes a stream. More...
 
NLIB_CHECK_RESULT errno_t Open (const char *filename, int flags, int mode) noexcept
 Opens the file in write mode. More...
 
NLIB_CHECK_RESULT errno_t Open (const wchar_t *filename, int flags, int mode) noexcept
 Opens the file in write mode. More...
 
NLIB_CHECK_RESULT errno_t FdOpen (nlib_fd fd) noexcept
 Makes an already-open file available for use by FileOutputStream. More...
 
nlib_fd GetFd () const noexcept
 Returns the file descriptor. More...
 
Basic Member Functions
 FileOutputStream () noexcept
 Instantiates the object with default parameters (default constructor). The buffer must be set and initialized by the Init function ahead of time.
 
virtual ~FileOutputStream () noexcept final override
 Destructor. Closes the file if it is open.
 
- 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 {
  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 file output streams.

Description
Supports only synchronous and sequential access. The class wraps the file API of each environment and has its own buffer.
The transition of the object state.
The overview of the object state transitions is described below:
dot_inline_dotgraph_7.png
Examples:
misc/writefile/writefile.cpp.

Definition at line 21 of file FileOutputStream.h.

Member Function Documentation

§ FdOpen()

nn::nlib::FileOutputStream::FdOpen ( nlib_fd  fd)
noexcept

Makes an already-open file available for use by FileOutputStream.

Parameters
[in]fdAn already-open nlib_fd-type value.
Returns
Returns 0 on success. Any other value indicates an error.
Description
If the Init function was not called ahead of time, it is called internally here.

§ GetFd()

nn::nlib::FileOutputStream::GetFd ( ) const
inlinenoexcept

Returns the file descriptor.

Returns
The file descriptor.

Definition at line 50 of file FileOutputStream.h.

§ Init() [1/2]

nn::nlib::FileOutputStream::Init ( )
inlinenoexcept

Initializes the stream with the default settings.

Returns
Returns 0 on success. Any other value indicates an error.
Description
The buffer that is used internally by the FileOutputStream object is allocated from the heap in the default size.

Definition at line 28 of file FileOutputStream.h.

§ Init() [2/2]

nn::nlib::FileOutputStream::Init ( const FileOutputStreamSettings settings)
noexcept

Initializes a stream.

Parameters
[in]settingsThe default options.
Returns
Returns 0 on success. Any other value indicates an error.
Description
If the only the buffer size has been specified, the buffer is allocated from the heap.

§ Open() [1/2]

nn::nlib::FileOutputStream::Open ( const char *  filename,
int  flags,
int  mode 
)
noexcept

Opens the file in write mode.

Parameters
[in]filenameThe path to the file.
[in]flagsFlags to be passed to nlib_fd_open() for opening files (NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC, if they are omitted).
[in]modeA permission argument to be passed to nlib_fd_open() (0644 if it is omitted).
Returns
Returns 0 on success. Any other value indicates an error.
Description
If the Init function was not called ahead of time, it is called internally here.

§ Open() [2/2]

nn::nlib::FileOutputStream::Open ( const wchar_t *  filename,
int  flags,
int  mode 
)
noexcept

Opens the file in write mode.

Parameters
[in]filenameThe path to the file.
[in]flagsFlags to be passed to nlib_fd_open() for opening files (NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC, if they are omitted).
[in]modeA permission argument to be passed to nlib_fd_open() (0644 if it is omitted).
Returns
Returns 0 on success. Any other value indicates an error.
Description
If the Init function was not called ahead of time, it is called internally here.

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