The ReadOnlyMemoryFile class provides a (read-only) file interface to a block of memory. More...
#include <kanzi/core/file/read_only_memory_file.hpp>
Public Member Functions | |
const byte * | map () override |
Maps the contents of a file to the process memory. | |
void | read (char *buffer, uintmax_t count) override |
Reads data from a file. | |
ReadOnlyMemoryFile (const byte *buffer, uintmax_t size) | |
void | seek (SeekPosition position, intmax_t offset) override |
Sets the position in a file. | |
uintmax_t | size () const override |
Gets the size of a file. | |
uintmax_t | tell () const override |
Gets the current position in a file. | |
KZ_NO_DISCARD uintmax_t | tryRead (char *buffer, uintmax_t count) override |
Tries to reads data from a file. | |
void | write (const char *, uintmax_t) override |
Writes data to a file. | |
~ReadOnlyMemoryFile () override=default | |
Public Member Functions inherited from kanzi::File | |
virtual | ~File () |
Destructor. | |
Additional Inherited Members | |
Public Types inherited from kanzi::File | |
enum | SeekPosition { SeekBegin , SeekCurrent } |
Seek origin enumeration for seek(). More... | |
Protected Member Functions inherited from kanzi::File | |
File () | |
The ReadOnlyMemoryFile class provides a (read-only) file interface to a block of memory.
It is constructed from a size and a pointer to the memory block. You need to make sure that the memory block remains valid while the ReadOnlyMemoryFile is being used.
|
inlineexplicit |
|
overridedefault |
Reads data from a file.
The function starts reading at the current file position. When you call read(), it invalidates the pointer returned by map(). This function throws when its can't read count number of bytes from the File.
buffer | Buffer to which to read. The size of the buffer in bytes must be at least the size of the value you pass in the count parameter. |
count | Number of bytes to read. |
Implements kanzi::File.
|
overridevirtual |
Tries to reads data from a file.
The function starts reading at the current file position. When you call tryRead(), it invalidates the pointer returned by map().
buffer | Buffer to which to read. The size of the buffer in bytes must be at least the size of the value you pass in the count parameter. |
count | Number of bytes to read. |
Implements kanzi::File.
Writes data to a file.
The function starts writing at the current file position. When you call write(), it invalidates the pointer returned by map().
buffer | Buffer from which to write. The size of the buffer in bytes must be at least the size of the value you pass in the count parameter. |
count | Number of bytes to write. |
Implements kanzi::File.
|
overridevirtual |
|
overridevirtual |
Gets the current position in a file.
Implements kanzi::File.
|
overridevirtual |
Sets the position in a file.
You can set the position as an offset to either the current position or the beginning of the file. When you call seek(), it invalidates the pointer returned by map().
position | Seek origin. |
offset | Offset in bytes from the seek origin. |
Implements kanzi::File.