LCOV - code coverage report
Current view: top level - utilities/include/mcrl2/utilities/detail - io.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 0 9 0.0 %
Date: 2024-05-04 03:44:52 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/utilities/detail/io.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_UTILITIES_DETAIL_IO_H
      13             : #define MCRL2_UTILITIES_DETAIL_IO_H
      14             : 
      15             : #include <fstream>
      16             : #include "mcrl2/utilities/exception.h"
      17             : #include "mcrl2/utilities/text_utility.h"
      18             : 
      19             : namespace mcrl2 {
      20             : 
      21             : namespace utilities {
      22             : 
      23             : namespace detail {
      24             : 
      25             : /// \brief Reads text from the file filename, or from stdin if filename equals "-".
      26             : inline
      27             : std::string read_text(const std::string& filename)
      28             : {
      29             :   if (filename.empty())
      30             :   {
      31             :     return utilities::read_text(std::cin);
      32             :   }
      33             :   else
      34             :   {
      35             :     std::ifstream from(filename.c_str());
      36             :     if (!from.good())
      37             :     {
      38             :       throw mcrl2::runtime_error("Could not read from filename " + filename);
      39             :     }
      40             :     return utilities::read_text(from);
      41             :   }
      42             : }
      43             : 
      44             : /// \brief Saves text to the file filename, or to stdout if filename equals "-".
      45             : inline
      46           0 : void write_text(const std::string& filename, const std::string& text)
      47             : {
      48           0 :   if (filename.empty())
      49             :   {
      50           0 :     std::cout << text;
      51             :   }
      52             :   else
      53             :   {
      54           0 :     std::ofstream to(filename);
      55           0 :     if (!to.good())
      56             :     {
      57           0 :       throw mcrl2::runtime_error("Could not write to filename " + filename);
      58             :     }
      59           0 :     to << text;
      60           0 :   }
      61           0 : }
      62             : 
      63             : } // namespace detail
      64             : 
      65             : } // namespace utilities
      66             : 
      67             : } // namespace mcrl2
      68             : 
      69             : #endif // MCRL2_UTILITIES_DETAIL_IO_H

Generated by: LCOV version 1.14