OpenEnroth d1a3925
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
FileOutputStream Class Reference

#include <FileOutputStream.h>

Inheritance diagram for FileOutputStream:
OutputStream

Public Member Functions

 FileOutputStream ()=default
 
 FileOutputStream (std::string_view path, size_t bufferSize=DEFAULT_BUFFER_SIZE)
 
virtual ~FileOutputStream ()
 
void open (std::string_view path, size_t bufferSize=DEFAULT_BUFFER_SIZE)
 
- Public Member Functions inherited from OutputStream
virtual ~OutputStream ()
 
void write (const void *data, size_t size)
 
void write (std::string_view s)
 
void write (const Blob &blob)
 
void flush ()
 
void close ()
 
bool isOpen () const
 
size_t position () const
 
size_t size () const
 
const std::string & displayPath () const
 

Static Public Attributes

static constexpr size_t DEFAULT_BUFFER_SIZE = 1024 * 1024
 

Private Types

using base_type = OutputStream
 

Private Member Functions

virtual void _overflow (Buffer *buffer, const void *data, size_t size) override
 
virtual void _flush (Buffer *buffer) override
 
virtual void _close (Buffer *buffer, bool canThrow) override
 
void writeBuffer (const Buffer &buffer, bool canThrow)
 

Private Attributes

FILE * _file = nullptr
 
std::unique_ptr< char[]> _buf
 
size_t _bufSize = 0
 

Additional Inherited Members

- Public Types inherited from OutputStream
using Buffer = StreamBuffer< char >
 
- Protected Member Functions inherited from OutputStream
 OutputStream ()=default
 
void open (Buffer buffer, std::string_view displayPath)
 
virtual void _overflow (Buffer *buffer, const void *data, size_t size)=0
 
virtual void _flush (Buffer *buffer)=0
 
virtual void _close (Buffer *buffer, bool canThrow)=0
 
void destroy () noexcept
 

Detailed Description

Output stream that writes to a file.

Member Typedef Documentation

◆ base_type

Constructor & Destructor Documentation

◆ FileOutputStream() [1/2]

FileOutputStream::FileOutputStream ( )
default

◆ FileOutputStream() [2/2]

FileOutputStream::FileOutputStream ( std::string_view  path,
size_t  bufferSize = DEFAULT_BUFFER_SIZE 
)
explicit
Parameters
pathPath to the file to open.
bufferSizeSize of the internal write buffer.
Exceptions
ExceptionOn error.

◆ ~FileOutputStream()

FileOutputStream::~FileOutputStream ( )
virtual

Member Function Documentation

◆ _close()

void FileOutputStream::_close ( Buffer buffer,
bool  canThrow 
)
overrideprivatevirtual

Flushes any remaining buffered data and releases held resources.

Derived implementations should call OutputStream::_close() at the end.

Parameters
[in,out]bufferCurrent buffer state.
canThrowWhether the implementation is allowed to throw. When called from a destructor via destroy(), this is false and the implementation should do best-effort cleanup without throwing.
Exceptions
ExceptionOn error, only if canThrow is true.

Implements OutputStream.

◆ _flush()

void FileOutputStream::_flush ( Buffer buffer)
overrideprivatevirtual

Flushes buffered data to the underlying target.

Parameters
[in,out]bufferCurrent buffer state.
Exceptions
ExceptionOn error.

Implements OutputStream.

◆ _overflow()

void FileOutputStream::_overflow ( Buffer buffer,
const void *  data,
size_t  size 
)
overrideprivatevirtual

Called when a write doesn't fit in the current buffer. Implementations should handle the overflow data (write it out or store it), and provide a new writable buffer via the out parameter.

Parameters
[in,out]bufferCurrent buffer state on input. Set to the new buffer state on output. Data in [buffer->start, buffer->pos) is treated as dirty (not yet flushed).
dataPointer to the overflow data to write.
sizeSize of the overflow data, always greater than buffer->remaining().
Exceptions
ExceptionOn error.

Implements OutputStream.

◆ open()

void FileOutputStream::open ( std::string_view  path,
size_t  bufferSize = DEFAULT_BUFFER_SIZE 
)

Opens a file for writing.

Parameters
pathPath to the file to open.
bufferSizeSize of the internal write buffer.
Exceptions
ExceptionOn error.

◆ writeBuffer()

void FileOutputStream::writeBuffer ( const Buffer buffer,
bool  canThrow 
)
private

Member Data Documentation

◆ _buf

std::unique_ptr<char[]> FileOutputStream::_buf
private

◆ _bufSize

size_t FileOutputStream::_bufSize = 0
private

◆ _file

FILE* FileOutputStream::_file = nullptr
private

◆ DEFAULT_BUFFER_SIZE

constexpr size_t FileOutputStream::DEFAULT_BUFFER_SIZE = 1024 * 1024
staticconstexpr

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