Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
MileageFileHandler.hpp
Go to the documentation of this file.
1
15
16#ifndef MILEAGEFILEHANDLER_HPP
17#define MILEAGEFILEHANDLER_HPP
18
19#include <QFile>
20#include <QString>
21#include "FileController.hpp"
23#include <functional>
24
25using FileOpenFunc = std::function<bool(QFile &, QIODevice::OpenMode)>;
26using FileReadFunc = std::function<QString(QFile &)>;
27using FileWriteFunc = std::function<bool(QFile &, const QString &)>;
28using FileExistsFunc = std::function<bool(const QString &)>;
29
57
58#endif // MILEAGEFILEHANDLER_HPP
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.
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.