mCRL2
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1// Author(s): Sjoerd Cranen; simplified by Jan Friso Groote
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_LPS_IO_H
13#define MCRL2_LPS_IO_H
14
18
19#include <fstream>
20
21namespace mcrl2
22{
23
24namespace lps
25{
26
28atermpp::aterm_ostream& operator<<(atermpp::aterm_ostream& stream, const specification& spec);
29atermpp::aterm_ostream& operator<<(atermpp::aterm_ostream& stream, const stochastic_specification& spec);
30
32atermpp::aterm_istream& operator>>(atermpp::aterm_istream& stream, specification& spec);
33atermpp::aterm_istream& operator>>(atermpp::aterm_istream& stream, stochastic_specification& spec);
34
41template <typename Specification>
42void save_lps(const Specification& spec, std::ostream& stream, const std::string& target = "")
43{
44 mCRL2log(log::debug) << "Saving LPS" << (target.empty() ? "" : " to " + target) << ".\n";
45 atermpp::binary_aterm_ostream(stream) << spec;
46}
47
53template <typename Specification>
54void load_lps(Specification& spec, std::istream& stream, const std::string& source = "")
55{
56 mCRL2log(log::debug) << "Loading LPS" << (source.empty() ? "" : " from " + source) << ".\n";
57
58 if constexpr (std::is_same<Specification, specification>::value)
59 {
60 stochastic_specification stoch_spec;
61 atermpp::binary_aterm_istream(stream) >> stoch_spec;
62 spec=remove_stochastic_operators(stoch_spec);
63 }
64 else
65 {
66 atermpp::binary_aterm_istream(stream) >> spec;
67 }
68}
69
73template <typename Specification>
74void save_lps(const Specification& spec, const std::string& filename)
75{
76 if (filename.empty() || filename == "-")
77 {
78 save_lps(spec, std::cout, "standard output");
79 return;
80 }
81
82 std::ofstream ofs(filename, std::ios_base::binary);
83 if (!ofs.good())
84 {
85 throw mcrl2::runtime_error("Could not open file " + filename + ".");
86 }
87 save_lps(spec, ofs, filename);
88}
89
93
94template <typename Specification>
95void load_lps(Specification& spec, const std::string& filename)
96{
97 if (filename.empty() || filename == "-")
98 {
99 load_lps(spec, std::cin, "standard input");
100 return;
101 }
102
103 std::ifstream ifs(filename, std::ios_base::binary);
104 if (!ifs.good())
105 {
106 throw mcrl2::runtime_error("Could not open file " + filename + ".");
107 }
108 load_lps(spec, ifs, filename);
109}
110
111} // namespace lps
112
113} // namespace mcrl2
114
115#endif // MCRL2_LPS_IO_H
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
Definition aterm_io.h:59
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
Definition aterm_io.h:48
Reads terms from a stream in the steamable binary aterm format.
Writes terms in a streamable binary aterm format to an output stream.
Standard exception class for reporting runtime errors.
Definition exception.h:27
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
void save_lps(const Specification &spec, std::ostream &stream, const std::string &target="")
Save an LPS in the format specified.
Definition io.h:42
std::ostream & operator<<(std::ostream &out, const action_summand &x)
specification remove_stochastic_operators(const stochastic_specification &spec)
Converts a stochastic specification to a specification. Throws an exception if non-empty distribution...
std::istream & operator>>(std::istream &is, exploration_strategy &strat)
void load_lps(Specification &spec, std::istream &stream, const std::string &source="")
Load LPS from file.
Definition io.h:54
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
The class specification.