Xyst test code coverage report
Current view: top level - Base - PrintUtil.hpp (source / functions) Hit Total Coverage
Commit: 5689ba12dc66a776d3d75f1ee48cc7d78eaa18dc Lines: 17 17 100.0 %
Date: 2024-11-22 19:17:03 Functions: 18 24 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 16 56.2 %

           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                 :         33 : operator<< ( std::basic_ostream< Ch, Tr >& os, const Enum& e ) {
      33                 :         33 :   os << static_cast< unsigned int >( e );
      34                 :         33 :   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                 :       7799 :   os << std::boolalpha;
      45                 :       7799 :   os << "{ ";
      46 [ +  - ][ +  - ]:      15530 :   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 [ +  - ][ +  - ]:          8 :   ss << lhs << e;
      77         [ +  - ]:          8 :   lhs = ss.str();
      78         [ +  - ]:         16 :   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                 :          4 : 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