You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

  1. #ifndef STORM_PARSER_AUTOPARSER_H_
  2. #define STORM_PARSER_AUTOPARSER_H_
  3. #include "src/models/AtomicPropositionsLabeling.h"
  4. #include "boost/integer/integer_mask.hpp"
  5. #include "src/parser/Parser.h"
  6. #include <memory>
  7. #include <iostream>
  8. #include <utility>
  9. namespace storm {
  10. namespace parser {
  11. /*!
  12. * @brief Enumeration of all supported types of transition systems.
  13. */
  14. enum TransitionType {
  15. Unknown, DTMC, NDTMC
  16. };
  17. std::ostream& operator<<(std::ostream& os, const TransitionType type)
  18. {
  19. switch (type) {
  20. case Unknown: os << "Unknown"; break;
  21. case DTMC: os << "DTMC"; break;
  22. case NDTMC: os << "NDTMC"; break;
  23. default: os << "Invalid TransitionType";
  24. }
  25. return os;
  26. }
  27. /*!
  28. * @brief Checks the given file and tries to call the correct parser.
  29. *
  30. * This parser analyzes the filename, an optional format hint (in the first
  31. * line of the file) and the transitions within the file.
  32. *
  33. * If all three (or two, if the hint is not given) are consistent, it will
  34. * call the appropriate parser.
  35. * If two guesses are the same but the third one contradicts, it will issue
  36. * a warning to the user and call the (hopefully) appropriate parser.
  37. * If all guesses differ, but a format hint is given, it will issue a
  38. * warning to the user and use the format hint to determine the correct
  39. * parser.
  40. * Otherwise, it will issue an error.
  41. */
  42. class AutoTransitionParser : Parser {
  43. public:
  44. AutoTransitionParser(const std::string& filename);
  45. /*!
  46. * @brief Returns the type of transition system that was detected.
  47. */
  48. TransitionType getTransitionType() {
  49. return this->type;
  50. }
  51. // TODO: is this actually safe with shared_ptr?
  52. template <typename T>
  53. T* getParser() {
  54. return dynamic_cast<T*>( this->parser );
  55. }
  56. ~AutoTransitionParser() {
  57. delete this->parser;
  58. }
  59. private:
  60. TransitionType analyzeFilename(const std::string& filename);
  61. std::pair<TransitionType,TransitionType> analyzeContent(const std::string& filename);
  62. /*!
  63. * @brief Type of the transition system.
  64. */
  65. TransitionType type;
  66. /*!
  67. * @brief Pointer to a parser that has parsed the given transition system.
  68. */
  69. Parser* parser;
  70. };
  71. } // namespace parser
  72. } // namespace storm
  73. #endif /* STORM_PARSER_AUTOPARSER_H_ */