Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
cli.cpp
Go to the documentation of this file.
1#include "storm/utility/cli.h"
2
3#include <boost/algorithm/string.hpp>
8
9namespace storm {
10namespace utility {
11namespace cli {
12
14 char temp[512];
15 return (GetCurrentDir(temp, 512 - 1) ? std::string(temp) : std::string(""));
16}
17
18std::map<storm::expressions::Variable, storm::expressions::Expression> parseConstantDefinitionString(storm::expressions::ExpressionManager const& manager,
19 std::string const& constantDefinitionString) {
20 std::map<storm::expressions::Variable, storm::expressions::Expression> constantDefinitions;
21 std::set<storm::expressions::Variable> definedConstants;
22
23 if (!constantDefinitionString.empty()) {
24 // Parse the string that defines the undefined constants of the model and make sure that it contains exactly
25 // one value for each undefined constant of the model.
26 std::vector<std::string> definitions;
27 boost::split(definitions, constantDefinitionString, boost::is_any_of(","));
28 for (auto& definition : definitions) {
29 boost::trim(definition);
30
31 // Check whether the token could be a legal constant definition.
32 std::size_t positionOfAssignmentOperator = definition.find('=');
33 STORM_LOG_THROW(positionOfAssignmentOperator != std::string::npos, storm::exceptions::WrongFormatException,
34 "Illegal constant definition string: syntax error.");
35
36 // Now extract the variable name and the value from the string.
37 std::string constantName = definition.substr(0, positionOfAssignmentOperator);
38 boost::trim(constantName);
39 std::string value = definition.substr(positionOfAssignmentOperator + 1);
40 boost::trim(value);
41
42 // Check whether the constant is a legal undefined constant of the program and if so, of what type it is.
43 if (manager.hasVariable(constantName)) {
44 // Get the actual constant and check whether it's in fact undefined.
45 auto const& variable = manager.getVariable(constantName);
46 STORM_LOG_THROW(definedConstants.find(variable) == definedConstants.end(), storm::exceptions::WrongFormatException,
47 "Illegally trying to define constant '" << constantName << "' twice.");
48 definedConstants.insert(variable);
49
50 if (manager.hasVariable(value)) {
51 auto const& valueVariable = manager.getVariable(value);
53 variable.getType() == valueVariable.getType(), storm::exceptions::WrongFormatException,
54 "Illegally trying to define constant '" << constantName << "' by constant '" << valueVariable.getName() << " of different type.");
55 constantDefinitions[variable] = valueVariable.getExpression();
56 } else if (variable.hasBooleanType()) {
57 if (value == "true") {
58 constantDefinitions[variable] = manager.boolean(true);
59 } else if (value == "false") {
60 constantDefinitions[variable] = manager.boolean(false);
61 } else {
62 throw storm::exceptions::WrongFormatException() << "Illegal value for boolean constant: " << value << ".";
63 }
64 } else if (variable.hasIntegerType()) {
65 int_fast64_t integerValue = std::stoll(value);
66 constantDefinitions[variable] = manager.integer(integerValue);
67 } else if (variable.hasRationalType()) {
68 try {
69 storm::RationalNumber rationalValue = storm::utility::convertNumber<storm::RationalNumber>(value);
70 constantDefinitions[variable] = manager.rational(rationalValue);
71 } catch (std::exception& e) {
72 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException,
73 "Illegal constant definition string '" << constantName << "=" << value << "': " << e.what());
74 }
75 }
76 } else {
77 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException,
78 "Illegal constant definition string: unknown undefined constant '" << constantName << "'.");
79 }
80 }
81 }
82
83 return constantDefinitions;
84}
85
86std::vector<std::string> parseCommaSeparatedStrings(std::string const& input) {
87 std::vector<std::string> result;
88 if (!input.empty()) {
89 boost::split(result, input, boost::is_any_of(","));
90 for (auto& entry : result) {
91 boost::trim(entry);
92 }
93 }
94 return result;
95}
96
97} // namespace cli
98} // namespace utility
99} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::vector< std::string > parseCommaSeparatedStrings(std::string const &input)
Definition cli.cpp:86
std::string getCurrentWorkingDirectory()
Definition cli.cpp:13
std::map< storm::expressions::Variable, storm::expressions::Expression > parseConstantDefinitionString(storm::expressions::ExpressionManager const &manager, std::string const &constantDefinitionString)
Definition cli.cpp:18
LabParser.cpp.
Definition cli.cpp:18