1 // File: Model_Validator.cpp
3 // Author: Mikhail PONIKAROV
5 #include <Model_Validator.h>
6 #include <ModelAPI_Feature.h>
7 #include <Events_Error.h>
11 void Model_ValidatorsFactory::registerValidator(
12 const string& theID, ModelAPI_Validator* theValidator)
14 if (myIDs.find(theID) != myIDs.end()) {
15 Events_Error::send(string("Validator ") + theID + " is already registered");
17 myIDs[theID] = theValidator;
21 void Model_ValidatorsFactory::assignValidator(const string& theID, const string& theFeatureID)
24 map<string, ModelAPI_Validator*>::iterator aVal = myIDs.find(theID);
25 if (aVal == myIDs.end()) {
27 string("Validator ") + theID + " for feature " + theFeatureID + " was not registered");
30 if (myFeatures.find(theFeatureID) != myFeatures.end()) {
32 string("Validator for feature ") + theFeatureID + " is already registered");
36 myFeatures[theFeatureID] = aVal->second;
39 void Model_ValidatorsFactory::assignValidator(const string& theID,
40 const string& theFeatureID, const string& theAttrID, const list<string>& theArguments)
43 map<string, ModelAPI_Validator*>::iterator aVal = myIDs.find(theID);
44 if (aVal == myIDs.end()) {
46 string("Validator ") + theID + " for feature " + theFeatureID + " was not registered");
49 // create feature-structures if not exist
50 map<string, map<string, pair<ModelAPI_Validator*, list<string> > > >::iterator
51 aFeature = myAttrs.find(theFeatureID);
52 if (aFeature == myAttrs.end()) {
53 myAttrs[theFeatureID] = map<string, pair<ModelAPI_Validator*, list<string> > >();
54 aFeature = myAttrs.find(theFeatureID);
56 // add attr-structure if not exist, or generate error if already exist
57 map<string, pair<ModelAPI_Validator*, list<string> > >::iterator
58 anAttr = aFeature->second.find(theAttrID);
59 if (anAttr == aFeature->second.end()) {
61 aFeature->second[theAttrID] =
62 pair<ModelAPI_Validator*, list<string> >(aVal->second, theArguments);
66 string("Validator ") + theID + " for feature " + theFeatureID +
67 "attribute " + theAttrID + " is already registered");
72 const ModelAPI_Validator* Model_ValidatorsFactory::validator(const string& theFeatureID) const
74 map<string, ModelAPI_Validator*>::const_iterator aFeature = myFeatures.find(theFeatureID);
75 if (aFeature != myFeatures.cend())
76 return aFeature->second;
77 return NULL; // not found
80 /*bool Model_ValidatorsFactory::validate(
81 const boost::shared_ptr<ModelAPI_Feature>& theFeature, const string& theAttrID ) const
83 map<string, map<string, pair<ModelAPI_Validator*, list<string> > > >::const_iterator
84 aFeature = myAttrs.find(theFeature->getKind());
85 if (aFeature == myAttrs.cend()) return true; // feature is not found
86 map<string, pair<ModelAPI_Validator*, list<string> > >::const_iterator
87 anAttr = aFeature->second.find(theAttrID);
88 if (anAttr == aFeature->second.cend()) return true; // attribute is not found
89 return anAttr->second.first->validate(theFeature, theAttrID, anAttr->second.second);
92 Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory()