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

4
src/models/Dtmc.h

@ -19,6 +19,8 @@
#include "src/exceptions/InvalidArgumentException.h"
#include "src/utility/CommandLine.h"
#include "src/models/Model.h"
namespace storm {
namespace models {
@ -28,7 +30,7 @@ namespace models {
* labeled with atomic propositions.
*/
template <class T>
class Dtmc {
class Dtmc : public storm::models::Model {
public:
//! 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"
@ -10,12 +10,12 @@
namespace storm {
namespace parser {
AutoTransitionParser::AutoTransitionParser(const std::string& filename)
AutoParser::AutoParser(const std::string& filename)
: 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 (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
std::string::size_type extpos = filename.rfind(".");
@ -75,9 +75,9 @@ TransitionType AutoTransitionParser::analyzeFilename(const std::string& filename
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
MappedFile file(filename.c_str());
char* buf = file.data;
@ -90,7 +90,11 @@ std::pair<TransitionType,TransitionType> AutoTransitionParser::analyzeContent(co
if (strncmp(hint, "dtmc", sizeof(hint)) == 0) hintType = DTMC;
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

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

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