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. | |
virtual void | read (char *buffer, uintmax_t count)=0 |
Reads data from a file. | |
virtual void | seek (SeekPosition position, intmax_t offset)=0 |
Sets the position in a file. | |
virtual uintmax_t | size () const =0 |
Gets the size of a file. | |
virtual uintmax_t | tell () const =0 |
Gets the current position in a file. | |
virtual KZ_NO_DISCARD uintmax_t | tryRead (char *buffer, uintmax_t count)=0 |
Tries to reads data from a file. | |
virtual void | write (const char *buffer, uintmax_t count)=0 |
Writes data to a file. | |
virtual | ~File () |
Destructor. | |
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 |
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::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.
|
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::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.
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::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.
Gets the size of a file.
Implemented in kanzi::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.
Gets the current position in a file.
Implemented in kanzi::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.
|
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::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.
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::ReadOnlyMemoryFile, kanzi::WriteOnlyDiskFile, and kanzi::ReadOnlyDiskFile.