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(
12 const std::string& theID, 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(
22 const std::string& theID, 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, const std::string& theAttrID,
32 const std::list<std::string>& theArguments)
34 // create feature-structures if not exist
35 std::map<std::string, std::map<std::string, AttrValidators> >::iterator aFeature =
36 myAttrs.find(theFeatureID);
37 if (aFeature == myAttrs.end()) {
38 myAttrs[theFeatureID] = std::map<std::string, AttrValidators>();
39 aFeature = myAttrs.find(theFeatureID);
41 // add attr-structure if not exist, or generate error if already exist
42 std::map<std::string, AttrValidators>::iterator anAttr = aFeature->second.find(theAttrID);
43 if (anAttr == aFeature->second.end()) {
44 aFeature->second[theAttrID] = AttrValidators();
46 aFeature->second[theAttrID].insert(
47 std::pair<std::string, std::list<std::string> >(theID, theArguments));
50 void Model_ValidatorsFactory::validators(
51 const std::string& theFeatureID, std::list<ModelAPI_Validator*>& theResult ) const
53 std::map<std::string, std::set<std::string> >::const_iterator aFeature =
54 myFeatures.find(theFeatureID);
55 if (aFeature != myFeatures.cend()) {
56 std::set<std::string>::const_iterator aValIter = aFeature->second.cbegin();
57 for(; aValIter != aFeature->second.cend(); aValIter++) {
58 std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(*aValIter);
59 if (aFound == myIDs.end()) {
60 Events_Error::send(std::string("Validator ") + *aValIter + " was not registered");
62 theResult.push_back(aFound->second);
68 void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
69 const std::string& theAttrID, std::list<ModelAPI_Validator*>& theValidators,
70 std::list<std::list<std::string> >& theArguments) const
72 std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeature =
73 myAttrs.find(theFeatureID);
74 if (aFeature != myAttrs.cend()) {
75 std::map<std::string, AttrValidators>::const_iterator anAttr =
76 aFeature->second.find(theAttrID);
77 if (anAttr != aFeature->second.end()) {
78 AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
79 for(; aValIter != anAttr->second.cend(); aValIter++) {
80 std::map<std::string, ModelAPI_Validator*>::const_iterator aFound =
81 myIDs.find(aValIter->first);
82 if (aFound == myIDs.end()) {
83 Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
85 theValidators.push_back(aFound->second);
86 theArguments.push_back(aValIter->second);
93 Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory()
95 registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator);
96 registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator);
97 registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator);
98 registerValidator("Model_FeatureValidator", new Model_FeatureValidator);
102 const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& theID) const
104 std::map<std::string, ModelAPI_Validator*>::const_iterator aIt = myIDs.find(theID);
105 if (aIt != myIDs.end()) {