2 * Parameters_VariableValidator.cpp
4 * Created on: Apr 9, 2015
8 #include <ParametersPlugin_Validators.h>
10 #include <ModelAPI_AttributeString.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_ResultParameter.h>
14 ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
18 ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator()
22 bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribute,
23 const std::list<std::string>& theArguments) const
25 AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
26 bool result = isVariable(aStrAttr->value());
30 bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString) const
32 if (theString.empty())
34 std::string::const_iterator it = theString.begin();
35 if (!(isalpha(*it) || (*it) == '_') || it == theString.end())
38 for ( ; it != theString.end(); ++it ) {
39 if(!(isalnum(*it) || (*it) == '_')) {
46 ParametersPlugin_ExpressionValidator::ParametersPlugin_ExpressionValidator()
51 ParametersPlugin_ExpressionValidator::~ParametersPlugin_ExpressionValidator()
56 bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttribute,
57 const std::list<std::string>& theArguments) const
59 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
60 ResultParameterPtr aParam =
61 std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aFeature->firstResult());
63 AttributeStringPtr aStrAttr =
64 std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
65 bool isEmptyExpr = aStrAttr->value().empty();
72 return aFeature->error().empty();