Salome HOME
Boost has been removed from code
[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 Session.
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 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;
35   /// Stores the registered attributes that leads to the concealment of referenced objects in 
36   /// data tree. Map from feature kind to set of attribute IDs.
37   std::map<std::string, std::set<std::string> > myConcealed;
38
39  public:
40   /// Registers the instance of the validator by the ID
41   MODEL_EXPORT virtual void registerValidator(const std::string& theID,
42                                               ModelAPI_Validator* theValidator);
43
44   /// Assigns validator to the feature
45   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
46                                             const std::string& theFeatureID);
47
48   /// Assigns validator to the feature with arguments of the validator
49   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
50                                             const std::string& theFeatureID,
51                                             const std::list<std::string>& theArguments);
52
53   /// Assigns validator to the attribute of the feature
54   MODEL_EXPORT virtual void assignValidator(const std::string& theID,
55                                             const std::string& theFeatureID,
56                                             const std::string& theAttrID,
57                                             const std::list<std::string>& theArguments);
58
59   /// Provides a validator for the feature, returns NULL if no validator
60   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
61                                        std::list<ModelAPI_Validator*>& theResult,
62                                        std::list<std::list<std::string> >& theArguments) const;
63   /// Provides a validator for the attribute, returns NULL if no validator
64   MODEL_EXPORT virtual void validators(const std::string& theFeatureID,
65                                        const std::string& theAttrID,
66                                        std::list<ModelAPI_Validator*>& theValidators,
67                                        std::list<std::list<std::string> >& theArguments) const;
68
69   /// Returns registered validator by its Id
70   MODEL_EXPORT virtual const ModelAPI_Validator* validator(const std::string& theID) const;
71
72   /// Returns true if feature and all its attributes are valid.
73   MODEL_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
74
75   /// register that this attribute in feature is not obligatory for the feature execution
76   /// so, it is not needed for the standard validation mechanism
77   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
78
79   /// register that this attribute conceals in the object browser
80   /// all referenced features after execution
81   virtual void registerConcealment(std::string theFeature, std::string theAttribute);
82
83   /// Returns true that it was registered that attribute conceals the referenced result
84   virtual bool isConcealed(std::string theFeature, std::string theAttribute);
85
86 protected:
87   void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
88   /// Get instance from Session
89   Model_ValidatorsFactory();
90
91   friend class Model_Session;
92 };
93
94 #endif