Quinoa all test code coverage report
Current view: top level - Base - TaggedTuplePrint.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 5 5 100.0 %
Date: 2024-04-29 14:42:33 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Base/TaggedTuplePrint.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     Simple (unformatted, one-line) TaggedTuple printer
       9                 :            :   \details   Simple (unformatted, one-line) TaggedTuple printer.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : #ifndef TaggedTuplePrint_h
      13                 :            : #define TaggedTuplePrint_h
      14                 :            : 
      15                 :            : #include <ostream>
      16                 :            : 
      17                 :            : #include <brigand/algorithms/for_each.hpp>
      18                 :            : #include <brigand/sequences/has_key.hpp>
      19                 :            : 
      20                 :            : #include "NoWarning/set.hpp"
      21                 :            : #include "TaggedTuple.hpp"
      22                 :            : 
      23                 :            : namespace tk {
      24                 :            : 
      25                 :            : //! Function object type to print contents of a TaggedTuple
      26                 :            : //! \tparam List brigand::list of types in the tagged tuple
      27                 :            : //! \tparam Ignore brigand::list of types to not print
      28                 :            : template< class List, class Ignore = brigand::set<> >
      29                 :            : struct TuplePrinter {
      30                 :            :   std::ostream& os;
      31                 :            :   const tk::TaggedTuple< List >& tuple;
      32                 :            :   //! Constructor
      33                 :        197 :   TuplePrinter( std::ostream& s, const tk::TaggedTuple< List >& t ) :
      34                 :        197 :     os(s), tuple(t) {}
      35                 :            :   //! Function call operator templated on the type being output
      36                 :            :   template< typename Key > void operator()( brigand::type_<Key> ) {
      37                 :            :     using ignored = brigand::has_key< Ignore, Key >;
      38                 :            :     if constexpr( std::is_same_v< ignored, brigand::false_type > ) {
      39                 :            :       using Tuple = tk::TaggedTuple< List >;
      40                 :            :       const auto& key = Key::name();
      41                 :            :       const auto& value = tuple.template get< Key >();
      42                 :            :       if constexpr( Tuple::template is_tagged_tuple< Key >::value )
      43                 :            :         os << key << ": { " << value << "} ";
      44                 :            :       else
      45                 :            :         os << key << ": '" << value << "' ";
      46                 :            :     }
      47                 :            :   }
      48                 :            : };
      49                 :            : 
      50                 :            : //! Simple (unformatted, one-line) output of a TaggedTuple to output stream
      51                 :            : //! \tparam List brigand::list of types in the tagged tuple
      52                 :            : //! \param[in,out] os Output stream to output to
      53                 :            : //! \param[in] t TaggedTuple to print
      54                 :            : //! \return Output stream
      55                 :            : template< class List >
      56                 :            : inline std::ostream&
      57                 :        515 : operator<< ( std::ostream& os, const tk::TaggedTuple< List >& t ) {
      58                 :            :   using keys = typename tk::TaggedTuple< List >::Keys;
      59                 :            :   os << std::boolalpha;
      60                 :        502 :   brigand::for_each< keys >( TuplePrinter< List >( os, t ) );
      61                 :        515 :   return os;
      62                 :            : }
      63                 :            : 
      64                 :            : //! \brief Simple (unformatted, one-line) output of a TaggedTuple to output
      65                 :            : //!   stream with ignore
      66                 :            : //! \tparam List brigand::list of types in the tagged tuple
      67                 :            : //! \tparam Ignore brigand::list of types to not print
      68                 :            : //! \param[in,out] os Output stream to output to
      69                 :            : //! \param[in] t TaggedTuple to print
      70                 :            : template< class List, class Ignore = brigand::set<> >
      71                 :            : inline void
      72                 :            : print( std::ostream& os, const tk::TaggedTuple< List >& t ) {
      73                 :            :   using keys = typename tk::TaggedTuple< List >::Keys;
      74                 :            :   os << std::boolalpha;
      75                 :            :   brigand::for_each< keys >( TuplePrinter< List, Ignore >( os, t ) );
      76                 :            : }
      77                 :            : 
      78                 :            : } // tk::
      79                 :            : 
      80                 :            : #endif // TaggedTuplePrint_h

Generated by: LCOV version 1.14