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 Open (const char *filename, int flags, int mode) noexcept
 Opens the file in write mode. More...
 
errno_t Open (const char *filename, int flags) noexcept
 A parameter omitted version of the above function. Assigns 0644 to mode.
 
errno_t Open (const char *filename) noexcept
 A parameter omitted version of the above function. Assigns NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC to flags.
 
errno_t Open (const wchar_t *filename, int flags, int mode) noexcept
 Opens the file in write mode. More...
 
errno_t Open (const wchar_t *filename, int flags) noexcept
 A parameter omitted version of the above function. Assigns 0644 to mode.
 
errno_t Open (const wchar_t *filename) noexcept
 A parameter omitted version of the above function. Assigns NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC to flags.
 
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...
 
Constructor, Destructor, and Initialization
constexpr FileOutputStream () noexcept
 Instantiates the object with default parameters (default constructor). Requires initialization with Init() after execution.
 
virtual ~FileOutputStream () noexcept final override
 Destructor. Closes the file if it is open.
 
errno_t Init (const FileOutputStreamSettings &settings) noexcept
 Initializes by specifying the behavior option. Returns 0 if successful. More...
 
errno_t Init () noexcept
 A parameter omitted version of the above function which passes settings as the default value.
 
- 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 the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside.
 
constexpr OutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
virtual ~OutputStream () noexcept
 Destructor.
 

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 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

Definition at line 34 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 63 of file FileOutputStream.h.

◆ Init()

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

Initializes by specifying the behavior option. Returns 0 if successful.

Parameters
[in]settingsBehavior options.
Return values
0Success.
EALREADYAlready initialized.
ENOMEMIndicates that internal memory allocation failed.
EINVALIndicates that the specification of behavior options was invalid.

◆ 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: