int 
CompFlatteningConverter::convert()
{  
   // need to keep track so we can delete it later;
  int basePathResolverIndex = -1;

  // need to set the base path if we have the option
  if (getProperties() != NULL && getProperties()->hasOption("basePath"))
  {
    string basePath = getProperties()->getValue("basePath");
    if(basePath != ".")
    {
      // temporarily add a new resolver with the new basePath
      SBMLFileResolver basePathResolver;
      basePathResolver.addAdditionalDir(basePath);
      basePathResolverIndex = 
                   SBMLResolverRegistry::getInstance().getNumResolvers();
      SBMLResolverRegistry::getInstance().addResolver(&basePathResolver);    
    }
  }  

  // remember number of registered callbacks

  int numRegisteredCallbacks = Submodel::getNumProcessingCallbacks();

  int result = performConversion();

  if (basePathResolverIndex != -1)
  {
    // if we added a resolver remove it
    SBMLResolverRegistry::getInstance().removeResolver(basePathResolverIndex);
  }

  // remove all registered callbacks
  for (int index = Submodel::getNumProcessingCallbacks()-1; index >= numRegisteredCallbacks; --index)
  {
    Submodel::removeProcessingCallback(index);
  }
  
  // clean up PkgsToStrip
  if (mPkgsToStrip != NULL)
  {
    mPkgsToStrip->clear();
    delete mPkgsToStrip;
    mPkgsToStrip = NULL;
  }


  return result;

}
Ejemplo n.º 2
0
END_TEST
  
  
START_TEST (test_comp_fileresolver_resolve_4)
{ 
  string filename(TestDataDirectory);
  filename += "complexified.xml";
  SBMLDocument* doc = readSBMLFromFile(filename.c_str());
  fail_unless(doc->getLocationURI() == "file:" + filename);
  SBMLFileResolver fr;
  string newDir(TestDataDirectory);
  newDir += "/subdir";
  fr.addAdditionalDir(newDir);
  SBMLDocument* doc2 = fr.resolve("new_aggregate.xml", doc->getLocationURI());
  fail_unless(doc2 != NULL);
  fail_unless(doc2->getModel() != NULL);
}