17 #ifndef FILE_CLASS_EXT_HEADER
18 #define FILE_CLASS_EXT_HEADER
21 #include <a_util/filesystem.h>
22 #include <a_util/datetime.h>
23 #include <a_util/memory.h>
24 #include <system_error>
56 namespace exceptions {
73 EndOfFile(
const std::string& what) : runtime_error(what)
223 void open(const a_util::filesystem::Path& filename, uint32_t mode);
270 size_t read(
void* buffer,
size_t buffer_size);
283 void readAll(
void* buffer,
size_t buffer_size);
295 size_t skip(
size_t number_of_bytes);
314 size_t write(const
void* buffer,
size_t buffer_size);
329 void writeAll(const
void* buffer,
size_t buffer_size);
337 void write(const std::
string&
string);
454 a_util::datetime::DateTime
getTimeAccess(const a_util::filesystem::Path filename);
482 a_util::datetime::DateTime
getTimeChange(const a_util::filesystem::Path filename);
521 a_util::memory::set(data, bytes, 0x00, bytes);
530 void fileRename(
const a_util::filesystem::Path& from,
const a_util::filesystem::Path& to);
bool _system_cache_disabled
System cache disabled.
Definition: file.h:198
FileHandle _file
File handle.
Definition: file.h:191
File() noexcept
Constructor.
size_t _file_cache_offset
File cache offset.
Definition: file.h:194
FilePosRef
File position reference.
Definition: file.h:179
@ fp_current
offsets are measured from the current file position
Definition: file.h:184
@ fp_end
offsets are measured from the end of the file
Definition: file.h:187
@ fp_begin
offsets are measured from the beginning of the file
Definition: file.h:181
bool _read_cache_enabled
Read cache enabled.
Definition: file.h:196
void writeLine(const std::string &string)
FilePos setFilePos(FilePos offset, FilePosRef move_mode)
void readLine(std::string &string)
bool _reference
File is reference.
Definition: file.h:197
FilePos getFilePos() const
void readAll(void *buffer, size_t buffer_size)
void allocReadCache(size_t cache_size)
size_t skip(size_t number_of_bytes)
FilePos _sector_bytes_to_skip
Sector bytes that will be skipped.
Definition: file.h:200
int _sector_size
Sector size.
Definition: file.h:199
void * internalMalloc(size_t size, bool use_segment_size=false)
uint8_t * _read_cache
File read cache.
Definition: file.h:192
size_t _file_cache_size
File cache size.
Definition: file.h:195
size_t _file_cache_usage
File cache usage.
Definition: file.h:193
size_t read(void *buffer, size_t buffer_size)
size_t write(const void *buffer, size_t buffer_size)
void setReadCache(size_t read_cache_size)
void open(const a_util::filesystem::Path &filename, uint32_t mode)
void truncate(FilePos size)
OpenMode
Several flags to open files. Can be combined with bitwise or.
Definition: file.h:125
@ om_temporary_file
Definition: file.h:160
@ om_no_overwrite
No overwrite if file already exists.
Definition: file.h:143
@ om_text_mode
Definition: file.h:167
@ om_shared_read
Definition: file.h:148
@ om_read_write
Definition: file.h:140
@ om_write
Definition: file.h:133
@ om_short_lived
Advices the OS not to flush any data to the disk. Just supported on POSIX platforms.
Definition: file.h:163
@ om_sequential_access
Optimized for sequential access, use in addition to flags above.
Definition: file.h:156
@ om_shared_write
Definition: file.h:153
@ om_read
Definition: file.h:129
@ om_write_through
Immediately flush file data to disk. Windows only.
Definition: file.h:170
@ om_append
Append data to existing file. Sets seeking position to the end of the file stream.
Definition: file.h:136
@ om_disable_file_system_cache
Disable all file system caches. Windows only.
Definition: file.h:173
void internalFree(void *memory, bool use_segment_size=false)
void writeAll(const void *buffer, size_t buffer_size)
Exception to indicate the end of file was reached.
Definition: file.h:61
EndOfFile()
default CTOR
Definition: file.h:66
EndOfFile(const std::string &what)
CTOR with description.
Definition: file.h:73
Indicates a file access error. platform dependent errors can be obtained via code().
Definition: file.h:82
ErrorFileAccess(int system_error_code, const std::string &what)
CTOR for file access errors.
ErrorFileAccess(const std::string &what)
CTOR for file access errors with no error code!
Indicates a file access error while creating a file that already exists and File::om_no_overwrite was...
Definition: file.h:102
ErrorFileAlreadyExists(int system_error_code, const std::string &what)
CTOR for file access errors.
Definition: file.h:109
int64_t FilePos
Type for a file position.
Definition: file.h:37
a_util::datetime::DateTime getTimeAccess(const a_util::filesystem::Path filename)
This function returns the last access time of the file.
a_util::datetime::DateTime getTimeChange(const a_util::filesystem::Path filename)
This function returns the last change (write) time of the file.
int FileHandle
The type FileHandle is used internally only.
Definition: file.h:50
void memZero(void *data, size_t bytes)
Helper function to set a memory buffer to zero.
Definition: file.h:519
size_t getSectorSizeFor(const a_util::filesystem::Path &filename) noexcept
Get the sector size of a file within windows file system.
void freePageAlignedMemory(void *memory)
frees the memory buffer allocated with utils5ext::allocPageAlignedMemory
void fileRename(const a_util::filesystem::Path &from, const a_util::filesystem::Path &to)
Renames or moves a file.
FilePos FileSize
Type for the file size.
Definition: file.h:41
size_t getDefaultSectorSize() noexcept
Get the Default Sector Size.
void * allocPageAlignedMemory(size_t size, size_t page_size)
allocates a memory buffer for the size of size (in bytes), page aligned in size to page_size
a_util::datetime::DateTime getTimeCreation(const a_util::filesystem::Path filename)
This function returns the creation time of the file.