Quinoa all test code coverage report
Current view: top level - Base - PrintUtil.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 19 19 100.0 %
Date: 2024-11-08 10:55:28 Functions: 50 86 58.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 28 35.7 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Base/PrintUtil.hpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     String conversion utilities
       9                 :            :   \details   Various string conversion utilities.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : #ifndef PrintUtil_h
      13                 :            : #define PrintUtil_h
      14                 :            : 
      15                 :            : #include <ostream>
      16                 :            : #include <sstream>
      17                 :            : #include <string>
      18                 :            : #include <vector>
      19                 :            : #include <map>
      20                 :            : 
      21                 :            : #include "Has.hpp"
      22                 :            : 
      23                 :            : namespace tk {
      24                 :            : 
      25                 :            : //! Operator << for writing an enum class to an output stream
      26                 :            : //! \param[in] os Output stream into to write to
      27                 :            : //! \param[in] e Value of enum-class type to write to stream
      28                 :            : //! \return Updated output stream for chain-use of the operator
      29                 :            : template< typename Enum, typename Ch, typename Tr,
      30                 :            :           typename std::enable_if_t< std::is_enum_v<Enum>, int > = 0 >
      31                 :            : inline std::basic_ostream< Ch, Tr >&
      32                 :       4164 : operator<< ( std::basic_ostream< Ch, Tr >& os, const Enum& e ) {
      33                 :       4164 :   os << static_cast< unsigned int >( e );
      34                 :       4164 :   return os;
      35                 :            : }
      36                 :            : 
      37                 :            : //! Operator << for writing a std::vector to an output stream
      38                 :            : //! \param[in] os Output stream to write to
      39                 :            : //! \param[in] v Vector to write to stream
      40                 :            : //! \return Updated output stream for chain-use of the operator
      41                 :            : template< class T, typename Ch, typename Tr >
      42                 :            : inline std::basic_ostream< Ch, Tr >&
      43                 :      11262 : operator<< ( std::basic_ostream< Ch, Tr >& os, const std::vector< T >& v ) {
      44                 :      11262 :   os << std::boolalpha;
      45                 :      11262 :   os << "[ ";
      46 [ +  + ][ +  - ]:      19928 :   for (const auto& p : v) os << p << ' ';
                 [ +  - ]
      47                 :      11262 :   os << ']';
      48                 :      11262 :   return os;
      49                 :            : }
      50                 :            : 
      51                 :            : //! Operator << for writing an std::map to an output stream
      52                 :            : //! \param[in] os Output stream to write to
      53                 :            : //! \param[in] m Map to write to stream
      54                 :            : //! \return Updated output stream for chain-use of the operator
      55                 :            : template< typename Ch, typename Tr,
      56                 :            :           class Key, class Value, class Compare = std::less< Key > >
      57                 :            : inline std::basic_ostream< Ch, Tr >&
      58                 :        189 : operator<< ( std::basic_ostream< Ch, Tr >& os,
      59                 :            :              const std::map< Key, Value, Compare >& m )
      60                 :            : {
      61                 :            :   if constexpr( tk::HasTypedef_i_am_tagged_tuple_v< Value > )
      62                 :            :     for (const auto& [k,v] : m) os << '(' << k << ") : { " << v << "} ";
      63                 :            :   else
      64 [ -  + ][ -  - ]:        189 :     for (const auto& [k,v] : m) os << '(' << k << ") " << v << ' ';
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      65                 :        189 :   return os;
      66                 :            : }
      67                 :            : 
      68                 :            : //! Operator << for adding (concatenating) T to a std::basic_string for lvalues.
      69                 :            : //! \param[in] lhs Output std::basic_string into which e is written
      70                 :            : //! \param[in] e Value of arbitrary type to write to string
      71                 :            : //! \return Updated string
      72                 :            : template< typename T, typename Ch, typename Tr >
      73                 :            : std::basic_string< Ch, Tr >
      74                 :         10 : operator<< ( std::basic_string< Ch, Tr >& lhs, const T& e ) {
      75         [ +  - ]:         20 :   std::stringstream ss;
      76 [ +  - ][ +  - ]:         10 :   ss << lhs << e;
      77         [ +  - ]:         10 :   lhs = ss.str();
      78         [ +  - ]:         20 :   return lhs;
      79                 :            : }
      80                 :            : 
      81                 :            : //! Operator << for adding (concatenating) T to a std::basic_string for rvalues.
      82                 :            : //! \param[in] lhs Output std::basic_string into which e is written
      83                 :            : //! \param[in] e Value of arbitrary type to write to string
      84                 :            : //! \return Updated string
      85                 :            : template< typename T, typename Ch, typename Tr >
      86                 :            : std::basic_string< Ch, Tr >
      87                 :          6 : operator<< ( std::basic_string< Ch, Tr >&& lhs, const T& e ) {
      88                 :          6 :   return lhs << e;
      89                 :            : }
      90                 :            : 
      91                 :            : //!  Clean up whitespaces and format a long string into multiple lines
      92                 :            : std::string
      93                 :            : splitLines( std::string str,
      94                 :            :             std::string indent,
      95                 :            :             const std::string& name = "",
      96                 :            :             std::size_t width = 80 );
      97                 :            : 
      98                 :            : // Calculate base log file name
      99                 :            : std::string
     100                 :            : baselogname( const std::string& executable );
     101                 :            : 
     102                 :            : //! Construct log file name
     103                 :            : std::string
     104                 :            : logname( const std::string& executable, int numrestart = 0 );
     105                 :            : 
     106                 :            : } // tk::
     107                 :            : 
     108                 :            : #endif // PrintUtil_h

Generated by: LCOV version 1.14