schema_editor/comdel/domain/rule.h

71 lines
1.4 KiB
C
Raw Permalink Normal View History

2022-03-31 21:20:41 +00:00
#ifndef DOMAIN_RULE_H
#define DOMAIN_RULE_H
2022-05-27 06:18:17 +00:00
#include "address_space.h"
2022-03-31 21:20:41 +00:00
#include "value.h"
2022-05-27 06:18:17 +00:00
#include "function_signature.h"
2022-03-31 21:20:41 +00:00
#include <map>
#include <string>
#include <vector>
#include <optional>
namespace domain {
2022-05-27 06:18:17 +00:00
struct RuleContext {
std::map<std::string, AddressSpace> addressSpaces;
std::map<std::string, Value> attributes;
std::map<std::string, FunctionValidator *> function;
};
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
class Condition {
bool negated;
std::string function;
std::vector<Value> params;
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
public:
Condition(std::string function, std::vector<Value> params, bool negated);
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
bool evaluate(RuleContext &context);
2022-03-31 21:20:41 +00:00
};
2022-05-27 06:18:17 +00:00
class Action {
public:
enum ActionType {
ERROR,
WARNING
};
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
private:
ActionType type;
std::string message;
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
public:
Action(ActionType type, std::string message);
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
ActionType getType();
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
std::string getMessage();
};
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
class IfStatement {
Condition condition;
Action action;
public:
IfStatement(Condition condition, Action action);
2022-03-31 21:20:41 +00:00
2022-05-27 06:18:17 +00:00
std::optional<Action> evaluate(RuleContext &context);
};
class Rule {
std::vector<IfStatement> statements;
public:
explicit Rule(std::vector<IfStatement> statements);
std::optional<Action> evaluate(RuleContext &context);
};
2022-03-31 21:20:41 +00:00
} // namespace domain
#endif // DOMAIN_RULE_H