LCOV - code coverage report
Current view: top level - src/Tools - compute_bytes.cpp (source / functions) Hit Total Coverage
Test: streampu_clean.info Lines: 20 37 54.1 %
Date: 2024-06-12 12:04:18 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include <cstdint>
       2             : #include <sstream>
       3             : 
       4             : #include "Tools/Exception/exception.hpp"
       5             : #include "Tools/compute_bytes.h"
       6             : 
       7             : size_t
       8         454 : spu::tools::compute_bytes(const size_t n_elmts, const std::type_index type)
       9             : {
      10         454 :     if (type == typeid(int8_t))
      11           3 :         return n_elmts * sizeof(int8_t);
      12         451 :     else if (type == typeid(uint8_t))
      13         325 :         return n_elmts * sizeof(uint8_t);
      14         126 :     else if (type == typeid(int16_t))
      15           0 :         return n_elmts * sizeof(int16_t);
      16         126 :     else if (type == typeid(uint16_t))
      17           0 :         return n_elmts * sizeof(uint16_t);
      18         126 :     else if (type == typeid(int32_t))
      19          26 :         return n_elmts * sizeof(int32_t);
      20         100 :     else if (type == typeid(uint32_t))
      21          84 :         return n_elmts * sizeof(uint32_t);
      22          16 :     else if (type == typeid(int64_t))
      23           0 :         return n_elmts * sizeof(int64_t);
      24          16 :     else if (type == typeid(uint64_t))
      25          16 :         return n_elmts * sizeof(uint64_t);
      26           0 :     else if (type == typeid(float))
      27           0 :         return n_elmts * sizeof(float);
      28           0 :     else if (type == typeid(double))
      29           0 :         return n_elmts * sizeof(double);
      30             :     else
      31             :     {
      32           0 :         std::stringstream message;
      33           0 :         message << "This should never happen.";
      34           0 :         throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str());
      35           0 :     }
      36             : }
      37             : 
      38             : std::vector<size_t>
      39         185 : spu::tools::compute_bytes(const std::vector<size_t>& n_elmts, const std::vector<std::type_index>& type)
      40             : {
      41         185 :     if (n_elmts.size() != type.size())
      42             :     {
      43           0 :         std::stringstream message;
      44           0 :         message << "'n_elmts.size()' has to be equal to 'type.size()' ('n_elmts.size()' = " << n_elmts.size()
      45           0 :                 << ", 'type.size()' = " << type.size() << ").";
      46           0 :         throw tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
      47           0 :     }
      48             : 
      49         185 :     std::vector<size_t> bytes(n_elmts.size());
      50         513 :     for (size_t i = 0; i < n_elmts.size(); i++)
      51         328 :         bytes[i] = spu::tools::compute_bytes(n_elmts[i], type[i]);
      52         185 :     return bytes;
      53           0 : }

Generated by: LCOV version 1.14