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

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Base/PrintTaggedTupleDeep.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     Structured TaggedTuple printer with depth/indentation
      10                 :            :   \details   Structured TaggedTuple printer with depth/indentation.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : #pragma once
      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                 :            : 
      22                 :            : #include "Has.hpp"
      23                 :            : 
      24                 :            : // The include order here is important: it populates the overloads of
      25                 :            : // operator<< for various types, followed by TaggedTuple, the (simple)
      26                 :            : // TaggedTuplePrint (which will be accessible by the upstream, simpler
      27                 :            : // operator<< for vector, map, etc.) and finally, the most complex TaggedTuple
      28                 :            : // printer with depth, defined below.
      29                 :            : #include "PrintUtil.hpp"
      30                 :            : #include "TaggedTuple.hpp"
      31                 :            : #include "PrintTaggedTuple.hpp"
      32                 :            : 
      33                 :            : namespace tk {
      34                 :            : 
      35                 :            : //! Function object type to print contents of a TaggedTuple at depth
      36                 :            : //! \details Compared to tk::TuplePrinter this prints every key and value
      37                 :            : //!   in a new line and nested tagged tuples starts at increasing depths
      38                 :            : //!   (indents).
      39                 :            : //! \tparam List brigand::list of types in the tagged tuple
      40                 :            : template< class List >
      41                 :            : struct DeepTuplePrinter {
      42                 :            :   std::ostream& os;
      43                 :            :   const tk::TaggedTuple< List >& tuple;
      44                 :            :   std::size_t& depth;
      45                 :            :   //! Constructor
      46                 :        530 :   DeepTuplePrinter( std::ostream& s, const tk::TaggedTuple< List >& t,
      47                 :        530 :                     std::size_t& d ) : os(s), tuple(t), depth(d) {}
      48                 :            :   //! Function call operator templated on the type being output
      49                 :      30450 :   template< typename Key > void operator()( brigand::type_<Key> ) {
      50                 :            :     using Tuple = tk::TaggedTuple< List >;
      51                 :      30450 :     const auto& key = Key::key();
      52                 :      30450 :     const auto& value = tuple.template get< Key >();
      53                 :            :     if constexpr( Tuple::template is_tagged_tuple< Key >::value ) {
      54         [ +  - ]:        254 :       std::string indent( depth * 2, ' ' );
      55 [ +  - ][ +  - ]:        254 :       os << '\n' << indent << key << " = {";
         [ +  - ][ +  - ]
      56                 :            :       using ituple = typename Tuple::template TupleElement< Key >;
      57                 :            :       using ikeys = typename ituple::Keys;
      58                 :            :       using ilist = typename ituple::PairList;
      59         [ +  - ]:        254 :       brigand::for_each< ikeys >(
      60                 :        254 :         DeepTuplePrinter< ilist >( os, value, ++depth ) );
      61 [ +  - ][ +  - ]:        254 :       os << '\n' << indent << '}';
                 [ +  - ]
      62                 :        254 :       --depth;
      63                 :        254 :     } else {
      64         [ +  - ]:      30196 :       std::string indent( depth * 2, ' ' );
      65 [ +  - ][ +  - ]:      30196 :       os << '\n' << indent << key  << " = " << value;
         [ +  - ][ +  - ]
                 [ +  - ]
      66                 :      30196 :     }
      67                 :      30450 :   }
      68                 :            : };
      69                 :            : 
      70                 :            : //! Output command line object (a TaggedTuple) to file
      71                 :            : //! \tparam Tuple Tuple object type
      72                 :            : //! \param[in,out] os Output stream to print to
      73                 :            : //! \param[in] c Command line object to output to file
      74                 :            : template< class Tuple >
      75                 :        276 : void print( std::ostream& os, const Tuple& c ) {
      76                 :            :   static_assert( tk::HasTypedef_i_am_tagged_tuple_v< Tuple > );
      77                 :            :   using Keys = typename Tuple::Keys;
      78                 :            :   using List = typename Tuple::PairList;
      79         [ +  - ]:        276 :   os << "{";
      80                 :        276 :   std::size_t depth = 1;
      81         [ +  - ]:        276 :   brigand::for_each< Keys >( DeepTuplePrinter< List >( os, c, depth ) );
      82         [ +  - ]:        276 :   os << "\n}\n";
      83                 :        276 : }
      84                 :            : 
      85                 :            : } // tk::

Generated by: LCOV version 1.16