Browse Source

made a run of cpplint and fixed some of the warnings...

tempestpy_adaptions
gereon 12 years ago
parent
commit
ea84f91cf3
  1. 5
      src/models/AbstractModel.cpp
  2. 31
      src/parser/AutoParser.cpp
  3. 7
      src/parser/DeterministicSparseTransitionParser.cpp
  4. 12
      src/parser/DtmcParser.cpp
  5. 4
      src/parser/DtmcParser.h
  6. 17
      src/parser/Parser.cpp
  7. 5
      src/utility/IoUtility.cpp
  8. 26
      src/utility/Settings.cpp

5
src/models/AbstractModel.cpp

@ -12,8 +12,7 @@
* @param type Model type.
* @return Output stream os.
*/
std::ostream& storm::models::operator<<(std::ostream& os, storm::models::ModelType const type)
{
std::ostream& storm::models::operator<<(std::ostream& os, storm::models::ModelType const type) {
switch (type) {
case storm::models::Unknown: os << "Unknown"; break;
case storm::models::DTMC: os << "DTMC"; break;
@ -21,6 +20,6 @@ std::ostream& storm::models::operator<<(std::ostream& os, storm::models::ModelTy
case storm::models::MDP: os << "MDP"; break;
case storm::models::CTMDP: os << "CTMDP"; break;
default: os << "Invalid ModelType"; break;
}
}
return os;
}

31
src/parser/AutoParser.cpp

@ -1,13 +1,11 @@
#include "src/parser/AutoParser.h"
#include <string>
#include <cctype>
#include "src/exceptions/WrongFileFormatException.h"
#include "src/models/AbstractModel.h"
#include "src/parser/DtmcParser.h"
//#include "NonDeterministicSparseTransitionParser.h"
#include <string>
#include <cctype>
namespace storm {
namespace parser {
@ -15,18 +13,16 @@ namespace parser {
AutoParser::AutoParser(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile, std::string const & transitionRewardFile)
: model(nullptr) {
storm::models::ModelType type = this->analyzeHint(transitionSystemFile);
if (type == storm::models::Unknown) {
LOG4CPLUS_ERROR(logger, "Could not determine file type of " << transitionSystemFile << ".");
LOG4CPLUS_ERROR(logger, "The first line of the file should contain a format hint. Please fix your file and try again.");
throw storm::exceptions::WrongFileFormatException() << "Could not determine type of file " << transitionSystemFile;
}
else {
} else {
LOG4CPLUS_INFO(logger, "Model type seems to be " << type);
}
// Do actual parsing
switch (type) {
case storm::models::DTMC: {
@ -40,24 +36,23 @@ AutoParser::AutoParser(std::string const & transitionSystemFile, std::string con
break;
case storm::models::CTMDP:
break;
default: ; // Unknown
default: ; // Unknown
}
if (! this->model) std::cout << "model is still null" << std::endl;
if (!this->model) std::cout << "model is still null" << std::endl;
}
storm::models::ModelType AutoParser::analyzeHint(const std::string& filename) {
storm::models::ModelType hintType = storm::models::Unknown;
// Open file
MappedFile file(filename.c_str());
char* buf = file.data;
// parse hint
char hint[128];
sscanf(buf, "%s\n", hint);
for (char* c = hint; *c != '\0'; c++) *c = toupper(*c);
// check hint
if (strncmp(hint, "DTMC", sizeof(hint)) == 0) hintType = storm::models::DTMC;
else if (strncmp(hint, "CTMC", sizeof(hint)) == 0) hintType = storm::models::CTMC;
@ -67,5 +62,5 @@ storm::models::ModelType AutoParser::analyzeHint(const std::string& filename) {
return hintType;
}
} //namespace parser
} //namespace storm
} // namespace parser
} // namespace storm

7
src/parser/DeterministicSparseTransitionParser.cpp

@ -50,7 +50,7 @@ uint_fast64_t DeterministicSparseTransitionParser::firstPass(char* buf, uint_fas
/*
* Check file header and extract number of transitions.
*/
buf = strchr(buf, '\n') + 1; // skip format hint
buf = strchr(buf, '\n') + 1; // skip format hint
if (strncmp(buf, "STATES ", 7) != 0) {
LOG4CPLUS_ERROR(logger, "Expected \"STATES\" but got \"" << std::string(buf, 0, 16) << "\".");
return 0;
@ -151,7 +151,7 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
/*
* Read file header, extract number of states.
*/
buf = strchr(buf, '\n') + 1; // skip format hint
buf = strchr(buf, '\n') + 1; // skip format hint
buf += 7; // skip "STATES "
checked_strtol(buf, &buf);
buf = trimWhitespaces(buf);
@ -197,8 +197,9 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
if (fixDeadlocks) {
this->matrix->addNextValue(node, node, 1);
LOG4CPLUS_WARN(logger, "Warning while parsing " << filename << ": node " << node << " has no outgoing transitions. A self-loop was inserted.");
} else {
LOG4CPLUS_ERROR(logger, "Error while parsing " << filename << ": node " << node << " has no outgoing transitions.");
}
else LOG4CPLUS_ERROR(logger, "Error while parsing " << filename << ": node " << node << " has no outgoing transitions.");
}
lastrow = row;

12
src/parser/DtmcParser.cpp

@ -5,10 +5,14 @@
* Author: thomas
*/
#include "DtmcParser.h"
#include "DeterministicSparseTransitionParser.h"
#include "AtomicPropositionLabelingParser.h"
#include "SparseStateRewardParser.h"
#include "src/parser/DtmcParser.h"
#include <string>
#include <vector>
#include "src/parser/DeterministicSparseTransitionParser.h"
#include "src/parser/AtomicPropositionLabelingParser.h"
#include "src/parser/SparseStateRewardParser.h"
namespace storm {
namespace parser {

4
src/parser/DtmcParser.h

@ -8,8 +8,8 @@
#ifndef DTMCPARSER_H_
#define DTMCPARSER_H_
#include "Parser.h"
#include "models/Dtmc.h"
#include "src/parser/Parser.h"
#include "src/models/Dtmc.h"
namespace storm {
namespace parser {

17
src/parser/Parser.cpp

@ -2,6 +2,7 @@
#include <iostream>
#include <cstring>
#include <string>
#include "src/exceptions/FileIoException.h"
#include "src/exceptions/WrongFileFormatException.h"
@ -59,7 +60,7 @@ char* storm::parser::Parser::trimWhitespaces(char* buf) {
while ((*buf == ' ') || (*buf == '\t') || (*buf == '\n') || (*buf == '\r')) buf++;
return buf;
}
/*!
* Will stat the given file, open it and map it to memory.
* If anything of this fails, an appropriate exception is raised
@ -86,9 +87,9 @@ storm::parser::MappedFile::MappedFile(const char* filename) {
LOG4CPLUS_ERROR(logger, "Error in open(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in open()");
}
this->data = (char*) mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0);
if (this->data == (char*)-1) {
this->data = reinterpret_cast<char*>(mmap(NULL, this->st.st_size, PROT_READ, MAP_PRIVATE, this->file, 0));
if (this->data == reinterpret_cast<char*>(-1)) {
close(this->file);
LOG4CPLUS_ERROR(logger, "Error in mmap(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in mmap()");
@ -103,20 +104,20 @@ storm::parser::MappedFile::MappedFile(const char* filename) {
LOG4CPLUS_ERROR(logger, "Error in _stat(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in stat()");
}
this->file = CreateFileA(filename, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (this->file == INVALID_HANDLE_VALUE) {
LOG4CPLUS_ERROR(logger, "Error in CreateFileA(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in CreateFileA()");
}
this->mapping = CreateFileMappingA(this->file, NULL, PAGE_READONLY, (DWORD)(st.st_size >> 32), (DWORD)st.st_size, NULL);
if (this->mapping == NULL) {
CloseHandle(this->file);
LOG4CPLUS_ERROR(logger, "Error in CreateFileMappingA(" << filename << ").");
throw exceptions::FileIoException("storm::parser::MappedFile Error in CreateFileMappingA()");
}
this->data = static_cast<char*>(MapViewOfFile(this->mapping, FILE_MAP_READ, 0, 0, this->st.st_size));
if (this->data == NULL) {
CloseHandle(this->mapping);
@ -127,7 +128,7 @@ storm::parser::MappedFile::MappedFile(const char* filename) {
this->dataend = this->data + this->st.st_size;
#endif
}
/*!
* Will unmap the data and close the file.
*/

5
src/utility/IoUtility.cpp

@ -6,11 +6,12 @@
*/
#include "src/utility/IoUtility.h"
#include "src/parser/DeterministicSparseTransitionParser.h"
#include "src/parser/AtomicPropositionLabelingParser.h"
#include <fstream>
#include "src/parser/DeterministicSparseTransitionParser.h"
#include "src/parser/AtomicPropositionLabelingParser.h"
namespace storm {
namespace utility {

26
src/utility/Settings.cpp

@ -7,13 +7,17 @@
#include "src/utility/Settings.h"
#include "src/exceptions/BaseException.h"
#include <boost/algorithm/string/join.hpp>
#include <utility>
#include <map>
#include <string>
#include <list>
#include "src/exceptions/BaseException.h"
#include "log4cplus/logger.h"
#include "log4cplus/loggingmacros.h"
extern log4cplus::Logger logger;
#include <boost/algorithm/string/join.hpp>
namespace storm {
namespace settings {
@ -54,22 +58,22 @@ Settings::Settings(int const argc, char const * const argv[], char const * const
// Check module triggers, add corresponding options.
std::map< std::string, std::list< std::string > > options;
for (auto it : Settings::modules) {
options[it.first.first].push_back(it.first.second);
}
for (auto it : options) {
std::stringstream str;
str << "select " << it.first << " module (" << boost::algorithm::join(it.second, ", ") << ")";
Settings::desc->add_options()
(it.first.c_str(), bpo::value<std::string>()->default_value(it.second.front()), str.str().c_str())
;
}
// Perform first parse run.
this->firstRun(argc, argv, filename);
// Buffer for items to be deleted.
std::list< std::pair< std::string, std::string > > deleteQueue;
// Check module triggers.
@ -83,15 +87,15 @@ Settings::Settings(int const argc, char const * const argv[], char const * const
}
}
for (auto it : deleteQueue) Settings::modules.erase(it);
// Stop if help is set.
if (this->vm.count("help") > 0) {
return;
}
// Perform second run.
this->secondRun(argc, argv, filename);
// Finalize parsed options, check for specified requirements.
bpo::notify(this->vm);
LOG4CPLUS_DEBUG(logger, "Finished loading config.");
@ -190,5 +194,5 @@ std::ostream& help(std::ostream& os) {
return os;
}
} // namespace settings
} // namespace storm
} // namespace settings
} // namespace storm
Loading…
Cancel
Save