Kanzi  3.9.9
Kanzi Engine C++ API
kanzi::File Class Referenceabstract

Interface class for files. More...

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

Inheritance diagram for kanzi::File:
[legend]

Public Types

enum  SeekPosition { SeekBegin, SeekCurrent }
 Seek origin enumeration for seek(). More...
 

Public Member Functions

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

Protected Member Functions

 File ()
 

Detailed Description

Interface class for files.

Use this interface to hide differences between file implementations.

See also
ReadOnlyDiskFile, ReadOnlyMemoryFile.

Member Enumeration Documentation

Seek origin enumeration for seek().

Enumerator
SeekBegin 

Seek from start of file.

SeekCurrent 

Seek from current file position.

Constructor & Destructor Documentation

virtual kanzi::File::~File ( )
inlinevirtual

Destructor.

kanzi::File::File ( )
inlineexplicitprotected

Member Function Documentation

virtual void kanzi::File::read ( char *  buffer,
uintmax_t  count 
)
pure virtual

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

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.

virtual KZ_NO_DISCARD uintmax_t kanzi::File::tryRead ( char *  buffer,
uintmax_t  count 
)
pure virtual

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.

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.

virtual void kanzi::File::write ( const char *  buffer,
uintmax_t  count 
)
pure virtual

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

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.

virtual uintmax_t kanzi::File::size ( ) const
pure virtual

Gets the size of a file.

Returns
Returns the size of a file in bytes.

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.

virtual uintmax_t kanzi::File::tell ( ) const
pure virtual

Gets the current position in a file.

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

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.

virtual void kanzi::File::seek ( SeekPosition  position,
intmax_t  offset 
)
pure virtual

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

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.

virtual const byte* kanzi::File::map ( )
pure virtual

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

Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.


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