Hotwheels-Cluster 1.2
Creation of Cluster APP for SEA:ME project.
 
Loading...
Searching...
No Matches
MileageFileHandler Class Reference

Class that manages the mileage file. More...

#include <MileageFileHandler.hpp>

Public Member Functions

 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.
 
 ~MileageFileHandler ()=default
 
double readMileage () const override
 Reads the mileage from the file.
 
void writeMileage (double mileage) const override
 Writes the mileage to the file.
 
- Public Member Functions inherited from IMileageFileHandler
virtual ~IMileageFileHandler ()=default
 

Private Member Functions

void ensureFileExists () const
 Checks if the file exists and creates it if it does not.
 

Private Attributes

QString filePath
 
FileOpenFunc openFunc
 
FileReadFunc readFunc
 
FileWriteFunc writeFunc
 
FileExistsFunc existsFunc
 

Detailed Description

Class that manages the mileage file.

Definition at line 34 of file MileageFileHandler.hpp.

Constructor & Destructor Documentation

◆ MileageFileHandler()

MileageFileHandler::MileageFileHandler ( const QString & filePath,
FileOpenFunc openFunc = FileController::open,
FileReadFunc readFunc = FileController::read,
FileWriteFunc writeFunc = FileController::write,
FileExistsFunc existsFunc = FileController::exists )
explicit

Constructs a MileageFileHandler object with the specified file path and functions.

Parameters
filePathThe path to the mileage file.
openFuncThe function to open a file.
readFuncThe function to read from a file.
writeFuncThe function to write to a file.
existsFuncThe 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.

Here is the call graph for this function:

◆ ~MileageFileHandler()

MileageFileHandler::~MileageFileHandler ( )
default

Member Function Documentation

◆ 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.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ writeMileage()

void MileageFileHandler::writeMileage ( double mileage) const
overridevirtual

Writes the mileage to the file.

Parameters
mileageThe 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.

Field Documentation

◆ existsFunc

FileExistsFunc MileageFileHandler::existsFunc
private

Definition at line 53 of file MileageFileHandler.hpp.

◆ filePath

QString MileageFileHandler::filePath
private

Definition at line 49 of file MileageFileHandler.hpp.

◆ openFunc

FileOpenFunc MileageFileHandler::openFunc
private

Definition at line 50 of file MileageFileHandler.hpp.

◆ readFunc

FileReadFunc MileageFileHandler::readFunc
private

Definition at line 51 of file MileageFileHandler.hpp.

◆ writeFunc

FileWriteFunc MileageFileHandler::writeFunc
private

Definition at line 52 of file MileageFileHandler.hpp.


The documentation for this class was generated from the following files: