Example of the definition and use of an SBMLHttpResolver for working with SBML “comp” files.
#include <iostream>
#include <string>
#include <curl/curl.h>
static size_t WriteCallback(void *contents, size_t size,
size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
{
public:
SBMLHttpResolver ()
{
}
SBMLHttpResolver(const SBMLHttpResolver& c)
{
}
virtual ~SBMLHttpResolver ()
{
}
SBMLHttpResolver& operator=(const SBMLHttpResolver& rhs)
{
return *this;
}
virtual SBMLHttpResolver* clone() const
{
return new SBMLHttpResolver(*this);
}
const std::string& baseUri="") const
{
SBMLUri * resolved = resolveUri(uri, baseUri);
if (resolved == NULL)
return NULL;
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, resolved->
getUri().c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK)
}
return NULL;
}
virtual SBMLUri* resolveUri(
const std::string &sUri,
const std::string& sBaseUri="") const
{
{
return NULL;
}
}
protected:
private:
};
int resolveModelFromUri(const std::string& uri)
{
if (model == NULL)
{
return -1;
}
cout <<
"resolved: " << model->
getId() << endl;
else
cout << "resolved: " << uri << endl;
return 0;
}
int main(void)
{
SBMLHttpResolver resolver;
resolver.resolve("http://www.ebi.ac.uk/biomodels/models-main/publ/BIOMD0000000001/BIOMD0000000001.xml.origin");
if (originalBM1 != NULL)
{
cout <<
"resolved: " << originalBM1->
getModel()->
getId() << endl;
else
cout << "resolved: " << "BIOMD0000000001.xml.origin" << endl;
}
else
{
cout << "an error occured while trying to resolve the document. " << endl;
}
if (resolveModelFromUri("http://www.ebi.ac.uk/biomodels/models-main/publ/BIOMD0000000001/BIOMD0000000001.xml.origin") != 0 )
{
cout << "Comp V1 does not support L2V1 documents!" << endl;
}
if (resolveModelFromUri("http://www.ebi.ac.uk/biomodels-main/download?mid=BMID000000063853") != 0 )
{
cout << "something went wrong while getting the l3v1." << endl;
}
if (resolveModelFromUri("http://sbml.svn.sourceforge.net/viewvc/sbml/branches/libsbml-packages/comp/src/sbml/packages/comp/util/test/test-data/subdir/new_aggregate.xml?revision=16695") != 0 )
{
cout << "something went wrong while getting the l3v1 comp model." << endl;
}
cout << "done!";
return 0;
}