1 // File: ModelAPI_Validator.hxx
3 // Author: Mikhail PONIKAROV
5 #ifndef ModelAPI_Validator_H_
6 #define ModelAPI_Validator_H_
9 #include <boost/shared_ptr.hpp>
12 class ModelAPI_Feature;
14 /**\class ModelAPI_Validator
16 * \brief Allows to validate the attribute value of a feature or the whole feature.
18 * This object is assigned by the name
19 * in the XML file to the specific attribute or to the whole feature.
20 * If validator returns "false", it is signalized in user interface
21 * and feature is not executed.
22 * Validators must be registered in the validators factory to be
23 * correctly identified by the XML string-ID.
25 class MODELAPI_EXPORT ModelAPI_Validator
28 // Make virtual destructor in order to make the class polymorphic
29 virtual ~ModelAPI_Validator()
34 /// Returns true if feature and/or attributes are valid
35 /// \param theFeature the validated feature
36 /// \param theAttr the validated attribute ID, empty string of feature is validated
37 /// \param theArguments list of string, feature attribute names: dependent attributes
38 //virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
39 // const std::string theAttr, std::list<std::string> theArguments) const = 0;
42 typedef boost::shared_ptr<ModelAPI_Validator> ValidatorPtr;
44 /**\class ModelAPI_ValidatorsFactory
46 * \breif Manages the registered validators
48 * Allows to get a validator by the feature identifier and
49 * the attribute identifier (if attribute is validated).
50 * All accessible validators mustbe registered by the ID string first.
51 * The instance of this factory can be get in the PluginManager.
52 * Keeps the validator objects alive and just returns one of it by request.
53 * All the needed information is provided to the validator as an argument,
54 * this allows to work with them independently from the feature specific object.
56 class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
59 /// Registers the instance of the validator by the ID
60 virtual void registerValidator(const std::string& theID, ModelAPI_Validator* theValidator) = 0;
62 /// Assigns validator to the feature
63 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID) = 0;
65 /// Assigns validator to the attribute of the feature
66 virtual void assignValidator(const std::string& theID, const std::string& theFeatureID,
67 const std::string& theAttrID,
68 const std::list<std::string>& theArguments) = 0;
70 /// Provides a validator for the feature, returns NULL if no validator
71 virtual void validators(const std::string& theFeatureID,
72 std::list<ModelAPI_Validator*>& theResult) const = 0;
73 /// Provides a validator for the attribute, returns NULL if no validator
74 virtual void validators(const std::string& theFeatureID, const std::string& theAttrID,
75 std::list<ModelAPI_Validator*>& theValidators,
76 std::list<std::list<std::string> >& theArguments) const = 0;
78 /// Returns registered validator by its Id
79 virtual const ModelAPI_Validator* validator(const std::string& theID) const = 0;
81 /// Returns the result of "validate" method for attribute of validator.
82 /// If validator is not exists, returns true: everything is valid by default.
83 //virtual bool validate(
84 // const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const = 0;
87 /// Get instance from PluginManager
88 ModelAPI_ValidatorsFactory()