LCOV - code coverage report
Current view: top level - include - Manager.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 7 7 100.0 %
Date: 2024-12-28 17:36:05 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @file Manager.h
       3             :  * @author Damien Balima (www.dams-labs.net)
       4             :  * @brief Manager
       5             :  * @date 2024-03-08
       6             :  *
       7             :  * @copyright Damien Balima (c) CC-BY-NC-SA-4.0 2024
       8             :  *
       9             :  */
      10             : #pragma once
      11             : 
      12             : #include "AppParams.h"
      13             : #include "Common.h"
      14             : #include "NeuralNetworkBuilder.h"
      15             : #include "NeuralNetworkParams.h"
      16             : #include "RunnerVisitorFactory.h"
      17             : #include "SimpleLogger.h"
      18             : #include <cstddef>
      19             : #include <memory>
      20             : #include <mutex>
      21             : 
      22             : namespace sipai {
      23             : class Manager {
      24             : public:
      25         279 :   static Manager &getInstance() {
      26             :     static std::once_flag initInstanceFlag;
      27         280 :     std::call_once(initInstanceFlag, [] { instance_.reset(new Manager); });
      28         279 :     return *instance_;
      29             :   }
      30         175 :   static const Manager &getConstInstance() {
      31         175 :     return const_cast<const Manager &>(getInstance());
      32             :   }
      33             :   Manager(Manager const &) = delete;
      34             :   void operator=(Manager const &) = delete;
      35           1 :   ~Manager() = default;
      36             : 
      37             :   /**
      38             :    * @brief Application parameters.
      39             :    */
      40             :   AppParams app_params;
      41             : 
      42             :   /**
      43             :    * @brief Network parameters.
      44             :    */
      45             :   NeuralNetworkParams network_params;
      46             : 
      47             :   /**
      48             :    * @brief The neural network.
      49             :    */
      50             :   std::unique_ptr<NeuralNetwork> network = nullptr;
      51             : 
      52             :   /**
      53             :    * @brief Network builder.
      54             :    *
      55             :    * @param progressCallback
      56             :    */
      57             :   Manager &
      58             :   createOrImportNetwork(std::function<void(int)> progressCallback = {});
      59             : 
      60             :   /**
      61             :    * @brief show header
      62             :    *
      63             :    * @return Manager&
      64             :    */
      65             :   Manager &showHeader() {
      66             :     SimpleLogger::LOG_INFO(getVersionHeader());
      67             :     return *this;
      68             :   }
      69             : 
      70             :   /**
      71             :    * @brief show parameters
      72             :    *
      73             :    * @return Manager&
      74             :    */
      75             :   Manager &showParameters();
      76             : 
      77             :   /**
      78             :    * @brief Export the neural network to its json and csv files.
      79             :    *
      80             :    */
      81             :   void exportNetwork();
      82             : 
      83             :   /**
      84             :    * @brief Run the ai (main entrance).
      85             :    *
      86             :    */
      87             :   void run();
      88             : 
      89             :   /**
      90             :    * @brief Runs the provided visitor on the training and validation data sets
      91             :    * with the initialized neural network.
      92             :    *
      93             :    * This method is the entry point for executing different types of runners
      94             :    * (e.g., training, inference, evaluation) on the loaded data sets and the
      95             :    * initialized neural network. It accepts a visitor object implementing the
      96             :    * `RunnerVisitor` interface and calls its `visit` method, passing the
      97             :    * necessary data and parameters.
      98             :    *
      99             :    * @param visitor The visitor object implementing the `RunnerVisitor`
     100             :    * interface, which encapsulates the runner logic.
     101             :    */
     102             :   void runWithVisitor(const RunnerVisitor &visitor);
     103             : 
     104             :   /**
     105             :    * @brief Get a title line with the version
     106             :    *
     107             :    * @return std::string
     108             :    */
     109             :   std::string getVersionHeader() const {
     110             :     return app_params.title + " v" + app_params.version;
     111             :   }
     112             : 
     113             : private:
     114           1 :   Manager() = default;
     115             : 
     116             :   static std::unique_ptr<Manager> instance_;
     117             : 
     118             :   RunnerVisitorFactory runnerVisitorFactory_;
     119             : };
     120             : } // namespace sipai

Generated by: LCOV version 1.16