#include "ConfigYaml.h" #include std::ostream& operator <<(std::ostream &os, const Label& label) { os << "\"" << label.label_ << "\"" << "=" << label.text_; return os; } std::ostream& operator << (std::ostream &os, const Formula& formula) { os << formula.formula_ << "=" << formula.content_; return os; } std::ostream& operator << (std::ostream& os, const Action& action) { os << action.action_; return os; } std::ostream& operator << (std::ostream& os, const Constant& constant) { os << "const " << constant.type_ << " " << constant.constant_ << " = " << constant.value_; return os; } std::ostream& operator << (std::ostream& os, const Module& module) { os << "Module: " << module.module_ << std::endl; for (auto& action : module.actions_) { os << action << std::endl; } return os; } std::string Label::createExpression() const { if (overwrite_) { return "label \"" + label_ + "\" = " + text_ + Configuration::overwrite_identifier_; } return "label \"" + label_ + "\" = " + text_ + Configuration::configuration_identifier_; } std::string Formula::createExpression() const { if (overwrite_) { return "formula " + formula_ + " = " + content_ + Configuration::overwrite_identifier_; } return "formula " + formula_ + " = " + content_ + Configuration::configuration_identifier_; } std::string Action::createExpression() const { if (overwrite_) { return action_ + "\t" + guard_ + "-> " + update_ + Configuration::overwrite_identifier_; } return "\t" + action_ + "\t" + guard_ + "-> " + update_+ Configuration::configuration_identifier_; } std::string Constant::createExpression() const { if (overwrite_) { return "const " + type_ + " " + constant_ + " = " + value_ + Configuration::overwrite_identifier_; } return "const " + type_ + " " + constant_ + " = " + value_ + Configuration::configuration_identifier_; } YAML::Node YAML::convert::encode(const Module& rhs) { YAML::Node node; node.push_back(rhs.module_); node.push_back(rhs.actions_); return node; } bool YAML::convert::decode(const YAML::Node& node, Module& rhs) { if (!node.Type() == NodeType::Map) { return false; } rhs.actions_ = node["actions"].as>(); rhs.module_ = node["module"].as(); return true; } YAML::Node YAML::convert::encode(const Action& rhs) { YAML::Node node; node.push_back(rhs.action_); node.push_back(rhs.guard_); node.push_back(rhs.overwrite_); node.push_back(rhs.update_); return node; } bool YAML::convert::decode(const YAML::Node& node, Action& rhs) { if (!node.Type() == NodeType::Map) { return false; } rhs.action_ = node["action"].as(); rhs.guard_ = node["guard"].as(); rhs.update_ = node["update"].as(); if (node["overwrite"]) { rhs.overwrite_ = node["overwrite"].as(); } if (node["index"]) { rhs.index_ = node["index"].as(); } return true; } YAML::Node YAML::convert