Kanzi  3.9.4
Kanzi Engine API
kanzi::ReadOnlyMemoryFile Class Reference

The ReadOnlyMemoryFile class provides a (read-only) file interface to a block of memory. More...

#include <kanzi/core/file/read_only_memory_file.hpp>

Inheritance diagram for kanzi::ReadOnlyMemoryFile:
[legend]

Public Member Functions

const bytemap () override
 Maps the contents of a file to the process memory. More...
 
void read (char *buffer, uintmax_t count) override
 Reads data from a file. More...
 
 ReadOnlyMemoryFile (const byte *buffer, uintmax_t size)
 
void seek (SeekPosition position, intmax_t offset) override
 Sets the position in a file. More...
 
uintmax_t size () const override
 Gets the size of a file. More...
 
uintmax_t tell () const override
 Gets the current position in a file. More...
 
KZ_NO_DISCARD uintmax_t tryRead (char *buffer, uintmax_t count) override
 Tries to reads data from a file. More...
 
void write (const char *, uintmax_t) override
 Writes data to a file. More...
 
 ~ReadOnlyMemoryFile () override=default
 
- Public Member Functions inherited from kanzi::File
virtual ~File ()
 Destructor. More...
 

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 ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ReadOnlyMemoryFile()

kanzi::ReadOnlyMemoryFile::ReadOnlyMemoryFile ( const byte buffer,
uintmax_t  size 
)
inlineexplicit

◆ ~ReadOnlyMemoryFile()

kanzi::ReadOnlyMemoryFile::~ReadOnlyMemoryFile ( )
overridedefault

Member Function Documentation

◆ 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
bufferBuffer 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.
countNumber 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
bufferBuffer 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.
countNumber 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
bufferBuffer 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.
countNumber 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

Gets the current position in a file.

Returns
Returns the position in a file in bytes.
See also
seek(), read(), and write().

Implements kanzi::File.

◆ 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
positionSeek origin.
offsetOffset in bytes from the seek origin.
See also
SeekPosition and tell().

Implements kanzi::File.

◆ map()

const byte* kanzi::ReadOnlyMemoryFile::map ( )
overridevirtual

Maps the contents of a file to the process memory.

When you call read(), write(), or seek(), these functions invalidate the pointer returned by map().

Returns
Returns the pointer to the beginning of a file.
See also
read(), write(), and seek().

Implements kanzi::File.


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