Salome HOME
"Integer" Attribute added.
[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_H_
6 #define Model_Validator_H_
7
8 #include <Model.h>
9 #include <ModelAPI_Validator.h>
10 #include <map>
11 #include <set>
12
13 /**\class Model_ValidatorsFactory
14  * \ingroup DataModel
15  * \breif Manages the registered validators
16  *
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.
24  */
25 class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
26 {
27  private:
28   std::map<std::string, ModelAPI_Validator*> myIDs;  ///< map from ID to registered validator
29   /// validators IDs by feature ID
30   std::map<std::string, std::set<std::string> > myFeatures;
31   /// set of pairs: validators IDs, list of arguments
32   typedef std::set<std::pair<std::string, std::list<std::string> > > AttrValidators;
33   /// validators IDs and arguments by feature and attribute IDs
34   std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
35  public:
36   /// Registers the instance of the validator by the ID
37   MODEL_EXPORT virtual void registerValidator(const std::string& theID,
38                                               ModelAPI_Validator* theValidator);
39
40   /// Assigns validator to the feature
41   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
42                                             const std::string& theFeatureID);
43
44   /// Assigns validator to the attribute of the feature
45   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
46                                             const std::string& theFeatureID,
47                                             const std::string& theAttrID,
48                                             const std::list<std::string>& theArguments);
49
50   /// Provides a validator for the feature, returns NULL if no validator
51   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
52                                        std::list<ModelAPI_Validator*>& theResult) const;
53   /// Provides a validator for the attribute, returns NULL if no validator
54   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
55                                        const std::string& theAttrID,
56                                        std::list<ModelAPI_Validator*>& theValidators,
57                                        std::list<std::list<std::string> >& theArguments) const;
58
59   /// Returns registered validator by its Id
60   virtual const ModelAPI_Validator* validator(const std::string& theID) const;
61
62   /// Returns the result of "validate" method for attribute of validator.
63   /// If validator is not exists, returns true: everything is valid by default.
64   //MODEL_EXPORT virtual bool validate(
65   //  const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const;
66
67  protected:
68   void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
69   /// Get instance from PluginManager
70   Model_ValidatorsFactory();
71
72   friend class Model_PluginManager;
73 };
74
75 #endif