Interface class for files. More...
#include <kanzi/core/file/file.hpp>
Public Types | |
enum | SeekPosition { SeekBegin, SeekCurrent } |
Seek origin enumeration for seek(). More... | |
Public Member Functions | |
virtual const byte * | map ()=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 () | |
Interface class for files.
Use this interface to hide differences between file implementations.
Seek origin enumeration for seek().
Enumerator | |
---|---|
SeekBegin | Seek from start of file. |
SeekCurrent | Seek from current file position. |
|
inlinevirtual |
Destructor.
|
inlineexplicitprotected |
|
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.
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. |
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.
|
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().
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. |
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.
|
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().
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. |
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.
|
pure virtual |
Gets the size of a file.
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.
|
pure virtual |
Gets the current position in a file.
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.
|
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().
position | Seek origin. |
offset | Offset in bytes from the seek origin. |
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.
|
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().
Implemented in kanzi::ReadOnlyDiskFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyMemoryFile.