LCOV - code coverage report
Current view: top level - core/include/mcrl2/core/detail - print_utility.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 24 41 58.5 %
Date: 2024-03-08 02:52:28 Functions: 22 61 36.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Wieger Wesselink
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : /// \file mcrl2/core/detail/print_utility.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_CORE_DETAIL_PRINT_UTILITY_H
      13             : #define MCRL2_CORE_DETAIL_PRINT_UTILITY_H
      14             : 
      15             : #include "mcrl2/core/print.h"
      16             : 
      17             : namespace mcrl2
      18             : {
      19             : 
      20             : namespace core
      21             : {
      22             : 
      23             : namespace detail
      24             : {
      25             : 
      26             : /// \brief Creates a string representation of a container using the pp pretty print function.
      27             : /// \param v A container
      28             : /// \param message A string
      29             : /// \param print_index If true, an index is written in front of each term
      30             : template <typename Container>
      31         598 : std::string print_container(const Container& v, const std::string& begin_marker = "(", const std::string& end_marker = ")", const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
      32             : {
      33         598 :   std::ostringstream out;
      34         598 :   if (!message.empty())
      35             :   {
      36           0 :     out << "--- " << message << "---" << std::endl;
      37             :   }
      38         598 :   out << begin_marker;
      39         598 :   if (boundary_spaces)
      40             :   {
      41         550 :     out << " ";
      42             :   }
      43         598 :   int index = 0;
      44        2425 :   for (auto i = v.begin(); i != v.end(); ++i)
      45             :   {
      46        1827 :     if (print_index)
      47             :     {
      48           0 :       out << index++ << " ";
      49           0 :       out << *i;
      50           0 :       out << std::endl;
      51             :     }
      52             :     else
      53             :     {
      54        1827 :       if (i != v.begin())
      55             :       {
      56        1239 :         out << ", ";
      57             :       }
      58        1827 :       out << *i;
      59             :     }
      60             :   }
      61         598 :   if (boundary_spaces)
      62             :   {
      63         550 :     out << " ";
      64             :   }
      65         598 :   out << end_marker;
      66        1196 :   return out.str();
      67         598 : }
      68             : 
      69             : /// \brief Creates a string representation of a container.
      70             : /// \param v A container
      71             : /// \param message A string
      72             : /// \param print_index If true, an index is written in front of each term
      73             : template <typename Container>
      74           3 : std::string print_list(const Container& v, const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
      75             : {
      76           3 :   return print_container(v, "[", "]", message, print_index, boundary_spaces);
      77             : }
      78             : 
      79             : /// \brief Creates a string representation of a container.
      80             : /// \param v A container
      81             : /// \param message A string
      82             : /// \param print_index If true, an index is written in front of each term
      83             : template <typename Container>
      84         594 : std::string print_set(const Container& v, const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
      85             : {
      86         594 :   return print_container(v, "{", "}", message, print_index, boundary_spaces);
      87             : }
      88             : 
      89             : /// \brief Creates a string representation of a map
      90             : /// \param v A map container
      91             : /// \param message A string
      92             : /// \param print_index If true, an index is written in front of each term
      93             : template <typename MapContainer>
      94           0 : std::string print_map(const MapContainer& v, const std::string& message = "")
      95             : {
      96           0 :   std::ostringstream out;
      97           0 :   if (!message.empty())
      98             :   {
      99           0 :     out << "--- " << message << "---" << std::endl;
     100             :   }
     101           0 :   out << "{";
     102           0 :   for (auto i = v.begin(); i != v.end(); ++i)
     103             :   {
     104           0 :     if (i != v.begin())
     105             :     {
     106           0 :       out << ", ";
     107             :     }
     108           0 :     out << i->first << " -> " << i->second;
     109             :   }
     110           0 :   out << "}";
     111           0 :   return out.str();
     112           0 : }
     113             : 
     114             : /// \brief Prints a comma separated list of the elements of v. If v is empty, the empty string is returned.
     115             : /// \param v A container
     116             : template <typename Container>
     117           1 : std::string print_arguments(const Container& v)
     118             : {
     119           1 :   if (v.empty())
     120             :   {
     121           0 :     return "";
     122             :   }
     123           1 :   return print_container(v, "(", ")", "", false, false);
     124             : }
     125             : 
     126             : } // namespace detail
     127             : 
     128             : } // namespace core
     129             : 
     130             : } // namespace mcrl2
     131             : 
     132             : #endif // MCRL2_CORE_DETAIL_PRINT_UTILITY_H

Generated by: LCOV version 1.14