1 // File: Model_Validator.cpp
3 // Author: Mikhail PONIKAROV
5 #include <Model_Validator.h>
6 #include <Model_ResultValidators.h>
7 #include <Model_FeatureValidator.h>
8 #include <ModelAPI_Feature.h>
9 #include <Events_Error.h>
11 void Model_ValidatorsFactory::registerValidator(const std::string& theID,
12 ModelAPI_Validator* theValidator)
14 if (myIDs.find(theID) != myIDs.end()) {
15 Events_Error::send(std::string("Validator ") + theID + " is already registered");
17 myIDs[theID] = theValidator;
21 void Model_ValidatorsFactory::assignValidator(const std::string& theID,
22 const std::string& theFeatureID)
24 if (myFeatures.find(theFeatureID) == myFeatures.end()) {
25 myFeatures[theFeatureID] = std::set<std::string>();
27 myFeatures[theFeatureID].insert(theID);
30 void Model_ValidatorsFactory::assignValidator(const std::string& theID,
31 const std::string& theFeatureID,
32 const std::string& theAttrID,
33 const std::list<std::string>& theArguments)
35 // create feature-structures if not exist
36 std::map<std::string, std::map<std::string, AttrValidators> >::iterator aFeature = myAttrs.find(
38 if (aFeature == myAttrs.end()) {
39 myAttrs[theFeatureID] = std::map<std::string, AttrValidators>();
40 aFeature = myAttrs.find(theFeatureID);
42 // add attr-structure if not exist, or generate error if already exist
43 std::map<std::string, AttrValidators>::iterator anAttr = aFeature->second.find(theAttrID);
44 if (anAttr == aFeature->second.end()) {
45 aFeature->second[theAttrID] = AttrValidators();
47 aFeature->second[theAttrID].insert(
48 std::pair<std::string, std::list<std::string> >(theID, theArguments));
51 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
52 std::list<ModelAPI_Validator*>& theResult) const
54 std::map<std::string, std::set<std::string> >::const_iterator aFeature = myFeatures.find(
56 if (aFeature != myFeatures.cend()) {
57 std::set<std::string>::const_iterator aValIter = aFeature->second.cbegin();
58 for (; aValIter != aFeature->second.cend(); aValIter++) {
59 std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(*aValIter);
60 if (aFound == myIDs.end()) {
61 Events_Error::send(std::string("Validator ") + *aValIter + " was not registered");
63 theResult.push_back(aFound->second);
67 addDefaultValidators(theResult);
70 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
71 const std::string& theAttrID,
72 std::list<ModelAPI_Validator*>& theValidators,
73 std::list<std::list<std::string> >& theArguments) const
75 std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeature = myAttrs
77 if (aFeature != myAttrs.cend()) {
78 std::map<std::string, AttrValidators>::const_iterator anAttr = aFeature->second.find(theAttrID);
79 if (anAttr != aFeature->second.end()) {
80 AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
81 for (; aValIter != anAttr->second.cend(); aValIter++) {
82 std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(
84 if (aFound == myIDs.end()) {
85 Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
87 theValidators.push_back(aFound->second);
88 theArguments.push_back(aValIter->second);
95 Model_ValidatorsFactory::Model_ValidatorsFactory()
96 : ModelAPI_ValidatorsFactory()
98 registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator);
99 registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator);
100 registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator);
101 registerValidator("Model_FeatureValidator", new Model_FeatureValidator);
104 const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& theID) const
106 std::map<std::string, ModelAPI_Validator*>::const_iterator aIt = myIDs.find(theID);
107 if (aIt != myIDs.end()) {
113 void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const
115 std::string anId = "Model_FeatureValidator";
116 std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(anId);
117 if(it == myIDs.end())
119 theValidators.push_back(it->second);