The ReadOnlyMemoryFile class provides a (read-only) file interface to a block of memory.
More...
#include <kanzi/core/file/read_only_memory_file.hpp>
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.
◆ ReadOnlyMemoryFile()
kanzi::ReadOnlyMemoryFile::ReadOnlyMemoryFile |
( |
const byte * |
buffer, |
|
|
uintmax_t |
size |
|
) |
| |
|
inlineexplicit |
◆ ~ReadOnlyMemoryFile()
kanzi::ReadOnlyMemoryFile::~ReadOnlyMemoryFile |
( |
| ) |
|
|
overridedefault |
◆ read()
void kanzi::ReadOnlyMemoryFile::read |
( |
char * |
buffer, |
|
|
uintmax_t |
count |
|
) |
| |
|
overridevirtual |
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.
- Parameters
-
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. |
- See also
- write(), tell(), and map().
Implements kanzi::File.
◆ tryRead()
KZ_NO_DISCARD uintmax_t kanzi::ReadOnlyMemoryFile::tryRead |
( |
char * |
buffer, |
|
|
uintmax_t |
count |
|
) |
| |
|
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().
- Parameters
-
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. |
- See also
- write(), tell(), and map().
- Returns
- Returns the number of bytes read.
Implements kanzi::File.
◆ write()
void kanzi::ReadOnlyMemoryFile::write |
( |
const char * |
buffer, |
|
|
uintmax_t |
count |
|
) |
| |
|
overridevirtual |
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().
- Parameters
-
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. |
- See also
- read(), tell(), and map().
Implements kanzi::File.
◆ size()
uintmax_t kanzi::ReadOnlyMemoryFile::size |
( |
| ) |
const |
|
overridevirtual |
Gets the size of a file.
- Returns
- Returns the size of a file in bytes.
Implements kanzi::File.
◆ tell()
uintmax_t kanzi::ReadOnlyMemoryFile::tell |
( |
| ) |
const |
|
overridevirtual |
◆ seek()
void kanzi::ReadOnlyMemoryFile::seek |
( |
SeekPosition |
position, |
|
|
intmax_t |
offset |
|
) |
| |
|
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().
- Parameters
-
position | Seek origin. |
offset | Offset in bytes from the seek origin. |
- See also
- SeekPosition and tell().
Implements kanzi::File.
◆ map()
const byte* kanzi::ReadOnlyMemoryFile::map |
( |
| ) |
|
|
overridevirtual |
The documentation for this class was generated from the following file: