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.

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