LCOV - code coverage report
Current view: top level - utils - FileController.cpp (source / functions) Hit Total Coverage
Test: filtered.info Lines: 11 11 100.0 %
Date: 2025-07-25 11:48:17 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*!
       2             :  * @file FileController.cpp
       3             :  * @brief
       4             :  * @version 0.1
       5             :  * @date 2025-02-12
       6             :  * @details
       7             :  * @author Félix LE BIHAN (@Fle-bihh)
       8             :  * @author Tiago Pereira (@t-pereira06)
       9             :  * @author Ricardo Melo (@reomelo)
      10             :  * @author Michel Batista (@MicchelFAB)
      11             :  *
      12             :  * @copyright Copyright (c) 2025
      13             :  */
      14             : 
      15             : #include "FileController.hpp"
      16             : #include <QDebug>
      17             : #include <QTextStream>
      18             : 
      19             : /*!
      20             :  * @namespace FileController
      21             :  * @brief Open a file.
      22             :  */
      23             : namespace FileController {
      24             : 
      25             :         /*!
      26             :          * @brief Open a file.
      27             :          *
      28             :          * @details Opens a file with the specified mode.
      29             :          *
      30             :          * @param file The file to open.
      31             :          * @param mode The mode to open the file with.
      32             :          *
      33             :          * @return True if the file was opened successfully, false otherwise.
      34             :          */
      35           7 :         bool open(QFile &file, QIODevice::OpenMode mode)
      36             :         {
      37           7 :                 return file.open(mode);
      38             :         }
      39             : 
      40             :         /*!
      41             :          * @brief Reads a line from the file.
      42             :          *
      43             :          * @details This function reads a single line from the specified file using
      44             :          * a QTextStream. It assumes the file is already open for reading.
      45             :          *
      46             :          * @param file The file to read from.
      47             :          *
      48             :          * @return The line read from the file as a QString.
      49             :          */
      50           2 :         QString read(QFile &file)
      51             :         {
      52           4 :                 QTextStream in(&file);
      53           4 :                 return in.readLine();
      54             :         }
      55             : 
      56             :         /*!
      57             :          * @brief Writes a line to the file.
      58             :          *
      59             :          * @details This function writes a single line to the specified file using
      60             :          * a QTextStream. It assumes the file is already open for writing.
      61             :          *
      62             :          * @param file The file to write to.
      63             :          * @param data The line to write to the file.
      64             :          *
      65             :          * @return True if the line was written successfully, false otherwise.
      66             :          */
      67           3 :         bool write(QFile &file, const QString &data)
      68             :         {
      69           3 :                 QTextStream out(&file);
      70           3 :                 out << data << endl;
      71           6 :                 return true;
      72             :         }
      73             : 
      74             :         /*!
      75             :          * @brief Checks if a file exists.
      76             :          *
      77             :          * @details This function checks if the given file path exists.
      78             :          *
      79             :          * @param path The file path to check.
      80             :          *
      81             :          * @return True if the file exists, false otherwise.
      82             :          */
      83           2 :         bool exists(const QString &path)
      84             :         {
      85           2 :                 return QFile::exists(path);
      86             :         }
      87             : 
      88             : } // namespace FileController

Generated by: LCOV version 1.14