schema_editor/comdel/domain/comdelvalidator.h

44 lines
1.2 KiB
C
Raw Normal View History

2022-04-10 12:23:18 +00:00
#ifndef COMDEL_VALIDATOR_H
#define COMDEL_VALIDATOR_H
#include "instance.h"
#include "schema.h"
namespace domain {
struct ValidationError
{
Instance *instance;
InstanceAttribute *attribute;
Action::ActionType type;
std::string message;
};
struct ValidationContext {
Instance *instance;
InstanceAttribute *attribute;
std::map<std::string, AddressSpace> addressSpaces;
std::map<std::string, Value> attributes;
};
class ComdelValidator
{
public:
std::vector<ValidationError> validateSchema(Schema& schema, ValidationContext context);
std::vector<ValidationError> validateComponent(ComponentInstance *instance, ValidationContext context);
std::vector<ValidationError> validateAttribute(InstanceAttribute *attribute, ValidationContext context);
std::optional<ValidationError> validateRule(Rule rule, ValidationContext context);
ComdelValidator(std::map<std::string, FunctionCallback> callbacks): callbacks(callbacks) {}
private:
std::map<std::string, FunctionCallback> callbacks;
std::string populateMessage(string basicString, ValidationContext context);
string replacePlaceholder(string basicString, const string basicString1, Value value);
};
}
#endif //COMDEL_VALIDATOR_H