Class that manages the mileage file.
More...
#include <MileageFileHandler.hpp>
|
void | ensureFileExists () const |
| Checks if the file exists and creates it if it does not.
|
|
Class that manages the mileage file.
Definition at line 34 of file MileageFileHandler.hpp.
◆ MileageFileHandler()
Constructs a MileageFileHandler object with the specified file path and functions.
- Parameters
-
filePath | The path to the mileage file. |
openFunc | The function to open a file. |
readFunc | The function to read from a file. |
writeFunc | The function to write to a file. |
existsFunc | The function to check if a file exists. |
This constructor initializes the MileageFileHandler object with the specified file path and functions. It also calls ensureFileExists() to create the file if it does not exist.
Definition at line 33 of file MileageFileHandler.cpp.
◆ ~MileageFileHandler()
MileageFileHandler::~MileageFileHandler |
( |
| ) |
|
|
default |
◆ ensureFileExists()
void MileageFileHandler::ensureFileExists |
( |
| ) |
const |
|
private |
Checks if the file exists and creates it if it does not.
This method checks if the file exists by calling the existsFunc function. If the file does not exist, it is created by calling the openFunc function with the QIODevice::WriteOnly and QIODevice::Text flags. The default value of the mileage is written to the file by calling the writeFunc function. If the file is created successfully, a message is logged to the console indicating that the file was created.
- Warning
- If the file cannot be created, a warning message is logged to the console.
Definition at line 60 of file MileageFileHandler.cpp.
◆ readMileage()
double MileageFileHandler::readMileage |
( |
| ) |
const |
|
overridevirtual |
Reads the mileage from the file.
- Returns
- The mileage value read from the file or 0.0 if the file is invalid.
This method reads the mileage value from the file by calling the readFunc function. If the file cannot be opened for reading, a warning message is logged to the console. If the mileage value is invalid, a warning message is logged to the console and the default value of 0.0 is returned.
Implements IMileageFileHandler.
Definition at line 85 of file MileageFileHandler.cpp.
◆ writeMileage()
void MileageFileHandler::writeMileage |
( |
double | mileage | ) |
const |
|
overridevirtual |
Writes the mileage to the file.
- Parameters
-
mileage | The mileage value to write. |
This method writes the mileage value to the file by calling the writeFunc function. If the file cannot be opened for writing, a warning message is logged to the console.
Implements IMileageFileHandler.
Definition at line 112 of file MileageFileHandler.cpp.
◆ existsFunc
◆ filePath
QString MileageFileHandler::filePath |
|
private |
◆ openFunc
◆ readFunc
◆ writeFunc
The documentation for this class was generated from the following files: