21 checkSyntax(filename, file);
27 char const* buf = file.
getData();
30 parseLabelNames(filename, labeling, buf);
33 parseDeterministicLabelAssignments(filename, labeling, buf);
39 uint_fast64_t choiceCount, std::string
const& filename, boost::optional<std::vector<uint_fast64_t>>
const& nondeterministicChoiceIndices) {
41 checkSyntax(filename, file);
47 char const* buf = file.
getData();
50 parseLabelNames(filename, labeling, buf);
53 if (nondeterministicChoiceIndices) {
54 parseNonDeterministicLabelAssignments(filename, labeling, nondeterministicChoiceIndices.get(), buf);
56 parseDeterministicLabelAssignments(filename, labeling, buf);
63 char const* buf = file.
getData();
66 bool foundDecl =
false, foundEnd =
false;
70 while (buf[0] !=
'\0') {
81 if (strncmp(buf,
"#DECLARATION", cnt) == 0) {
84 }
else if (strncmp(buf,
"#END", cnt) == 0) {
93 "Error while parsing " << filename <<
": File header is corrupted (Token #DECLARATION missing - case sensitive).");
95 "Error while parsing " << filename <<
": File header is corrupted (Token #END missing - case sensitive).");
100 char proposition[128];
105 while (buf[0] !=
'\0') {
113 if (cnt >=
sizeof(proposition)) {
115 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": Atomic proposition with length > " << (
sizeof(proposition) - 1) <<
" was found.");
116 throw storm::exceptions::WrongFormatException()
117 <<
"Error while parsing " << filename <<
": Atomic proposition with length > " << (
sizeof(proposition) - 1) <<
" was found.";
119 }
else if (cnt > 0) {
121 if (strncmp(buf,
"#DECLARATION", cnt) == 0)
125 if (strncmp(buf,
"#END", cnt) == 0)
129 strncpy(proposition, buf, cnt);
130 proposition[cnt] =
'\0';
145 uint_fast64_t state = 0;
146 uint_fast64_t lastState = (uint_fast64_t)-1;
147 uint_fast64_t
const startIndexComparison = lastState;
149 char proposition[128];
151 while (buf[0] !=
'\0') {
157 if (state <= lastState && lastState != startIndexComparison) {
158 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": State " << state <<
" was found but has already been read or skipped previously.");
159 throw storm::exceptions::WrongFormatException()
160 <<
"Error while parsing " << filename <<
": State " << state <<
" was found but has already been read or skipped previously.";
163 while ((buf[0] !=
'\r') && (buf[0] !=
'\n') && (buf[0] !=
'\0')) {
169 if (buf[0] ==
'\n' || buf[0] ==
'\r')
174 strncpy(proposition, buf, cnt);
175 proposition[cnt] =
'\0';
179 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": Atomic proposition" << proposition <<
" was found but not declared.");
180 throw storm::exceptions::WrongFormatException()
181 <<
"Error while parsing " << filename <<
": Atomic proposition" << proposition <<
" was found but not declared.";
198 std::vector<uint_fast64_t>
const& nondeterministicChoiceIndices,
char const*& buf) {
199 uint_fast64_t
const startIndexComparison = (uint_fast64_t)-1;
200 uint_fast64_t state = 0;
201 uint_fast64_t lastState = startIndexComparison;
202 uint_fast64_t localChoice = 0;
203 uint_fast64_t lastLocalChoice = startIndexComparison;
205 char proposition[128];
207 while (buf[0] !=
'\0') {
214 if (state != lastState) {
215 lastLocalChoice = startIndexComparison;
219 STORM_LOG_THROW(state >= lastState || lastState == startIndexComparison, storm::exceptions::WrongFormatException,
220 "Error while parsing " << filename <<
": State " << state <<
" and Choice " << localChoice
221 <<
" were found but the state has already been read or skipped previously.");
222 STORM_LOG_THROW(state != lastState || localChoice > lastLocalChoice || lastLocalChoice == startIndexComparison, storm::exceptions::WrongFormatException,
223 "Error while parsing " << filename <<
": State " << state <<
" and Choice " << localChoice
224 <<
" were found but the choice has already been read or skipped previously.");
226 uint_fast64_t
const globalChoice = nondeterministicChoiceIndices[state] + localChoice;
227 STORM_LOG_THROW(globalChoice < nondeterministicChoiceIndices[state + 1], storm::exceptions::WrongFormatException,
228 "Error while parsing " << filename <<
": Invalid choice index " << localChoice <<
" at state " << state <<
".");
230 while ((buf[0] !=
'\r') && (buf[0] !=
'\n') && (buf[0] !=
'\0')) {
236 if (buf[0] ==
'\n' || buf[0] ==
'\r')
241 strncpy(proposition, buf, cnt);
242 proposition[cnt] =
'\0';
246 "Error while parsing " << filename <<
": Atomic proposition" << proposition <<
" was found but not declared.");
254 lastLocalChoice = localChoice;
This class manages the labeling of the choice space with a number of (atomic) labels.
void addLabelToChoice(std::string const &label, uint64_t choice)
Adds a label to a given choice.
A base class managing the labeling of items with a number of (atomic) labels.
virtual bool isChoiceLabeling() const
void addLabel(std::string const &label)
Adds a new label to the labelings.
ChoiceLabeling const & asChoiceLabeling() const
bool containsLabel(std::string const &label) const
Checks whether a label is registered within this labeling.
virtual bool isStateLabeling() const
StateLabeling const & asStateLabeling() const
This class manages the labeling of the state space with a number of (atomic) labels.
void addLabelToState(std::string const &label, storm::storage::sparse::state_type state)
Adds a label to a given state.
Opens a file and maps it to memory providing a char* containing the file content.
char const * getData() const
Returns a pointer to the beginning of the mapped file data.
static storm::models::sparse::ChoiceLabeling parseChoiceLabeling(uint_fast64_t choiceCount, std::string const &filename, boost::optional< std::vector< uint_fast64_t > > const &nondeterministicChoiceIndices=boost::none)
Parses the given file and returns the resulting choice labeling.
static storm::models::sparse::StateLabeling parseAtomicPropositionLabeling(uint_fast64_t stateCount, std::string const &filename)
Parses the given file and returns the resulting state labeling.
#define STORM_LOG_ERROR(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
char const * skipWord(char const *buf)
Skips all numbers, letters and special characters.
uint_fast64_t checked_strtol(char const *str, char const **end)
Calls strtol() internally and checks if the new pointer is different from the original one,...
char const * trimWhitespaces(char const *buf)
Skips spaces, tabs, newlines and carriage returns.