Browse Source

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

main
gereon 13 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. * @param type Model type.
* @return Output stream os. * @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) { switch (type) {
case storm::models::Unknown: os << "Unknown"; break; case storm::models::Unknown: os << "Unknown"; break;
case storm::models::DTMC: os << "DTMC"; 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::MDP: os << "MDP"; break;
case storm::models::CTMDP: os << "CTMDP"; break; case storm::models::CTMDP: os << "CTMDP"; break;
default: os << "Invalid ModelType"; break; default: os << "Invalid ModelType"; break;
} }
return os; return os;
} }

31
src/parser/AutoParser.cpp

@ -1,13 +1,11 @@
#include "src/parser/AutoParser.h" #include "src/parser/AutoParser.h"
#include <string>
#include <cctype>
#include "src/exceptions/WrongFileFormatException.h" #include "src/exceptions/WrongFileFormatException.h"
#include "src/models/AbstractModel.h" #include "src/models/AbstractModel.h"
#include "src/parser/DtmcParser.h" #include "src/parser/DtmcParser.h"
//#include "NonDeterministicSparseTransitionParser.h"
#include <string>
#include <cctype>
namespace storm { namespace storm {
namespace parser { namespace parser {
@ -15,18 +13,16 @@ namespace parser {
AutoParser::AutoParser(std::string const & transitionSystemFile, std::string const & labelingFile, AutoParser::AutoParser(std::string const & transitionSystemFile, std::string const & labelingFile,
std::string const & stateRewardFile, std::string const & transitionRewardFile) std::string const & stateRewardFile, std::string const & transitionRewardFile)
: model(nullptr) { : model(nullptr) {
storm::models::ModelType type = this->analyzeHint(transitionSystemFile); storm::models::ModelType type = this->analyzeHint(transitionSystemFile);
if (type == storm::models::Unknown) { if (type == storm::models::Unknown) {
LOG4CPLUS_ERROR(logger, "Could not determine file type of " << transitionSystemFile << "."); 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."); 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; throw storm::exceptions::WrongFileFormatException() << "Could not determine type of file " << transitionSystemFile;
} } else {
else {
LOG4CPLUS_INFO(logger, "Model type seems to be " << type); LOG4CPLUS_INFO(logger, "Model type seems to be " << type);
} }
// Do actual parsing // Do actual parsing
switch (type) { switch (type) {
case storm::models::DTMC: { case storm::models::DTMC: {
@ -40,24 +36,23 @@ AutoParser::AutoParser(std::string const & transitionSystemFile, std::string con
break; break;
case storm::models::CTMDP: case storm::models::CTMDP:
break; 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 AutoParser::analyzeHint(const std::string& filename) {
storm::models::ModelType hintType = storm::models::Unknown; storm::models::ModelType hintType = storm::models::Unknown;
// Open file // Open file
MappedFile file(filename.c_str()); MappedFile file(filename.c_str());
char* buf = file.data; char* buf = file.data;
// parse hint // parse hint
char hint[128]; char hint[128];
sscanf(buf, "%s\n", hint); sscanf(buf, "%s\n", hint);
for (char* c = hint; *c != '\0'; c++) *c = toupper(*c); for (char* c = hint; *c != '\0'; c++) *c = toupper(*c);
// check hint // check hint
if (strncmp(hint, "DTMC", sizeof(hint)) == 0) hintType = storm::models::DTMC; if (strncmp(hint, "DTMC", sizeof(hint)) == 0) hintType = storm::models::DTMC;
else if (strncmp(hint, "CTMC", sizeof(hint)) == 0) hintType = storm::models::CTMC; 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; return hintType;
} }
} //namespace parser } // namespace parser
} //namespace storm } // 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. * 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) { if (strncmp(buf, "STATES ", 7) != 0) {
LOG4CPLUS_ERROR(logger, "Expected \"STATES\" but got \"" << std::string(buf, 0, 16) << "\"."); LOG4CPLUS_ERROR(logger, "Expected \"STATES\" but got \"" << std::string(buf, 0, 16) << "\".");
return 0; return 0;
@ -151,7 +151,7 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
/* /*
* Read file header, extract number of states. * 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 " buf += 7; // skip "STATES "
checked_strtol(buf, &buf); checked_strtol(buf, &buf);
buf = trimWhitespaces(buf); buf = trimWhitespaces(buf);
@ -197,8 +197,9 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
if (fixDeadlocks) { if (fixDeadlocks) {
this->matrix->addNextValue(node, node, 1); this->matrix->addNextValue(node, node, 1);
LOG4CPLUS_WARN(logger, "Warning while parsing " << filename << ": node " << node << " has no outgoing transitions. A self-loop was inserted."); 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; lastrow = row;

12
src/parser/DtmcParser.cpp

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

4
src/parser/DtmcParser.h

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

17
src/parser/Parser.cpp

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

5
src/utility/IoUtility.cpp

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

26
src/utility/Settings.cpp

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