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.

124 lines
2.7 KiB

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