Skip to content

Commit

Permalink
adding validation
Browse files Browse the repository at this point in the history
  • Loading branch information
skeating committed Sep 19, 2023
1 parent 7013ab7 commit aee04c3
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 191 deletions.
4 changes: 3 additions & 1 deletion dev/packages/deviser-fbc_v3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<attribute name="id" required="false" type="SId" abstract="false"/>
<attribute name="name" required="false" type="string" abstract="false"/>
<attribute name="reaction" required="true" type="SIdRef" element="Reaction" abstract="false"/>
<attribute name="reaction2" required="false" type="SIdRef" element="Reaction" abstract="false"/>
<attribute name="coefficient" required="true" type="double" abstract="false"/>
<attribute name="variableType" required="true" type="enum" element="FbcVariableType" abstract="false"/>
</attributes>
Expand Down Expand Up @@ -226,8 +227,9 @@
<attributes>
<attribute name="id" required="false" type="SId" abstract="false"/>
<attribute name="name" required="false" type="string" abstract="false"/>
<attribute name="coefficient" required="true" type="double" abstract="false"/>
<attribute name="coefficient" required="true" type="SIdRef" element="Parameter" abstract="false"/>
<attribute name="variable" required="true" type="SIdRef" element="Reaction,Parameter" abstract="false"/>
<attribute name="variable2" required="false" type="SIdRef" element="Reaction,Parameter" abstract="false"/>
<attribute name="variableType" required="true" type="enum" element="FbcVariableType" abstract="false"/>
</attributes>
</element>
Expand Down
135 changes: 87 additions & 48 deletions src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(
: SBase(level, version)
, mCoefficient ("")
, mVariable ("")
, mVariableType (FBC_VARIABLE_TYPE_INVALID)
, mVariable2 ("")
, mVariableType (FBC_VARIABLE_TYPE_INVALID)
{
setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion));
}
Expand All @@ -81,8 +81,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(FbcPkgNamespaces
: SBase(fbcns)
, mCoefficient ("")
, mVariable ("")
, mVariableType (FBC_VARIABLE_TYPE_INVALID)
, mVariable2 ("")
, mVariableType (FBC_VARIABLE_TYPE_INVALID)
{
setElementNamespace(fbcns->getURI());
loadPlugins(fbcns);
Expand All @@ -97,8 +97,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(const
: SBase( orig )
, mCoefficient ( orig.mCoefficient )
, mVariable ( orig.mVariable )
, mVariableType ( orig.mVariableType )
, mVariable2 ( orig.mVariable2 )
, mVariableType ( orig.mVariableType )
{
}

Expand All @@ -115,8 +115,8 @@ UserDefinedConstraintComponent::operator=(const UserDefinedConstraintComponent&
SBase::operator=(rhs);
mCoefficient = rhs.mCoefficient;
mVariable = rhs.mVariable;
mVariableType = rhs.mVariableType;
mVariable2 = rhs.mVariable2;
mVariableType = rhs.mVariableType;
}

return *this;
Expand Down Expand Up @@ -185,6 +185,7 @@ UserDefinedConstraintComponent::getVariable() const
return mVariable;
}


/*
* Returns the value of the "variable2" attribute of this
* UserDefinedConstraintComponent.
Expand Down Expand Up @@ -273,6 +274,7 @@ UserDefinedConstraintComponent::isSetVariable2() const
return (mVariable2.empty() == false);
}


/*
* Predicate returning @c true if this UserDefinedConstraintComponent's
* "variableType" attribute is set.
Expand Down Expand Up @@ -341,8 +343,15 @@ UserDefinedConstraintComponent::setCoefficient(const std::string& coefficient)

if (coreLevel == 3 && coreVersion == 1 && pkgVersion == 3)
{
mCoefficient = coefficient;
return LIBSBML_OPERATION_SUCCESS;
if (!(SyntaxChecker::isValidInternalSId(coefficient)))
{
return LIBSBML_INVALID_ATTRIBUTE_VALUE;
}
else
{
mCoefficient = coefficient;
return LIBSBML_OPERATION_SUCCESS;
}
}
else
{
Expand Down Expand Up @@ -410,6 +419,7 @@ UserDefinedConstraintComponent::setVariable2(const std::string& variable)
}
}


/*
* Sets the value of the "variableType" attribute of this
* UserDefinedConstraintComponent.
Expand Down Expand Up @@ -521,7 +531,7 @@ UserDefinedConstraintComponent::unsetCoefficient()
{
mCoefficient.erase();

if (isSetCoefficient() == false)
if (mCoefficient.empty() == true)
{
return LIBSBML_OPERATION_SUCCESS;
}
Expand Down Expand Up @@ -571,6 +581,7 @@ UserDefinedConstraintComponent::unsetVariable2()
}
}


/*
* Unsets the value of the "variableType" attribute of this
* UserDefinedConstraintComponent.
Expand All @@ -594,10 +605,12 @@ UserDefinedConstraintComponent::renameSIdRefs(const std::string& oldid,
{
setCoefficient(newid);
}

if (isSetVariable() && mVariable == oldid)
{
setVariable(newid);
}

if (isSetVariable2() && mVariable2 == oldid)
{
setVariable2(newid);
Expand Down Expand Up @@ -786,11 +799,6 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName,
{
int return_value = SBase::getAttribute(attributeName, value);

if (return_value == LIBSBML_OPERATION_SUCCESS)
{
return return_value;
}

return return_value;
}

Expand Down Expand Up @@ -844,24 +852,24 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName,
value = getName();
return_value = LIBSBML_OPERATION_SUCCESS;
}
else if (attributeName == "variable")
else if (attributeName == "coefficient")
{
value = getVariable();
value = getCoefficient();
return_value = LIBSBML_OPERATION_SUCCESS;
}
else if (attributeName == "variableType")
else if (attributeName == "variable")
{
value = getVariableTypeAsString();
value = getVariable();
return_value = LIBSBML_OPERATION_SUCCESS;
}
else if (attributeName == "coefficient")
else if (attributeName == "variable2")
{
value = getCoefficient();
value = getVariable2();
return_value = LIBSBML_OPERATION_SUCCESS;
}
else if (attributeName == "variable2")
else if (attributeName == "variableType")
{
value = getVariable2();
value = getVariableTypeAsString();
return_value = LIBSBML_OPERATION_SUCCESS;
}

Expand Down Expand Up @@ -900,14 +908,14 @@ UserDefinedConstraintComponent::isSetAttribute(const std::string&
{
value = isSetVariable();
}
else if (attributeName == "variableType")
{
value = isSetVariableType();
}
else if (attributeName == "variable2")
{
value = isSetVariable2();
}
else if (attributeName == "variableType")
{
value = isSetVariableType();
}

return value;
}
Expand Down Expand Up @@ -1012,22 +1020,22 @@ UserDefinedConstraintComponent::setAttribute(const std::string& attributeName,
{
return_value = setName(value);
}
else if (attributeName == "variable")
{
return_value = setVariable(value);
}
else if (attributeName == "variableType")
{
return_value = setVariableType(value);
}
else if (attributeName == "coefficient")
{
return_value = setCoefficient(value);
}
else if (attributeName == "variable")
{
return_value = setVariable(value);
}
else if (attributeName == "variable2")
{
return_value = setVariable2(value);
}
else if (attributeName == "variableType")
{
return_value = setVariableType(value);
}

return return_value;
}
Expand Down Expand Up @@ -1064,14 +1072,14 @@ UserDefinedConstraintComponent::unsetAttribute(const std::string&
{
value = unsetVariable();
}
else if (attributeName == "variableType")
{
value = unsetVariableType();
}
else if (attributeName == "variable2")
{
value = unsetVariable2();
}
else if (attributeName == "variableType")
{
value = unsetVariableType();
}

return value;
}
Expand Down Expand Up @@ -1101,8 +1109,8 @@ UserDefinedConstraintComponent::addExpectedAttributes(ExpectedAttributes&
attributes.add("name");
attributes.add("coefficient");
attributes.add("variable");
attributes.add("variableType");
attributes.add("variable2");
attributes.add("variableType");
}
}

Expand Down Expand Up @@ -1250,12 +1258,12 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes&
}

//
// coefficient double (use = "required" )
// coefficient SIdRef (use = "required" )
//

numErrs = log ? log->getNumErrors() : 0;
XMLTriple tripleCOEFF("coefficient", mURI, getPrefix());
assigned = attributes.readInto(tripleCOEFF, mCoefficient);
assigned = attributes.readInto("coefficient", mCoefficient);

if (assigned == true)
{
Expand Down Expand Up @@ -1321,6 +1329,34 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes&
}
}

//
// variable2 SIdRef (use = "optional" )
//

assigned = attributes.readInto("variable2", mVariable2);

if (assigned == true)
{
if (mVariable2.empty() == true)
{
logEmptyString(mVariable2, level, version,
"<UserDefinedConstraintComponent>");
}
else if (SyntaxChecker::isValidSBMLSId(mVariable2) == false)
{
std::string msg = "The variable2 attribute on the <" + getElementName() +
">";
if (isSetId())
{
msg += " with id '" + getId() + "'";
}

msg += " is '" + mVariable2 + "', which does not conform to the syntax.";
log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, msg,
getLine(), getColumn());
}
}

//
// variableType enum (use = "required" )
//
Expand Down Expand Up @@ -1456,17 +1492,16 @@ UserDefinedConstraintComponent::writeL3V1V3Attributes(XMLOutputStream& stream)
stream.writeAttribute("variable", getPrefix(), mVariable);
}

if (isSetVariableType() == true)
{
stream.writeAttribute("variableType", getPrefix(),
FbcVariableType_toString(mVariableType));
}

if (isSetVariable2() == true)
{
stream.writeAttribute("variable2", getPrefix(), mVariable2);
}

if (isSetVariableType() == true)
{
stream.writeAttribute("variableType", getPrefix(),
FbcVariableType_toString(mVariableType));
}
}

/** @endcond */
Expand Down Expand Up @@ -1698,6 +1733,7 @@ UserDefinedConstraintComponent_isSetVariable(const
return (udcc != NULL) ? static_cast<int>(udcc->isSetVariable()) : 0;
}


/*
* Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's
* "variable2" attribute is set.
Expand All @@ -1710,6 +1746,7 @@ UserDefinedConstraintComponent_isSetVariable2(const
return (udcc != NULL) ? static_cast<int>(udcc->isSetVariable2()) : 0;
}


/*
* Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's
* "variableType" attribute is set.
Expand Down Expand Up @@ -1758,7 +1795,7 @@ int
UserDefinedConstraintComponent_setCoefficient(
UserDefinedConstraintComponent_t
* udcc,
const char* coefficient)
const char * coefficient)
{
return (udcc != NULL) ? udcc->setCoefficient(coefficient) :
LIBSBML_INVALID_OBJECT;
Expand Down Expand Up @@ -1878,18 +1915,20 @@ UserDefinedConstraintComponent_unsetVariable(UserDefinedConstraintComponent_t *
return (udcc != NULL) ? udcc->unsetVariable() : LIBSBML_INVALID_OBJECT;
}


/*
* Unsets the value of the "variable2" attribute of this
* UserDefinedConstraintComponent_t.
*/
LIBSBML_EXTERN
int
UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t *
udcc)
UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t
* udcc)
{
return (udcc != NULL) ? udcc->unsetVariable2() : LIBSBML_INVALID_OBJECT;
}


/*
* Unsets the value of the "variableType" attribute of this
* UserDefinedConstraintComponent_t.
Expand Down
Loading

0 comments on commit aee04c3

Please sign in to comment.