1 // File: Model_Validator.hxx
3 // Author: Mikhail PONIKAROV
5 #ifndef Model_Validator_HeaderFile
6 #define Model_Validator_HeaderFile
9 #include <ModelAPI_Validator.h>
12 /**\class Model_ValidatorsFactory
14 * \breif Manages the registered validators
16 * Allows to get a validator by the feature identifier and
17 * the attribute identifier (if attribute is validated).
18 * All accessible validators mustbe registered by the ID string first.
19 * The instance of this factory can be get in the PluginManager.
20 * Keeps the validator objects alive and just returns one of it by request.
21 * All the needed information is provided to the validator as an argument,
22 * this allows to work with them independently from the feature specific object.
24 class Model_ValidatorsFactory: public ModelAPI_ValidatorsFactory
26 std::map<std::string, ModelAPI_Validator*> myIDs; ///< map from ID to registered validator
27 std::map<std::string, ModelAPI_Validator*> myFeatures; ///< validators by feature ID
28 std::map<std::string, std::map<std::string, std::pair<ModelAPI_Validator*,
29 std::list<std::string> > > > myAttrs; ///< validators and arguments by feature and attribute IDs
31 /// Registers the instance of the validator by the ID
32 MODEL_EXPORT virtual void registerValidator(
33 const std::string& theID, ModelAPI_Validator* theValidator);
35 /// Assigns validator to the feature
36 MODEL_EXPORT virtual void assignValidator(
37 const std::string& theID, const std::string& theFeatureID);
39 /// Assigns validator to the attribute of the feature
40 MODEL_EXPORT virtual void assignValidator(const std::string& theID,
41 const std::string& theFeatureID, const std::string& theAttrID,
42 const std::list<std::string>& theArguments);
44 /// Provides a validator for the feature, returns NULL if no validator
45 MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theFeatureID) const;
46 /// Provides a validator for the attribute, returns NULL if no validator
47 MODEL_EXPORT virtual const ModelAPI_Validator* validator(
48 const std::string& theFeatureID, const std::string& theAttrID) const;
50 /// Returns the result of "validate" method for attribute of validator.
51 /// If validator is not exists, returns true: everything is valid by default.
52 //MODEL_EXPORT virtual bool validate(
53 // const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const;
56 /// Get instance from PluginManager
57 Model_ValidatorsFactory();
59 friend class Model_PluginManager;