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: 23 39 59.0 %
Date: 2019-06-26 00:32:26 Functions: 19 54 35.2 %
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 <iostream>
      16             : #include <sstream>
      17             : #include <string>
      18             : 
      19             : #include "mcrl2/core/print.h"
      20             : 
      21             : namespace mcrl2
      22             : {
      23             : 
      24             : namespace core
      25             : {
      26             : 
      27             : namespace detail
      28             : {
      29             : 
      30             : /// \brief Creates a string representation of a container using the pp pretty print function.
      31             : /// \param v A container
      32             : /// \param message A string
      33             : /// \param print_index If true, an index is written in front of each term
      34             : template <typename Container>
      35         578 : 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)
      36             : {
      37        1156 :   std::ostringstream out;
      38         578 :   if (!message.empty())
      39             :   {
      40           0 :     out << "--- " << message << "---" << std::endl;
      41             :   }
      42         578 :   out << begin_marker;
      43         578 :   if (boundary_spaces)
      44             :   {
      45         530 :     out << " ";
      46             :   }
      47         578 :   int index = 0;
      48        2372 :   for (auto i = v.begin(); i != v.end(); ++i)
      49             :   {
      50        1794 :     if (print_index)
      51             :     {
      52           0 :       out << index++ << " ";
      53           0 :       out << *i;
      54           0 :       out << std::endl;
      55             :     }
      56             :     else
      57             :     {
      58        1794 :       if (i != v.begin())
      59             :       {
      60        1223 :         out << ", ";
      61             :       }
      62        1794 :       out << *i;
      63             :     }
      64             :   }
      65         578 :   if (boundary_spaces)
      66             :   {
      67         530 :     out << " ";
      68             :   }
      69         578 :   out << end_marker;
      70        1156 :   return out.str();
      71             : }
      72             : 
      73             : /// \brief Creates a string representation of a container.
      74             : /// \param v A container
      75             : /// \param message A string
      76             : /// \param print_index If true, an index is written in front of each term
      77             : template <typename Container>
      78           4 : std::string print_list(const Container& v, const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
      79             : {
      80           4 :   return print_container(v, "[", "]", message, print_index, boundary_spaces);
      81             : }
      82             : 
      83             : /// \brief Creates a string representation of a container.
      84             : /// \param v A container
      85             : /// \param message A string
      86             : /// \param print_index If true, an index is written in front of each term
      87             : template <typename Container>
      88         573 : std::string print_set(const Container& v, const std::string& message = "", bool print_index = false, bool boundary_spaces = true)
      89             : {
      90         573 :   return print_container(v, "{", "}", message, print_index, boundary_spaces);
      91             : }
      92             : 
      93             : /// \brief Creates a string representation of a map
      94             : /// \param v A map container
      95             : /// \param message A string
      96             : /// \param print_index If true, an index is written in front of each term
      97             : template <typename MapContainer>
      98           0 : std::string print_map(const MapContainer& v, const std::string& message = "")
      99             : {
     100           0 :   std::ostringstream out;
     101           0 :   if (!message.empty())
     102             :   {
     103           0 :     out << "--- " << message << "---" << std::endl;
     104             :   }
     105           0 :   out << "{";
     106           0 :   for (auto i = v.begin(); i != v.end(); ++i)
     107             :   {
     108           0 :     if (i != v.begin())
     109             :     {
     110           0 :       out << ", ";
     111             :     }
     112           0 :     out << i->first << " -> " << i->second;
     113             :   }
     114           0 :   out << "}";
     115           0 :   return out.str();
     116             : }
     117             : 
     118             : /// \brief Prints a comma separated list of the elements of v. If v is empty, the empty string is returned.
     119             : /// \param v A container
     120             : template <typename Container>
     121           1 : std::string print_arguments(const Container& v)
     122             : {
     123           1 :   if (v.empty())
     124             :   {
     125           0 :     return "";
     126             :   }
     127           1 :   return print_container(v, "(", ")", "", false, false);
     128             : }
     129             : 
     130             : } // namespace detail
     131             : 
     132             : } // namespace core
     133             : 
     134             : } // namespace mcrl2
     135             : 
     136             : #endif // MCRL2_CORE_DETAIL_PRINT_UTILITY_H

Generated by: LCOV version 1.12