1 // File: Model_Validator.cpp
3 // Author: Mikhail PONIKAROV
5 #include <Model_Validator.h>
6 #include <Model_FeatureValidator.h>
7 #include <ModelAPI_Feature.h>
8 #include <Events_Error.h>
10 void Model_ValidatorsFactory::registerValidator(const std::string& theID,
11 ModelAPI_Validator* theValidator)
13 if (myIDs.find(theID) != myIDs.end()) {
14 Events_Error::send(std::string("Validator ") + theID + " is already registered");
16 myIDs[theID] = theValidator;
20 void Model_ValidatorsFactory::assignValidator(const std::string& theID,
21 const std::string& theFeatureID)
23 if (myFeatures.find(theFeatureID) == myFeatures.end()) {
24 myFeatures[theFeatureID] = AttrValidators();
26 if (myFeatures[theFeatureID].find(theID) != myFeatures[theFeatureID].end()) {
27 //Events_Error::send(std::string("Validator ") + theID +
28 // " for feature " + theFeatureID + "is already registered");
30 myFeatures[theFeatureID][theID] = std::list<std::string>();
34 void Model_ValidatorsFactory::assignValidator(const std::string& theID,
35 const std::string& theFeatureID,
36 const std::list<std::string>& theArguments)
38 if (myFeatures.find(theFeatureID) == myFeatures.end()) {
39 myFeatures[theFeatureID] = AttrValidators();
42 if (myFeatures[theFeatureID].find(theID) != myFeatures[theFeatureID].end()) {
43 //Events_Error::send(std::string("Validator ") + theID +
44 // " for feature " + theFeatureID + "is already registered");
46 myFeatures[theFeatureID][theID] = theArguments;
50 void Model_ValidatorsFactory::assignValidator(const std::string& theID,
51 const std::string& theFeatureID,
52 const std::string& theAttrID,
53 const std::list<std::string>& theArguments)
55 // create feature-structures if not exist
56 std::map<std::string, std::map<std::string, AttrValidators> >::iterator aFeature = myAttrs.find(
58 if (aFeature == myAttrs.end()) {
59 myAttrs[theFeatureID] = std::map<std::string, AttrValidators>();
60 aFeature = myAttrs.find(theFeatureID);
62 // add attr-structure if not exist, or generate error if already exist
63 std::map<std::string, AttrValidators>::iterator anAttr = aFeature->second.find(theAttrID);
64 if (anAttr == aFeature->second.end()) {
65 aFeature->second[theAttrID] = AttrValidators();
67 aFeature->second[theAttrID][theID] = theArguments;
70 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
71 std::list<ModelAPI_Validator*>& theResult,
72 std::list<std::list<std::string> >& theArguments) const
74 std::map<std::string, AttrValidators>::const_iterator aFeature = myFeatures.find(theFeatureID);
75 if (aFeature != myFeatures.cend()) {
76 AttrValidators::const_iterator aValIter = aFeature->second.cbegin();
77 for (; aValIter != aFeature->second.cend(); aValIter++) {
78 std::map<std::string, ModelAPI_Validator*>::const_iterator aFound =
79 myIDs.find(aValIter->first);
80 if (aFound == myIDs.end()) {
81 Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
83 theResult.push_back(aFound->second);
84 theArguments.push_back(aValIter->second);
88 addDefaultValidators(theResult);
91 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
92 const std::string& theAttrID,
93 std::list<ModelAPI_Validator*>& theValidators,
94 std::list<std::list<std::string> >& theArguments) const
96 std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeature = myAttrs
98 if (aFeature != myAttrs.cend()) {
99 std::map<std::string, AttrValidators>::const_iterator anAttr = aFeature->second.find(theAttrID);
100 if (anAttr != aFeature->second.end()) {
101 AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
102 for (; aValIter != anAttr->second.cend(); aValIter++) {
103 std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(
105 if (aFound == myIDs.end()) {
106 Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
108 theValidators.push_back(aFound->second);
109 theArguments.push_back(aValIter->second);
116 Model_ValidatorsFactory::Model_ValidatorsFactory()
117 : ModelAPI_ValidatorsFactory()
119 registerValidator("Model_FeatureValidator", new Model_FeatureValidator);
122 const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& theID) const
124 std::map<std::string, ModelAPI_Validator*>::const_iterator aIt = myIDs.find(theID);
125 if (aIt != myIDs.end()) {
131 void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const
133 std::string anId = "Model_FeatureValidator";
134 std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(anId);
135 if(it == myIDs.end())
137 theValidators.push_back(it->second);