Quinoa regression test code coverage report
Current view: top level - Base - PrintUtil.hpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 13 20 65.0 %
Date: 2021-11-11 13:17:06 Functions: 71 149 47.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 40 15.0 %

           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                 :       4355 : operator<< ( std::basic_ostream< Ch, Tr >& os, const Enum& e ) {
      33                 :       4355 :   os << static_cast< unsigned int >( e );
      34                 :       4355 :   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                 :      56852 : operator<< ( std::basic_ostream< Ch, Tr >& os, const std::vector< T >& v ) {
      44                 :      56852 :   os << std::boolalpha;
      45                 :      56852 :   os << "[ ";
      46 [ +  + ][ +  - ]:      70264 :   for (const auto& p : v) os << p << ' ';
                 [ +  - ]
      47                 :      56852 :   os << ']';
      48                 :      56852 :   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                 :        389 : 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 [ -  + ][ -  - ]:        156 :     for (const auto& [k,v] : m) os << '(' << k << ") : { " << v << "} ";
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      63                 :            :   else
      64 [ -  + ][ -  - ]:        233 :     for (const auto& [k,v] : m) os << '(' << k << ") " << v << ' ';
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      65                 :        389 :   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                 :          0 : operator<< ( std::basic_string< Ch, Tr >& lhs, const T& e ) {
      75         [ -  - ]:          0 :   std::stringstream ss;
      76 [ -  - ][ -  - ]:          0 :   ss << lhs << e;
      77         [ -  - ]:          0 :   lhs = ss.str();
      78         [ -  - ]:          0 :   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                 :          0 : operator<< ( std::basic_string< Ch, Tr >&& lhs, const T& e ) {
      88                 :          0 :   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