LCOV - code coverage report
Current view: top level - core/include/mcrl2/core - print_format.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 0 8 0.0 %
Date: 2020-02-13 00:44:47 Functions: 0 1 0.0 %
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/print_format.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_CORE_PRINT_FORMAT_H
      13             : #define MCRL2_CORE_PRINT_FORMAT_H
      14             : 
      15             : #include "mcrl2/utilities/exception.h"
      16             : #include <string>
      17             : 
      18             : namespace mcrl2 {
      19             : 
      20             : namespace core {
      21             : 
      22             : /// \brief print_format_type represents the available pretty print formats
      23             : typedef enum { print_default, print_internal } print_format_type;
      24             : 
      25             : /// \brief Print string representation of pretty print format
      26             : /// \param pp_format a pretty print format
      27             : /// \return string representation of the pretty print format
      28             : /// \throws mcrl2::runtime error if an unknown pretty print format
      29             : ///         is passed into the function.
      30             : inline
      31           0 : std::string pp_format_to_string(const print_format_type pp_format)
      32             : {
      33           0 :   switch (pp_format)
      34             :   {
      35           0 :     case print_default:
      36           0 :       return "default";
      37           0 :     case print_internal:
      38           0 :       return "internal";
      39           0 :     default:
      40           0 :       throw mcrl2::runtime_error("Unknown pretty print format");
      41             :   }
      42             : }
      43             : 
      44             : inline
      45             : std::ostream& operator<<(std::ostream& os, const print_format_type& pp_format)
      46             : {
      47             :   os << pp_format_to_string(pp_format);
      48             :   return os;
      49             : }
      50             : 
      51             : inline
      52             : print_format_type parse_pp_format(const std::string& s)
      53             : {
      54             :   if(s == "default")
      55             :   {
      56             :     return print_default;
      57             :   }
      58             :   else if(s == "internal")
      59             :   {
      60             :     return print_internal;
      61             :   }
      62             :   else
      63             :   {
      64             :     throw mcrl2::runtime_error("Unknown pretty print format " + s);
      65             :   }
      66             : }
      67             : 
      68             : inline
      69             : std::istream& operator>>(std::istream& is, print_format_type& f)
      70             : {
      71             :   try
      72             :   {
      73             :     std::string s;
      74             :     is >> s;
      75             :     f = parse_pp_format(s);
      76             :   }
      77             :   catch(mcrl2::runtime_error &)
      78             :   {
      79             :     is.setstate(std::ios_base::failbit);
      80             :   }
      81             :   return is;
      82             : }
      83             : 
      84             : } // namespace core
      85             : 
      86             : } // namespace mcrl2
      87             : 
      88             : #endif // MCRL2_CORE_PRINT_FORMAT_H

Generated by: LCOV version 1.13