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.

131 lines
2.9 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. static const std::string overwrite_identifier_;
  13. static const std::string configuration_identifier_;
  14. std::string module_ {};
  15. std::string expression_{};
  16. std::string identifier_{};
  17. int index_{};
  18. ConfigType type_ {ConfigType::Label};
  19. bool overwrite_ {false};
  20. Configuration() = default;
  21. Configuration(std::string expression
  22. , std::string identifier
  23. , ConfigType type
  24. , bool overwrite = false
  25. , std::string module = ""
  26. , int index = 0) : expression_(expression), identifier_(identifier), type_(type), overwrite_(overwrite), module_{module}, index_(index) {}
  27. ~Configuration() = default;
  28. Configuration(const Configuration&) = default;
  29. friend std::ostream& operator << (std::ostream& os, const Configuration& config) {
  30. os << "Configuration with Type: " << static_cast<char>(config.type_) << std::endl;
  31. return os << "\tExpression=" << config.expression_ << std::endl;
  32. }
  33. };
  34. struct Label {
  35. private:
  36. public:
  37. std::string text_;
  38. std::string label_;
  39. bool overwrite_{false};
  40. std::string createExpression() const;
  41. friend std::ostream& operator <<(std::ostream &os, const Label& label);
  42. };
  43. struct Formula {
  44. private:
  45. public:
  46. std::string formula_;
  47. std::string content_;
  48. bool overwrite_ {false};
  49. std::string createExpression() const;
  50. friend std::ostream& operator << (std::ostream &os, const Formula& formula);
  51. };
  52. struct Action {
  53. public:
  54. std::string action_;
  55. std::string guard_;
  56. std::string update_;
  57. int index_{0};
  58. bool overwrite_ {false};
  59. std::string createExpression() const;
  60. friend std::ostream& operator << (std::ostream& os, const Action& action);
  61. };
  62. struct Module {
  63. public:
  64. std::vector<Action> actions_;
  65. std::string module_;
  66. friend std::ostream& operator << (std::ostream& os, const Module& module);
  67. };
  68. template<>
  69. struct YAML::convert<Module> {
  70. static YAML::Node encode(const Module& rhs);
  71. static bool decode(const YAML::Node& node, Module& rhs);
  72. };
  73. template<>
  74. struct YAML::convert<Action> {
  75. static YAML::Node encode(const Action& rhs);
  76. static bool decode(const YAML::Node& node, Action& rhs);
  77. };
  78. template<>
  79. struct YAML::convert<Label> {
  80. static YAML::Node encode(const Label& rhs);
  81. static bool decode(const YAML::Node& node, Label& rhs);
  82. };
  83. template<>
  84. struct YAML::convert<Formula> {
  85. static YAML::Node encode(const Formula& rhs);
  86. static bool decode(const YAML::Node& node, Formula& rhs);
  87. };
  88. struct YamlConfigParser {
  89. public:
  90. YamlConfigParser(std::string file) : file_(file) {}
  91. YamlConfigParser(const YamlConfigParser&) = delete;
  92. ~YamlConfigParser() = default;
  93. std::vector<Configuration> parseConfiguration();
  94. private:
  95. std::string file_;
  96. };