LCOV - code coverage report
Current view: top level - include/esys/repo/manifest - task_t.h (source / functions) Hit Total Coverage
Test: esysrepo_coverage.info Lines: 17 17 100.0 %
Date: 2026-08-01 10:43:40 Functions: 8 10 80.0 %

          Line data    Source code
       1             : /*!
       2             :  * \file esys/repo/manifest/task_t.h
       3             :  * \brief Task t for esysrepo
       4             :  *
       5             :  * \cond
       6             :  * __legal_b__
       7             :  *
       8             :  * Copyright (c) 2020 Michel Gillet
       9             :  * Distributed under the MIT License.
      10             :  * (See accompanying file LICENSE.txt or
      11             :  * copy at https://opensource.org/licenses/MIT)
      12             :  *
      13             :  * __legal_e__
      14             :  * \endcond
      15             :  *
      16             :  */
      17             : 
      18             : #pragma once
      19             : 
      20             : #include "esys/repo/esysrepo_defs.h"
      21             : #include "esys/repo/manifest/taskbase.h"
      22             : 
      23             : #include <memory>
      24             : #include <functional>
      25             : 
      26             : namespace esys
      27             : {
      28             : 
      29             : namespace repo
      30             : {
      31             : 
      32             : namespace manifest
      33             : {
      34             : 
      35             : /*! \tparam OBJ the task object type */
      36             : /*! \tparam F the callable type */
      37             : template<typename OBJ, typename F, typename... ARGS>
      38             : class Task_t : public TaskBase
      39             : {
      40             : public:
      41             :     //! Constructor
      42             :     /*!
      43             :      * \param[in] obj std::shared_ptr<OBJ> obj
      44             :      * \param[in] raw_fct F &&raw_fct
      45             :      * \param[in] args ARGS &&... args
      46             :      */
      47             :     Task_t(std::shared_ptr<OBJ> obj, F &&raw_fct, ARGS &&... args);
      48             : 
      49             :     //! Constructor
      50             :     /*!
      51             :      * \param[in] obj std::shared_ptr<OBJ> obj
      52             :      * \param[in] raw_fct F &&raw_fct
      53             :      * \param[in] repo std::shared_ptr<Repository> repo
      54             :      * \param[in] args ARGS &&... args
      55             :      */
      56             :     Task_t(std::shared_ptr<OBJ> obj, F &&raw_fct, std::shared_ptr<Repository> repo, ARGS &&... args);
      57             : 
      58             :     //! Destructor
      59             :     ~Task_t() override;
      60             : 
      61             :     //! run
      62             :     int run() override;
      63             : 
      64             : private:
      65             :     //!< \cond DOXY_IMPL
      66             :     std::shared_ptr<OBJ> m_obj;
      67             :     F m_raw_fct;
      68             :     std::function<int()> m_fct;
      69             : 
      70             :     //!< \endcond
      71             : };
      72             : 
      73             : template<typename OBJ, typename F, typename... ARGS>
      74           1 : Task_t<OBJ, F, ARGS...>::Task_t(std::shared_ptr<OBJ> obj, F &&raw_fct, ARGS &&... args)
      75             :     : TaskBase()
      76           1 :     , m_obj(obj)
      77           1 :     , m_raw_fct(std::forward<F>(raw_fct))
      78             : {
      79           4 :     m_fct = [obj, raw_fct, args...] { return (obj.get()->*raw_fct)(args...); };
      80           1 : }
      81             : 
      82             : template<typename OBJ, typename F, typename... ARGS>
      83           1 : Task_t<OBJ, F, ARGS...>::Task_t(std::shared_ptr<OBJ> obj, F &&raw_fct, std::shared_ptr<Repository> repo,
      84             :                                 ARGS &&... args)
      85             :     : TaskBase()
      86           1 :     , m_obj(obj)
      87           2 :     , m_raw_fct(std::forward<F>(raw_fct))
      88             : {
      89           3 :     this->set_repo(repo);
      90             : 
      91           5 :     m_fct = [obj, raw_fct, repo, args...] { return (obj.get()->*raw_fct)(repo, args...); };
      92           1 : }
      93             : 
      94             : template<typename OBJ, typename F, typename... ARGS>
      95           2 : Task_t<OBJ, F, ARGS...>::~Task_t()
      96             : {
      97           4 : }
      98             : 
      99             : template<typename OBJ, typename F, typename... ARGS>
     100           2 : int Task_t<OBJ, F, ARGS...>::run()
     101             : {
     102           2 :     int result = m_fct();
     103           2 :     this->set_result(result);
     104             : 
     105           2 :     return result;
     106             : }
     107             : 
     108             : } // namespace manifest
     109             : 
     110             : } // namespace repo
     111             : 
     112             : } // namespace esys

Generated by: LCOV version 1.14