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>
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
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
45
inline
46
void
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
mcrl2::runtime_error
Standard exception class for reporting runtime errors.
Definition
exception.h:27
exception.h
Exception classes for use in libraries and tools.
mcrl2::utilities::detail::write_text
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
mcrl2::utilities::detail::read_text
std::string read_text(const std::string &filename)
Reads text from the file filename, or from stdin if filename equals "-".
Definition
io.h:27
mcrl2::utilities::read_text
std::string read_text(const std::string &filename, bool warn=false)
Read text from a file.
Definition
text_utility.cpp:66
mcrl2
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition
indexed_set.h:72
text_utility.h
String manipulation functions.
utilities
include
mcrl2
utilities
detail
io.h
Generated by
1.9.7