LCOV - code coverage report
Current view: top level - core/include/mcrl2/core - load_aterm.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 3 4 75.0 %
Date: 2024-04-26 03:18:02 Functions: 1 1 100.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/load_aterm.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_CORE_LOAD_ATERM_H
      13             : #define MCRL2_CORE_LOAD_ATERM_H
      14             : 
      15             : #include "mcrl2/atermpp/aterm_io_binary.h"
      16             : #include "mcrl2/atermpp/aterm_io_text.h"
      17             : 
      18             : namespace mcrl2 {
      19             : 
      20             : namespace core {
      21             : 
      22             : namespace detail {
      23             : 
      24             : inline
      25           6 : std::string file_source(const std::string& filename)
      26             : {
      27           6 :   if (filename.empty() || filename == "-")
      28             :   {
      29           0 :     return "standard input";
      30             :   }
      31           6 :   return filename;
      32             : }
      33             : 
      34             : } // namespace detail
      35             : 
      36             : /// \brief Attempts to read an aterm from a stream.
      37             : /// \param[in] stream The stream from which the term is read.
      38             : /// \param[in] binary A boolean indicating whether the stream is in binary of textual format.
      39             : /// \param[in] format The format that is being read (for example "LPS" or "PBES").
      40             : /// \param[in] source The source from which the stream originates (the empty string is used for an unknown source).
      41             : /// \param[in] transformer A funtion that is applied to every subterm of the read term.
      42             : /// \exception Throws a mcrl2 runtime error when an error occurs when reading the term.
      43             : inline
      44             : atermpp::aterm load_aterm(std::istream& stream,
      45             :   bool binary = true,
      46             :   const std::string& format = "aterm",
      47             :   const std::string& source = "",
      48             :   atermpp::aterm_transformer transformer = atermpp::identity)
      49             : {
      50             :   atermpp::aterm result;
      51             :   try
      52             :   {
      53             :     if (binary)
      54             :     {
      55             :       atermpp::binary_aterm_istream(stream) >> transformer >> result;
      56             :     }
      57             :     else
      58             :     {
      59             :       atermpp::text_aterm_istream(stream) >> transformer >> result;
      60             :     }
      61             :   }
      62             :   catch (std::exception &e)
      63             :   {
      64             :     if (source.empty())
      65             :     {
      66             :       throw mcrl2::runtime_error("Failed to read a valid " + format + " from the input.\n" + e.what());
      67             :     }
      68             :     else 
      69             :     {
      70             :       throw mcrl2::runtime_error("Failed to read a valid " + format + " from the input " + source + ".\n" + e.what());
      71             :     }
      72             :   }
      73             :   return result;
      74             : }
      75             : 
      76             : } // namespace core
      77             : 
      78             : } // namespace mcrl2
      79             : 
      80             : #endif // MCRL2_CORE_LOAD_ATERM_H

Generated by: LCOV version 1.14