Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ImcaMarkovAutomatonParser.cpp
Go to the documentation of this file.
2
3#include <fstream>
4#include <memory>
5
8#include "storm/io/file.h"
11
12namespace storm {
13namespace parser {
14
15template<typename ValueType>
16std::shared_ptr<storm::models::sparse::MarkovAutomaton<ValueType>> ImcaMarkovAutomatonParser<ValueType>::parseImcaFile(
17 std::string const& filename, ExplicitModelParserOptions const& options) {
18 // Open file and initialize result.
19 std::ifstream inputFileStream;
20 storm::io::openFile(filename, inputFileStream);
21
23
24 // Now try to parse the contents of the file.
25 std::string fileContent((std::istreambuf_iterator<char>(inputFileStream)), (std::istreambuf_iterator<char>()));
26 PositionIteratorType first(fileContent.begin());
27 PositionIteratorType iter = first;
28 PositionIteratorType last(fileContent.end());
29
30 try {
31 // Start parsing.
32 ImcaParserGrammar<ValueType> grammar(options);
33 bool succeeded = qi::phrase_parse(
34 iter, last, grammar, storm::spirit_encoding::space_type() | qi::lit("//") >> *(qi::char_ - (qi::eol | qi::eoi)) >> (qi::eol | qi::eoi), components);
35 STORM_LOG_THROW(succeeded, storm::exceptions::WrongFormatException, "Could not parse imca file.");
36 STORM_LOG_DEBUG("Parsed imca file successfully.");
37 } catch (qi::expectation_failure<PositionIteratorType> const& e) {
38 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, e.what_);
39 storm::io::closeFile(inputFileStream);
40 } catch (std::exception& e) {
41 // In case of an exception properly close the file before passing exception.
42 storm::io::closeFile(inputFileStream);
43 throw e;
44 }
45
46 // Close the stream in case everything went smoothly
47 storm::io::closeFile(inputFileStream);
48
49 // Build the model from the obtained model components
51 ->template as<storm::models::sparse::MarkovAutomaton<ValueType>>();
52}
53
55} // namespace parser
56} // namespace storm
boost::spirit::line_pos_iterator< BaseIteratorType > PositionIteratorType
static std::shared_ptr< storm::models::sparse::MarkovAutomaton< ValueType > > parseImcaFile(std::string const &filename, ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parses the given file under the assumption that it contains a Markov automaton specified in the imca ...
#define STORM_LOG_DEBUG(message)
Definition logging.h:21
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18
Contains all file parsers and helper classes.
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > buildModelFromComponents(storm::models::ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > &&components)
Definition builder.cpp:20