LCOV - code coverage report
Current view: top level - src/types - State.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 6 100.0 %
Date: 2023-04-08 04:19:02 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /*
       2             :  * State.hpp
       3             :  *
       4             :  * Generic State class to hold time, Ah, Wh.
       5             :  *
       6             :  *  Created on: 02 Sep 2022
       7             :  *   Author(s): Jorn Reniers, Volkan Kumtepeli
       8             :  */
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "../settings/settings.hpp"
      13             : #include "../utility/array_util.hpp"
      14             : 
      15             : #include <array>
      16             : #include <algorithm>
      17             : 
      18             : namespace slide {
      19             : 
      20             : static double EMPTY_STATE{ 0 }; // To return reference when a state is not defined.
      21             : 
      22             : template <size_t N, size_t N_cumulative = settings::data::N_CumulativeCell>
      23             : struct State : public std::array<double, N + N_cumulative>
      24             : {
      25             :   enum Index : size_t //!< Index variables for:
      26             :   {
      27             :     i_time = N,
      28             :     i_Ah,
      29             :     i_Wh,
      30             :     N_states,
      31             :   };
      32             : 
      33      806970 :   inline auto time() const { return (N_cumulative != 3) ? EMPTY_STATE : (*this)[i_time]; } //!< time [s]
      34      806970 :   inline auto Ah() const { return (N_cumulative != 3) ? EMPTY_STATE : (*this)[i_Ah]; }     //!< Current throughput [Ah]
      35      806970 :   inline auto Wh() const { return (N_cumulative != 3) ? EMPTY_STATE : (*this)[i_Wh]; }     //!< Energy throughput [Wh]
      36             : 
      37     2035338 :   inline auto &time() { return (N_cumulative != 3) ? EMPTY_STATE : (*this)[i_time]; } //!< time [s]
      38     2448231 :   inline auto &Ah() { return (N_cumulative != 3) ? EMPTY_STATE : (*this)[i_Ah]; }     //!< Current throughput [Ah]
      39     2035338 :   inline auto &Wh() { return (N_cumulative != 3) ? EMPTY_STATE : (*this)[i_Wh]; }     //!< Energy throughput [Wh]
      40             : 
      41             :   constexpr static auto description(size_t i)
      42             :   {
      43             :     if constexpr (N_cumulative != 3)
      44             :       return "";
      45             :     else {
      46             :       if (i == i_time)
      47             :         return "time [s]";
      48             :       else if (i == i_Ah)
      49             :         return "Current throughput [Ah]";
      50             :       else if (i == i_Wh)
      51             :         return "Energy throughput [Wh]";
      52             :       else
      53             :         return "";
      54             :     }
      55             :   }
      56             : 
      57             :   inline auto reset() { this->fill(0); }
      58             : };
      59             : 
      60             : } // namespace slide

Generated by: LCOV version 1.14