Xyst test code coverage report
Current view: top level - Base - PrintUtil.hpp (source / functions) Hit Total Coverage
Commit: e489e3468f2b950872163df1285c13fa7a355e8c Lines: 14 14 100.0 %
Date: 2024-11-20 18:16:45 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 40 25.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                 :            :              2022-2024 J. Bakosi
       8                 :            :              All rights reserved. See the LICENSE file for details.
       9                 :            :   \brief     String conversion utilities
      10                 :            :   \details   Various string conversion utilities.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : #pragma once
      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                 :            : operator<< ( std::basic_ostream< Ch, Tr >& os, const Enum& e ) {
      33 [ +  - ][ +  - ]:         30 :   os << static_cast< unsigned int >( e );
      34                 :          3 :   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                 :       7799 : operator<< ( std::basic_ostream< Ch, Tr >& os, const std::vector< T >& v ) {
      44                 :            :   os << std::boolalpha;
      45                 :       7799 :   os << "{ ";
      46         [ +  + ]:      15576 :   for (const auto& p : v) os << p << ' ';
      47                 :       7799 :   os << '}';
      48                 :       7799 :   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                 :            : 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                 :            :     for (const auto& [k,v] : m) os << '(' << k << ") " << v << ' ';
      65                 :            :   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                 :          8 : operator<< ( std::basic_string< Ch, Tr >& lhs, const T& e ) {
      75                 :          8 :   std::stringstream ss;
      76         [ +  - ]:          6 :   ss << lhs << e;
      77         [ +  - ]:         16 :   lhs = ss.str();
      78                 :          8 :   return lhs;
      79                 :          8 : }
      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                 :            : operator<< ( std::basic_string< Ch, Tr >&& lhs, const T& e ) {
      88 [ +  - ][ +  - ]:          4 :   return lhs << e;
         [ +  - ][ +  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      89                 :            : }
      90                 :            : 
      91                 :            : } // tk::

Generated by: LCOV version 1.16