schema_editor/comdel/domain/rule.h

71 lines
1.3 KiB
C
Raw Normal View History

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