schema_editor/comdel/domain/comdelvalidator.h

55 lines
1.7 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"
2022-05-19 22:44:40 +00:00
#include "library.h"
2022-04-10 12:23:18 +00:00
namespace domain {
struct ValidationError
{
2022-05-08 13:47:47 +00:00
ComponentInstance *instance;
2022-04-10 12:23:18 +00:00
InstanceAttribute *attribute;
Action::ActionType type;
std::string message;
};
struct ValidationContext {
2022-05-08 13:47:47 +00:00
ComponentInstance *instance;
2022-04-10 12:23:18 +00:00
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);
2022-05-19 22:44:40 +00:00
std::vector<ValidationError> validateInstanceCount(Schema &schema, Library& library, ValidationContext context);
std::vector<ValidationError> validatePinConnections(Schema &schema, Library& library, ValidationContext context);
2022-05-15 09:17:05 +00:00
ComdelValidator(std::vector<FunctionValidator*> validators) {
for(auto* validator: validators) {
validator->clear();
this->validators.insert(std::make_pair(validator->getName(), validator));
}
}
2022-04-10 12:23:18 +00:00
private:
2022-05-15 09:17:05 +00:00
std::map<std::string, FunctionValidator*> validators;
2022-04-10 12:23:18 +00:00
2022-05-15 09:17:05 +00:00
std::string populateMessage(string message, ValidationContext context);
2022-04-10 12:23:18 +00:00
2022-05-15 09:17:05 +00:00
string replacePlaceholder(string message, const string name, Value value);
2022-05-19 22:44:40 +00:00
bool connectionExists(Schema &schema, shared_ptr <ComponentInstance> &component, Pin &pin);
2022-04-10 12:23:18 +00:00
};
}
#endif //COMDEL_VALIDATOR_H