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

An implementation of input_stream for reading from a file. More...

#include <file_input_stream.hpp>

Inheritance diagram for rav::FileInputStream:
rav::InputStream

Public Member Functions

 FileInputStream (const std::filesystem::path &f)
tl::expected< size_t, Error > read (uint8_t *buffer, const size_t size) override
 Reads data from the stream into the given buffer.
bool set_read_position (const size_t position) override
 Sets the read position in the stream.
size_t get_read_position () override
std::optional< size_t > size () const override
bool exhausted () override
Public Member Functions inherited from rav::InputStream
 InputStream ()=default
virtual ~InputStream ()=default
std::optional< size_t > remaining ()
bool skip (size_t size)
 Skips size amount of bytes in the stream.
tl::expected< std::string, Error > read_as_string (size_t size)
 Reads size amount of bytes from the stream and returns it as a string.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > read_ne ()
 Reads a value from the given 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< Type, Error > read_be ()
 Reads a big-endian value from the given stream.
template<typename Type, std::enable_if_t< std::is_trivially_copyable_v< Type >, bool > = true>
tl::expected< Type, Error > read_le ()
 Reads a little-endian value from the given stream.

Additional Inherited Members

Public Types inherited from rav::InputStream
enum class  Error { insufficient_data , failed_to_set_read_position }
Static Public Member Functions inherited from rav::InputStream
static const char * to_string (const Error e)

Detailed Description

An implementation of input_stream for reading from a file.

Definition at line 36 of file file_input_stream.hpp.

Constructor & Destructor Documentation

◆ FileInputStream()

rav::FileInputStream::FileInputStream ( const std::filesystem::path & f)
inlineexplicit

Definition at line 38 of file file_input_stream.hpp.

Member Function Documentation

◆ exhausted()

bool rav::FileInputStream::exhausted ( )
inlinenodiscardoverridevirtual
Returns
True if the stream has no more data to read.

Implements rav::InputStream.

Definition at line 89 of file file_input_stream.hpp.

◆ get_read_position()

size_t rav::FileInputStream::get_read_position ( )
inlinenodiscardoverridevirtual
Returns
The current read position in the stream.

Implements rav::InputStream.

Definition at line 77 of file file_input_stream.hpp.

◆ read()

tl::expected< size_t, Error > rav::FileInputStream::read ( uint8_t * buffer,
const size_t size )
inlinenodiscardoverridevirtual

Reads data from the stream into the given buffer.

If the stream doesn't have enough data, then nothing will be read.

Parameters
bufferThe buffer to read data into.
sizeThe number of bytes to read.
Returns
The number of bytes read.

Implements rav::InputStream.

Definition at line 56 of file file_input_stream.hpp.

◆ set_read_position()

bool rav::FileInputStream::set_read_position ( const size_t position)
inlineoverridevirtual

Sets the read position in the stream.

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

Implements rav::InputStream.

Definition at line 72 of file file_input_stream.hpp.

◆ size()

std::optional< size_t > rav::FileInputStream::size ( ) const
inlinenodiscardoverridevirtual
Returns
The total number of bytes in this stream. Not all streams support this operation, in which case an empty optional is returned.

Implements rav::InputStream.

Definition at line 85 of file file_input_stream.hpp.


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