1 // File: Model_Validator.hxx
3 // Author: Mikhail PONIKAROV
5 #ifndef Model_Validator_H_
6 #define Model_Validator_H_
9 #include <ModelAPI_Validator.h>
13 /**\class Model_ValidatorsFactory
15 * \breif Manages the registered validators
17 * Allows to get a validator by the feature identifier and
18 * the attribute identifier (if attribute is validated).
19 * All accessible validators mustbe registered by the ID string first.
20 * The instance of this factory can be get in the PluginManager.
21 * Keeps the validator objects alive and just returns one of it by request.
22 * All the needed information is provided to the validator as an argument,
23 * this allows to work with them independently from the feature specific object.
25 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
28 std::map<std::string, ModelAPI_Validator*> myIDs; ///< map from ID to registered validator
29 /// validators IDs to list of arguments
30 typedef std::map<std::string, std::list<std::string> > AttrValidators;
31 /// validators IDs by feature ID
32 std::map<std::string, AttrValidators> myFeatures;
33 /// validators IDs and arguments by feature and attribute IDs
34 std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
36 /// Registers the instance of the validator by the ID
37 MODEL_EXPORT virtual void registerValidator(const std::string& theID,
38 ModelAPI_Validator* theValidator);
40 /// Assigns validator to the feature
41 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
42 const std::string& theFeatureID);
44 /// Assigns validator to the feature with arguments of the validator
45 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
46 const std::string& theFeatureID,
47 const std::list<std::string>& theArguments);
49 /// Assigns validator to the attribute of the feature
50 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
51 const std::string& theFeatureID,
52 const std::string& theAttrID,
53 const std::list<std::string>& theArguments);
55 /// Provides a validator for the feature, returns NULL if no validator
56 MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
57 std::list<ModelAPI_Validator*>& theResult,
58 std::list<std::list<std::string> >& theArguments) const;
59 /// Provides a validator for the attribute, returns NULL if no validator
60 MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
61 const std::string& theAttrID,
62 std::list<ModelAPI_Validator*>& theValidators,
63 std::list<std::list<std::string> >& theArguments) const;
65 /// Returns registered validator by its Id
66 MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
68 /// Returns true if feature and all its attributes are valid.
69 MODEL_EXPORT virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const;
72 void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
73 /// Get instance from PluginManager
74 Model_ValidatorsFactory();
76 friend class Model_PluginManager;