Xyst test code coverage report
Current view: top level - Base - PrintTaggedTupleDeep.hpp (source / functions) Coverage Total Hit
Commit: 1fb74642dd9d7732b67f32dec2f2762e238d3fa7 Lines: 100.0 % 19 19
Test Date: 2025-08-13 22:18:46 Functions: 100.0 % 165 165
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 50.0 % 18 9

             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-2025 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                 :        1897 :   DeepTuplePrinter( std::ostream& s, const tk::TaggedTuple< List >& t,
      47                 :        1897 :                     std::size_t& d ) : os(s), tuple(t), depth(d) {}
      48                 :             :   //! Function call operator templated on the type being output
      49                 :       40022 :   template< typename Key > void operator()( brigand::type_<Key> ) {
      50                 :             :     using Tuple = tk::TaggedTuple< List >;
      51                 :             :     const auto& key = Key::key();
      52                 :       40022 :     const auto& value = tuple.template get< Key >();
      53                 :             :     if constexpr( Tuple::template is_tagged_tuple< Key >::value ) {
      54                 :        2681 :       std::string indent( depth * 2, ' ' );
      55 [ +  - ][ +  - ]:        5362 :       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                 :           1 :       brigand::for_each< ikeys >(
      60         [ +  - ]:        2681 :         DeepTuplePrinter< ilist >( os, value, ++depth ) );
      61 [ +  - ][ +  - ]:        5362 :       os << '\n' << indent << '}';
      62                 :        2681 :       --depth;
      63                 :             :     } else {
      64                 :       37341 :       std::string indent( depth * 2, ' ' );
      65 [ +  - ][ +  - ]:      107957 :       os << '\n' << indent << key  << " = " << value;
                 [ +  - ]
      66                 :             :     }
      67                 :       40022 :   }
      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                 :         291 : 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                 :         291 :   os << "{";
      80                 :         291 :   std::size_t depth = 1;
      81                 :         291 :   brigand::for_each< Keys >( DeepTuplePrinter< List >( os, c, depth ) );
      82                 :         291 :   os << "\n}\n";
      83                 :         291 : }
      84                 :             : 
      85                 :             : } // tk::
        

Generated by: LCOV version 2.0-1