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.

114 lines
2.5 KiB

  1. #pragma once
  2. #include <vector>
  3. #include <ostream>
  4. #include "yaml-cpp/yaml.h"
  5. typedef std::string expressions;
  6. enum class ConfigType : char {
  7. Label = 'L',
  8. Formula = 'F',
  9. Module = 'M'
  10. };
  11. struct Configuration
  12. {
  13. expressions expressions_;
  14. std::string derivation_;
  15. ConfigType type_ {ConfigType::Label};
  16. bool overwrite_;
  17. Configuration() = default;
  18. Configuration(std::string expression, std::string derivation, ConfigType type, bool overwrite = false) : expressions_(expression), derivation_(derivation), type_(type), overwrite_(overwrite) {}
  19. ~Configuration() = default;
  20. Configuration(const Configuration&) = default;
  21. friend std::ostream& operator << (std::ostream& os, const Configuration& config) {
  22. os << "Configuration with Type: " << static_cast<char>(config.type_) << std::endl;
  23. os << "\tExpression=" << config.expressions_ << std::endl;
  24. return os << "\tDerviation=" << config.derivation_;
  25. }
  26. };
  27. struct Label {
  28. private:
  29. public:
  30. std::string text_;
  31. std::string label_;
  32. bool overwrite_;
  33. friend std::ostream& operator <<(std::ostream &os, const Label& label);
  34. };
  35. struct Formula {
  36. private:
  37. public:
  38. std::string formula_;
  39. std::string content_;
  40. bool overwrite_;
  41. friend std::ostream& operator << (std::ostream &os, const Formula& formula);
  42. };
  43. struct Action {
  44. public:
  45. std::string action_;
  46. std::string guard_;
  47. std::string update_;
  48. bool overwrite_;
  49. friend std::ostream& operator << (std::ostream& os, const Action& action);
  50. };
  51. struct Module {
  52. public:
  53. std::vector<Action> actions_;
  54. std::string module_;
  55. friend std::ostream& operator << (std::ostream& os, const Module& module);
  56. };
  57. template<>
  58. struct YAML::convert<Module> {
  59. static YAML::Node encode(const Module& rhs);
  60. static bool decode(const YAML::Node& node, Module& rhs);
  61. };
  62. template<>
  63. struct YAML::convert<Action> {
  64. static YAML::Node encode(const Action& rhs);
  65. static bool decode(const YAML::Node& node, Action& rhs);
  66. };
  67. template<>
  68. struct YAML::convert<Label> {
  69. static YAML::Node encode(const Label& rhs);
  70. static bool decode(const YAML::Node& node, Label& rhs);
  71. };
  72. template<>
  73. struct YAML::convert<Formula> {
  74. static YAML::Node encode(const Formula& rhs);
  75. static bool decode(const YAML::Node& node, Formula& rhs);
  76. };
  77. struct YamlConfigParser {
  78. public:
  79. YamlConfigParser(std::string file) : file_(file) {}
  80. YamlConfigParser(const YamlConfigParser&) = delete;
  81. ~YamlConfigParser() = default;
  82. std::vector<Configuration> parseConfiguration();
  83. private:
  84. std::string file_;
  85. };