예제 #1
0
int SBaseRef::saveReferencedElement()
{
  //The only thing that knows what Model we should point to is the parent of this object.  Since it will also be of the class SBaseRef, just call this recursively.
  SBMLDocument* doc = getSBMLDocument();
  SBase* parent = getParentSBMLObject();
  if (parent==NULL) {
    if (doc) {
      string error = "In SBaseRef::saveReferencedElement, unable to find referenced element: no parent could be found for the given <sBaseRef> element.";
      doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
    }
    return LIBSBML_OPERATION_FAILED;
  }
  SBaseRef* parentref = static_cast<SBaseRef*>(parent);
  if (parentref==NULL || (parent->getTypeCode() != SBML_COMP_SBASEREF &&
                          parent->getTypeCode() != SBML_COMP_PORT &&
                          parent->getTypeCode() != SBML_COMP_DELETION &&
                          parent->getTypeCode() != SBML_COMP_REPLACEDBY &&
                          parent->getTypeCode() != SBML_COMP_REPLACEDELEMENT)) {
    if (doc) {
      string error = "In SBaseRef::saveReferencedElement, unable to find referenced element: the parent of the given <sBaseRef> element was not the correct type.";
      doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
    }
    return LIBSBML_OPERATION_FAILED;
  }
  if (parentref->saveReferencedElement() != LIBSBML_OPERATION_SUCCESS) {
    //saveReferencedElement will set its own error messages.
    return LIBSBML_OPERATION_FAILED;
  }
  mReferencedElement = parentref->getReferencedElement();
  mDirectReference = parentref->getDirectReference();
  if (mReferencedElement==NULL) {
    //getReferencedElement will set its own error messages.
    return LIBSBML_OPERATION_FAILED;
  }
  return LIBSBML_OPERATION_SUCCESS;
}