Browse Source

first steps towards an AutoParser

renamed AutoTransitionParser to AutoParser
created new base class for all models
main
gereon 12 years ago
parent
commit
1776f8ce12
  1. 4
      src/models/Ctmc.h
  2. 4
      src/models/Dtmc.h
  3. 13
      src/models/Model.h
  4. 24
      src/parser/AutoParser.cpp
  5. 23
      src/parser/AutoParser.h

4
src/models/Ctmc.h

@ -18,6 +18,8 @@
#include "src/storage/SparseMatrix.h" #include "src/storage/SparseMatrix.h"
#include "src/exceptions/InvalidArgumentException.h" #include "src/exceptions/InvalidArgumentException.h"
#include "src/models/Model.h"
namespace storm { namespace storm {
namespace models { namespace models {
@ -27,7 +29,7 @@ namespace models {
* labeled with atomic propositions. * labeled with atomic propositions.
*/ */
template <class T> template <class T>
class Ctmc {
class Ctmc : public storm::models::Model {
public: public:
//! Constructor //! Constructor

4
src/models/Dtmc.h

@ -19,6 +19,8 @@
#include "src/exceptions/InvalidArgumentException.h" #include "src/exceptions/InvalidArgumentException.h"
#include "src/utility/CommandLine.h" #include "src/utility/CommandLine.h"
#include "src/models/Model.h"
namespace storm { namespace storm {
namespace models { namespace models {
@ -28,7 +30,7 @@ namespace models {
* labeled with atomic propositions. * labeled with atomic propositions.
*/ */
template <class T> template <class T>
class Dtmc {
class Dtmc : public storm::models::Model {
public: public:
//! Constructor //! Constructor

13
src/models/Model.h

@ -0,0 +1,13 @@
#ifndef STORM_MODELS_MODEL_H_
#define STORM_MODELS_MODEL_H_
namespace storm {
namespace models {
class Model {
};
} // namespace models
} // namespace storm
#endif /* STORM_MODELS_MODEL_H_ */

24
src/parser/AutoTransitionParser.cpp → src/parser/AutoParser.cpp

@ -1,4 +1,4 @@
#include "src/parser/AutoTransitionParser.h"
#include "src/parser/AutoParser.h"
#include "src/exceptions/WrongFileFormatException.h" #include "src/exceptions/WrongFileFormatException.h"
@ -10,12 +10,12 @@
namespace storm { namespace storm {
namespace parser { namespace parser {
AutoTransitionParser::AutoTransitionParser(const std::string& filename)
AutoParser::AutoParser(const std::string& filename)
: type(Unknown) { : type(Unknown) {
TransitionType name = this->analyzeFilename(filename);
std::pair<TransitionType,TransitionType> content = this->analyzeContent(filename);
TransitionType hint = content.first, transitions = content.second;
ModelType name = this->analyzeFilename(filename);
std::pair<ModelType,ModelType> content = this->analyzeContent(filename);
ModelType hint = content.first, transitions = content.second;
if (hint == Unknown) { if (hint == Unknown) {
if (name == transitions) this->type = name; if (name == transitions) this->type = name;
@ -60,8 +60,8 @@ AutoTransitionParser::AutoTransitionParser(const std::string& filename)
} }
} }
TransitionType AutoTransitionParser::analyzeFilename(const std::string& filename) {
TransitionType type = Unknown;
ModelType AutoParser::analyzeFilename(const std::string& filename) {
ModelType type = Unknown;
// find file extension // find file extension
std::string::size_type extpos = filename.rfind("."); std::string::size_type extpos = filename.rfind(".");
@ -75,9 +75,9 @@ TransitionType AutoTransitionParser::analyzeFilename(const std::string& filename
return type; return type;
} }
std::pair<TransitionType,TransitionType> AutoTransitionParser::analyzeContent(const std::string& filename) {
std::pair<ModelType,ModelType> AutoParser::analyzeContent(const std::string& filename) {
TransitionType hintType = Unknown, transType = Unknown;
ModelType hintType = Unknown, transType = Unknown;
// Open file // Open file
MappedFile file(filename.c_str()); MappedFile file(filename.c_str());
char* buf = file.data; char* buf = file.data;
@ -90,7 +90,11 @@ std::pair<TransitionType,TransitionType> AutoTransitionParser::analyzeContent(co
if (strncmp(hint, "dtmc", sizeof(hint)) == 0) hintType = DTMC; if (strncmp(hint, "dtmc", sizeof(hint)) == 0) hintType = DTMC;
else if (strncmp(hint, "ndtmc", sizeof(hint)) == 0) hintType = NDTMC; else if (strncmp(hint, "ndtmc", sizeof(hint)) == 0) hintType = NDTMC;
return std::pair<TransitionType,TransitionType>(hintType, transType);
// check transition format
// todo.
return std::pair<ModelType,ModelType>(hintType, transType);
} }
} //namespace parser } //namespace parser

23
src/parser/AutoTransitionParser.h → src/parser/AutoParser.h

@ -14,19 +14,19 @@ namespace storm {
namespace parser { namespace parser {
/*! /*!
* @brief Enumeration of all supported types of transition systems.
* @brief Enumeration of all supported types of models.
*/ */
enum TransitionType {
enum ModelType {
Unknown, DTMC, NDTMC Unknown, DTMC, NDTMC
}; };
std::ostream& operator<<(std::ostream& os, const TransitionType type)
std::ostream& operator<<(std::ostream& os, const ModelType type)
{ {
switch (type) { switch (type) {
case Unknown: os << "Unknown"; break; case Unknown: os << "Unknown"; break;
case DTMC: os << "DTMC"; break; case DTMC: os << "DTMC"; break;
case NDTMC: os << "NDTMC"; break; case NDTMC: os << "NDTMC"; break;
default: os << "Invalid TransitionType";
default: os << "Invalid ModelType";
} }
return os; return os;
} }
@ -46,35 +46,34 @@ std::ostream& operator<<(std::ostream& os, const TransitionType type)
* parser. * parser.
* Otherwise, it will issue an error. * Otherwise, it will issue an error.
*/ */
class AutoTransitionParser : Parser {
class AutoParser : Parser {
public: public:
AutoTransitionParser(const std::string& filename);
AutoParser(const std::string& filename);
/*! /*!
* @brief Returns the type of transition system that was detected. * @brief Returns the type of transition system that was detected.
*/ */
TransitionType getTransitionType() {
ModelType getModelType() {
return this->type; return this->type;
} }
// TODO: is this actually safe with shared_ptr?
template <typename T> template <typename T>
T* getParser() { T* getParser() {
return dynamic_cast<T*>( this->parser ); return dynamic_cast<T*>( this->parser );
} }
~AutoTransitionParser() {
~AutoParser() {
delete this->parser; delete this->parser;
} }
private: private:
TransitionType analyzeFilename(const std::string& filename);
std::pair<TransitionType,TransitionType> analyzeContent(const std::string& filename);
ModelType analyzeFilename(const std::string& filename);
std::pair<ModelType,ModelType> analyzeContent(const std::string& filename);
/*! /*!
* @brief Type of the transition system. * @brief Type of the transition system.
*/ */
TransitionType type;
ModelType type;
/*! /*!
* @brief Pointer to a parser that has parsed the given transition system. * @brief Pointer to a parser that has parsed the given transition system.
Loading…
Cancel
Save