16#ifndef MILEAGEFILEHANDLER_HPP
17#define MILEAGEFILEHANDLER_HPP
25using FileOpenFunc = std::function<bool(QFile &, QIODevice::OpenMode)>;
Definition of the FileController namespace.
Definition of the IMileageFileHandler interface.
std::function< bool(const QString &)> FileExistsFunc
std::function< bool(QFile &, const QString &)> FileWriteFunc
std::function< QString(QFile &)> FileReadFunc
std::function< bool(QFile &, QIODevice::OpenMode)> FileOpenFunc
Interface for reading and writing the mileage of a vehicle to a file.
double readMileage() const override
Reads the mileage from the file.
MileageFileHandler(const QString &filePath, FileOpenFunc openFunc=FileController::open, FileReadFunc readFunc=FileController::read, FileWriteFunc writeFunc=FileController::write, FileExistsFunc existsFunc=FileController::exists)
Constructs a MileageFileHandler object with the specified file path and functions.
FileExistsFunc existsFunc
void ensureFileExists() const
Checks if the file exists and creates it if it does not.
~MileageFileHandler()=default
void writeMileage(double mileage) const override
Writes the mileage to the file.
bool open(QFile &file, QIODevice::OpenMode mode)
Open a file.
bool exists(const QString &path)
Checks if a file exists.
QString read(QFile &file)
Reads a line from the file.
bool write(QFile &file, const QString &data)
Writes a line to the file.