71 lines
1.4 KiB
C++
71 lines
1.4 KiB
C++
#ifndef DOMAIN_RULE_H
|
|
#define DOMAIN_RULE_H
|
|
|
|
#include "address_space.h"
|
|
#include "value.h"
|
|
#include "function_signature.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, FunctionValidator *> 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:
|
|
explicit Rule(std::vector<IfStatement> statements);
|
|
|
|
std::optional<Action> evaluate(RuleContext &context);
|
|
};
|
|
|
|
} // namespace domain
|
|
|
|
#endif // DOMAIN_RULE_H
|