Example of the definition and use of an SBMLHttpResolver for working with SBML “comp” files.
Example of the definition and use of an SBMLHttpResolver for working with SBML “comp” files.
#include <iostream>
#include <string>
#include <curl/curl.h>
LIBSBML_CPP_NAMESPACE_USE
using namespace std;
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
{
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;
}
const std::string& sBaseUri="") const
{
if (uri.getScheme() != "http")
{
return NULL;
}
}
protected:
private:
};
int resolveModelFromUri(const std::string& uri)
{
if (model == NULL)
{
return -1;
}
if (model->isSetId())
cout << "resolved: " << model->getId() << endl;
else
cout << "resolved: " << uri << endl;
if (model->isSetNotes())
cout << model->getNotesString() << endl << 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;
}
Include all SBML types of Comp extension in a single header file.
SBMLDocument_t * readSBMLFromString(const char *xml)
Reads an SBML document from a text string.
Definition of SBMLResolver, the base class for resolving SBML documents.
Definition of SBMLResolverRegistry, a registry of available resolvers.
Include all SBML types in a single header file.
Definition of SBMLUri, the utility class for handling URIs.
Definition CompSBMLDocumentPlugin.h:94
ExternalModelDefinition * createExternalModelDefinition()
Creates a ExternalModelDefinition object, adds it to the end of the ExternalModelDefinition objects l...
Definition CompSBMLDocumentPlugin.cpp:536
Definition ExternalModelDefinition.h:128
virtual int setSource(const std::string &source)
Sets the value of the "source" attribute of this ExternalModelDefinition.
Definition ExternalModelDefinition.cpp:333
virtual Model * getReferencedModel()
Resolves and returns the referenced Model object of this ExternalModelDefinition.
Definition ExternalModelDefinition.cpp:573
Definition SBMLDocument.h:351
const Model * getModel() const
Returns the Model object stored in this SBMLDocument.
Definition SBMLDocument.cpp:350
Definition SBMLResolver.h:77
virtual SBMLDocument * resolve(const std::string &uri, const std::string &baseUri="") const
Resolves the document for the given URI.
Definition SBMLResolver.cpp:95
virtual SBMLResolver * clone() const
Creates and returns a deep copy of this SBMLResolver object.
Definition SBMLResolver.cpp:88
SBMLResolver & operator=(const SBMLResolver &rhs)
Assignment operator for SBMLResolver.
Definition SBMLResolver.cpp:76
virtual SBMLUri * resolveUri(const std::string &uri, const std::string &baseUri="") const
Resolves the full URI for the given URI without actually reading the document.
Definition SBMLResolver.cpp:101
static SBMLResolverRegistry & getInstance()
Returns the singleton instance for the resolver registry.
int addResolver(const SBMLResolver *resolver)
Adds the given resolver to the registry of SBML resolvers.
const std::string & getUri() const
Returns the full stored URI, after replacing backslashes with slashes.
Definition SBMLUri.cpp:306
#define LIBSBML_EXTERN
LIBSBML_EXTERN is used under Windows to simplify exporting functions from a DLL.
Definition extern.h:102