mCRL2
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
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//
11
12#ifndef MCRL2_UTILITIES_DETAIL_IO_H
13#define MCRL2_UTILITIES_DETAIL_IO_H
14
15#include <fstream>
18
19namespace mcrl2 {
20
21namespace utilities {
22
23namespace detail {
24
26inline
27std::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
45inline
46void write_text(const std::string& filename, const std::string& text)
47{
48 if (filename.empty())
49 {
50 std::cout << text;
51 }
52 else
53 {
54 std::ofstream to(filename);
55 if (!to.good())
56 {
57 throw mcrl2::runtime_error("Could not write to filename " + filename);
58 }
59 to << text;
60 }
61}
62
63} // namespace detail
64
65} // namespace utilities
66
67} // namespace mcrl2
68
69#endif // MCRL2_UTILITIES_DETAIL_IO_H
Standard exception class for reporting runtime errors.
Definition exception.h:27
Exception classes for use in libraries and tools.
void write_text(const std::string &filename, const std::string &text)
Saves text to the file filename, or to stdout if filename equals "-".
Definition io.h:46
std::string read_text(const std::string &filename)
Reads text from the file filename, or from stdin if filename equals "-".
Definition io.h:27
std::string read_text(const std::string &filename, bool warn=false)
Read text from a file.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
String manipulation functions.