Kanzi  3.9.8
Kanzi Engine C++ API
kanzi::ReadOnlyDiskFile Class Reference

Implements the File interface for files residing on a disk. More...

#include <kanzi/core/platform/file/win32/read_only_disk_file.hpp>

Inheritance diagram for kanzi::ReadOnlyDiskFile:
[legend]

Public Member Functions

const bytemap () override
 
const bytemap () override
 Creates a memory mapping of the disk file. More...
 
const bytemap () override
 Creates a memory mapping of the disk file. More...
 
const bytemap () override
 Creates a memory mapping of the disk file. More...
 
void read (char *buffer, uintmax_t count) override
 Reads data from a file. More...
 
void read (char *buffer, uintmax_t count) override
 Reads data from a file. More...
 
void read (char *buffer, uintmax_t count) override
 Reads data from a file. More...
 
void read (char *buffer, uintmax_t count) override
 Reads data from a file. More...
 
 ReadOnlyDiskFile (string_view filename)
 Constructor. More...
 
 ReadOnlyDiskFile (string_view filename)
 Constructor. More...
 
 ReadOnlyDiskFile (string_view filename)
 Constructor. More...
 
 ReadOnlyDiskFile (string_view filename)
 Constructor. More...
 
 ReadOnlyDiskFile (const char *filename)
 Constructor. More...
 
void seek (SeekPosition position, intmax_t offset) override
 Sets the position in a file. More...
 
void seek (SeekPosition position, intmax_t offset) override
 Sets the position in a file. More...
 
void seek (SeekPosition position, intmax_t offset) override
 Sets the position in a file. More...
 
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 size () const override
 Gets the size of a file. More...
 
uintmax_t size () const override
 Gets the size of 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...
 
uintmax_t tell () const override
 Gets the current position in a file. More...
 
uintmax_t tell () const override
 Gets the current position in 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...
 
KZ_NO_DISCARD uintmax_t tryRead (char *buffer, uintmax_t count) override
 Tries to reads data from a file. More...
 
KZ_NO_DISCARD uintmax_t tryRead (char *buffer, uintmax_t count) override
 Tries to reads data from 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 *buffer, uintmax_t count) override
 Writes data to a file. More...
 
void write (const char *buffer, uintmax_t count) override
 Writes data to a file. More...
 
void write (const char *buffer, uintmax_t count) override
 Writes data to a file. More...
 
void write (const char *buffer, uintmax_t count) override
 Writes data to a file. More...
 
 ~ReadOnlyDiskFile () override
 Destructor. More...
 
 ~ReadOnlyDiskFile () override
 Destructor. More...
 
 ~ReadOnlyDiskFile () override
 
 ~ReadOnlyDiskFile () override
 Destructor. More...
 
- Public Member Functions inherited from kanzi::File
virtual ~File ()
 Destructor. More...
 

Static Public Member Functions

static ReadOnlyDiskFileUniquePtr tryOpen (string_view filename)
 Factory function. More...
 
static ReadOnlyDiskFileUniquePtr tryOpen (string_view filename)
 Factory function. More...
 
static ReadOnlyDiskFileUniquePtr tryOpen (string_view filename)
 Factory function. More...
 
static ReadOnlyDiskFileUniquePtr tryOpen (string_view filename)
 Factory function. More...
 

Protected Member Functions

 ReadOnlyDiskFile (KzsResourceFile *resourceFile)
 Constructor. More...
 
 ReadOnlyDiskFile (int fileDescriptor)
 Constructor. More...
 
 ReadOnlyDiskFile (int fileDescriptor)
 Constructor. More...
 
 ReadOnlyDiskFile (HANDLE fileHandle)
 Constructor. More...
 
- Protected Member Functions inherited from kanzi::File
 File ()
 

Protected Attributes

vector< char > m_data
 Buffer for reading file contents if memory-mapping is not supported. More...
 
int m_fileDescriptor
 Opaque handle to the disk file. More...
 
HANDLE m_fileHandle
 Opaque handle to the disk file. More...
 
bytem_map
 Pointer to memory map. More...
 
HANDLE m_mapHandle
 Opaque handle to the memory map of the disk file. More...
 
voidm_mapView
 Pointer to the memory map of the disk file. More...
 
KzsResourceFilem_resourceFile
 Opaque handle to the disk file. More...
 

Additional Inherited Members

- Public Types inherited from kanzi::File
enum  SeekPosition { SeekBegin, SeekCurrent }
 Seek origin enumeration for seek(). More...
 

Detailed Description

Implements the File interface for files residing on a disk.

Constructor & Destructor Documentation

kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( string_view  filename)
explicit

Constructor.

Parameters
filenameThe name (including path) of the disk file to handle. Throws runtime_error if file cannot be accessed.
kanzi::ReadOnlyDiskFile::~ReadOnlyDiskFile ( )
override
kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( KzsResourceFile resourceFile)
explicitprotected

Constructor.

Parameters
resourceFileA pointer to an open resource file.
kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( string_view  filename)
explicit

Constructor.

Parameters
filenameThe name (including path) of the disk file to handle. Throws runtime_error if file cannot be accessed.
kanzi::ReadOnlyDiskFile::~ReadOnlyDiskFile ( )
override

Destructor.

Closes the file handle.

kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( int  fileDescriptor)
explicitprotected

Constructor.

