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.

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