Salome HOME
a917911d91c5dce5218c927a4167a21b6ebd0041
[modules/shaper.git] / src / Model / Model_Validator.h
1 // File:        Model_Validator.hxx
2 // Created:     2 Jul 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Validator_HeaderFile
6 #define Model_Validator_HeaderFile
7
8 #include <Model.h>
9 #include <ModelAPI_Validator.h>
10 #include <map>
11
12 /**\class Model_ValidatorsFactory
13  * \ingroup DataModel
14  * \breif Manages the registered validators
15  *
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.
23  */
24 class Model_ValidatorsFactory: public ModelAPI_ValidatorsFactory
25 {
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
30 public:
31   /// Registers the instance of the validator by the ID
32   MODEL_EXPORT virtual void registerValidator(
33     const std::string& theID, ModelAPI_Validator* theValidator);
34
35   /// Assigns validator to the feature
36   MODEL_EXPORT virtual void assignValidator(
37     const std::string& theID, const std::string& theFeatureID);
38
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);
43
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
47   /// Returns the result of "validate" method for attribute of validator.
48   /// If validator is not exists, returns true: everything is valid by default.
49   //MODEL_EXPORT virtual bool validate(
50   //  const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const;
51
52 protected:
53   /// Get instance from PluginManager
54   Model_ValidatorsFactory();
55
56   friend class Model_PluginManager;
57 };
58
59 #endif