Parameters
fileDescriptorAn open disk file descriptor.
kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( string_view  filename)
explicit

Constructor.

Parameters
filenameThe name (including path) of the disk file to handle. Throws runtime_error if file cannot be accessed.
kanzi::ReadOnlyDiskFile::~ReadOnlyDiskFile ( )
override

Destructor.

Closes the file handle.

kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( int  fileDescriptor)
explicitprotected

Constructor.

Parameters
fileDescriptorAn open disk file descriptor.
kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( string_view  filename)
explicit

Constructor.

Parameters
filenameThe name (including path) of the disk file to handle. Throws runtime_error if file cannot be accessed.
kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( const char *  filename)
explicit

Constructor.

Parameters
filenameThe name (including path) of the disk file to handle. Throws runtime_error if file cannot be accessed.
kanzi::ReadOnlyDiskFile::~ReadOnlyDiskFile ( )
override

Destructor.

Closes the file handle and unmaps the file as needed.

kanzi::ReadOnlyDiskFile::ReadOnlyDiskFile ( HANDLE  fileHandle)
explicitprotected

Constructor.

Parameters
fileHandleAn open disk file handle.

Member Function Documentation

static ReadOnlyDiskFileUniquePtr kanzi::ReadOnlyDiskFile::tryOpen ( string_view  filename)
static

Factory function.

Creates an object representing an open file handle to a disk file.

Parameters
filenameThe name (including path) of the disk file to handle.
Returns
Pointer to the object, or null when file cannot be accessed.
void kanzi::ReadOnlyDiskFile::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.

KZ_NO_DISCARD uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

uintmax_t kanzi::ReadOnlyDiskFile::size ( ) const
overridevirtual

Gets the size of a file.

Returns
Returns the size of a file in bytes.

Implements kanzi::File.

uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

const byte* kanzi::ReadOnlyDiskFile::map ( )
overridevirtual
Note
Some memory mapping operations on Android are limited to 32 bit.

Implements kanzi::File.

static ReadOnlyDiskFileUniquePtr kanzi::ReadOnlyDiskFile::tryOpen ( string_view  filename)
static

Factory function.

Creates an object representing an open file handle to a disk file.

Parameters
filenameThe name (including path) of the disk file to handle.
Returns
Pointer to the object, or null when file cannot be accessed.
void kanzi::ReadOnlyDiskFile::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.

KZ_NO_DISCARD uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

uintmax_t kanzi::ReadOnlyDiskFile::size ( ) const
overridevirtual

Gets the size of a file.

Returns
Returns the size of a file in bytes.

Implements kanzi::File.

uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

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

Creates a memory mapping of the disk file.

Does nothing if the disk file has already been memory mapped.

Returns
Pointer to the view of the memory map.

Implements kanzi::File.

static ReadOnlyDiskFileUniquePtr kanzi::ReadOnlyDiskFile::tryOpen ( string_view  filename)
static

Factory function.

Creates an object representing an open file handle to a disk file.

Parameters
filenameThe name (including path) of the disk file to handle.
Returns
Pointer to the object, or null when file cannot be accessed.
void kanzi::ReadOnlyDiskFile::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.

KZ_NO_DISCARD uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

uintmax_t kanzi::ReadOnlyDiskFile::size ( ) const
overridevirtual

Gets the size of a file.

Returns
Returns the size of a file in bytes.

Implements kanzi::File.

uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

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

Creates a memory mapping of the disk file.

Does nothing if the disk file has already been memory mapped.

Returns
Pointer to the view of the memory map.

Implements kanzi::File.

static ReadOnlyDiskFileUniquePtr kanzi::ReadOnlyDiskFile::tryOpen ( string_view  filename)
static

Factory function.

Creates an object representing an open file handle to a disk file.

Parameters
filenameThe name (including path) of the disk file to handle.
Returns
Pointer to the object, or null when file cannot be accessed.
void kanzi::ReadOnlyDiskFile::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.

KZ_NO_DISCARD uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

uintmax_t kanzi::ReadOnlyDiskFile::size ( ) const
overridevirtual

Gets the size of a file.

Returns
Returns the size of a file in bytes.

Implements kanzi::File.

uintmax_t kanzi::ReadOnlyDiskFile::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.

void kanzi::ReadOnlyDiskFile::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.

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

Creates a memory mapping of the disk file.

Does nothing if the disk file has already been memory mapped.

Returns
Pointer to the view of the memory map.

Implements kanzi::File.

Member Data Documentation

KzsResourceFile* kanzi::ReadOnlyDiskFile::m_resourceFile
protected

Opaque handle to the disk file.

byte* kanzi::ReadOnlyDiskFile::m_map
protected

Pointer to memory map.

int kanzi::ReadOnlyDiskFile::m_fileDescriptor
protected

Opaque handle to the disk file.

void * kanzi::ReadOnlyDiskFile::m_mapView
protected

Pointer to the memory map of the disk file.

Pointer to the view of the memory map of the disk file.

vector<char> kanzi::ReadOnlyDiskFile::m_data
protected

Buffer for reading file contents if memory-mapping is not supported.

HANDLE kanzi::ReadOnlyDiskFile::m_fileHandle
protected

Opaque handle to the disk file.

HANDLE kanzi::ReadOnlyDiskFile::m_mapHandle
protected

Opaque handle to the memory map of the disk file.


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