RAVENNAKIT
Loading...
Searching...
No Matches
rav::FileOutputStream Class Referencefinal

An implementation of output_stream for writing to a file. More...

#include <file_output_stream.hpp>

Inheritance diagram for rav::FileOutputStream:
rav::OutputStream

Public Member Functions

 FileOutputStream (const std::filesystem::path &file)
 ~FileOutputStream () override=default
tl::expected< void, Error > write (const uint8_t *buffer, const size_t size) override
 Writes data from the given buffer to the stream.
tl::expected< void, Error > set_write_position (const size_t position) override
 Sets the write position in the stream.
size_t get_write_position () override
void flush () override
 Flushes the stream, ensuring that all data is written to the underlying storage.
Public Member Functions inherited from rav::OutputStream
 OutputStream ()=default
virtual ~OutputStream ()=default
tl::expected< void, Error > write (const char *buffer, const size_t size)
 Convenience function to write data from a char buffer to the stream.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< void, Error > write_ne (const Type value)
 Writes a value to the stream in native byte order (not to be confused with network-endian).
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< void, Error > write_be (const Type value)
 Writes a big-endian value to the stream.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< void, Error > write_le (const Type value)
 Writes a little-endian value to the stream.
tl::expected< void, Error > write_string (const std::string &str)
 Writes a string to the stream.
tl::expected< void, Error > write_cstring (const char *str)
 Writes a c-string to the stream, up to and including the null character.

Additional Inherited Members

Public Types inherited from rav::OutputStream
enum class  Error { failed_to_write , out_of_memory }

Detailed Description

An implementation of output_stream for writing to a file.

Definition at line 35 of file file_output_stream.hpp.

Constructor & Destructor Documentation

◆ FileOutputStream()

rav::FileOutputStream::FileOutputStream ( const std::filesystem::path & file)
inlineexplicit

Definition at line 37 of file file_output_stream.hpp.

◆ ~FileOutputStream()

rav::FileOutputStream::~FileOutputStream ( )
overridedefault

Member Function Documentation

◆ flush()

void rav::FileOutputStream::flush ( )
inlineoverridevirtual

Flushes the stream, ensuring that all data is written to the underlying storage.

Not all streams support this operation.

Implements rav::OutputStream.

Definition at line 63 of file file_output_stream.hpp.

◆ get_write_position()

size_t rav::FileOutputStream::get_write_position ( )
inlinenodiscardoverridevirtual
Returns
The current write position in the stream.

Implements rav::OutputStream.

Definition at line 59 of file file_output_stream.hpp.

◆ set_write_position()

tl::expected< void, Error > rav::FileOutputStream::set_write_position ( const size_t position)
inlineoverridevirtual

Sets the write position in the stream.

Parameters
positionThe new write position.
Returns
True if the write position was successfully set.

Implements rav::OutputStream.

Definition at line 54 of file file_output_stream.hpp.

◆ write()

tl::expected< void, Error > rav::FileOutputStream::write ( const uint8_t * buffer,
const size_t size )
inlineoverridevirtual

Writes data from the given buffer to the stream.

Parameters
bufferThe buffer to write data from.
sizeThe number of bytes to write.
Returns
An expected indicating success or failure.

Implements rav::OutputStream.

Definition at line 49 of file file_output_stream.hpp.


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