Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BEOrderParser.cpp
Go to the documentation of this file.
2
3#include <boost/algorithm/string.hpp>
4
8#include "storm/io/file.h"
10
11namespace storm::dft {
12namespace parser {
13
14template<typename ValueType>
15std::vector<size_t> BEOrderParser<ValueType>::parseBEOrder(std::string const& filename, storm::dft::storage::DFT<ValueType> const& dft) {
16 std::ifstream file;
17 storm::io::openFile(filename, file);
18
19 std::string line;
20 size_t lineNo = 0;
21 std::vector<size_t> beOrder;
22 try {
23 while (storm::io::getline(file, line)) {
24 ++lineNo;
25 boost::trim(line);
26 if (line.empty()) {
27 // Empty line
28 continue;
29 }
30
31 // Split line into tokens w.r.t. whitespace
32 boost::trim(line);
33 std::vector<std::string> tokens;
34 boost::split(tokens, line, boost::is_any_of(" \t"), boost::token_compress_on);
35
36 for (auto const& token : tokens) {
37 std::string name = DFTGalileoParser<ValueType>::parseName(token);
38 STORM_LOG_THROW(dft.existsName(name), storm::exceptions::InvalidArgumentException, "No DFT element with name '" << name << "' exists.");
39 auto element = dft.getElement(dft.getIndex(name));
40 STORM_LOG_THROW(element->isBasicElement(), storm::exceptions::InvalidArgumentException, "Element '" << name << "' is not a BE.");
41 beOrder.push_back(element->id());
42 }
43 }
44 } catch (storm::exceptions::BaseException const& exception) {
45 STORM_LOG_THROW(false, storm::exceptions::FileIoException, "A parsing exception occurred in line " << lineNo << ": " << exception.what());
46 }
48 STORM_LOG_THROW(beOrder.size() == dft.nrBasicElements(), storm::exceptions::InvalidArgumentException,
49 "DFT has " << dft.nrBasicElements() << " BEs but " << beOrder.size() << " BE names where given.");
50 return beOrder;
51}
52
53// Explicitly instantiate the class.
54template class BEOrderParser<double>;
56
57} // namespace parser
58} // namespace storm::dft
Parser for BE order from text file.
static std::vector< size_t > parseBEOrder(std::string const &filename, storm::dft::storage::DFT< ValueType > const &dft)
Parse BE order from given file.
static std::string parseName(std::string const &name)
Parse element name (strip quotation marks, etc.).
Represents a Dynamic Fault Tree.
Definition DFT.h:52
size_t nrBasicElements() const
Definition DFT.h:99
DFTElementCPointer getElement(size_t index) const
Get a pointer to an element in the DFT.
Definition DFT.h:189
bool existsName(std::string const &name) const
Check whether an element with the given name exists.
Definition DFT.cpp:678
size_t getIndex(std::string const &name) const
Get id for the given element name.
Definition DFT.cpp:683
This class represents the base class of all exception classes.
virtual const char * what() const NOEXCEPT override
Retrieves the message associated with this exception.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::basic_istream< CharT, Traits > & getline(std::basic_istream< CharT, Traits > &input, std::basic_string< CharT, Traits, Allocator > &str)
Overloaded getline function which handles different types of newline ( and \r).
Definition file.h:80
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