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
{
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
{
if (uri.getScheme() != "http")
{
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;
}
SBMLExtensionNamespaces< CompExtension > CompPkgNamespaces
Definition: CompExtension.h:326
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:544
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
virtual bool isSetId() const
Predicate returning true if this Model's "id" attribute is set.
Definition: Model.cpp:618
virtual const std::string & getId() const
Returns the value of the "id" attribute of this Model.
Definition: SBMLDocument.h:349
const Model * getModel() const
Returns the Model object stored in this SBMLDocument.
Definition: SBMLDocument.cpp:350
Definition: SBMLResolver.h:77
int addResolver(const SBMLResolver *resolver)
Adds the given resolver to the registry of SBML resolvers.
Definition: SBMLResolverRegistry.cpp:77
static SBMLResolverRegistry & getInstance()
Returns the singleton instance for the resolver registry.
Definition: SBMLResolverRegistry.cpp:66
const std::string & getUri() const
Returns the full stored URI, after replacing backslashes with slashes.
Definition: SBMLUri.cpp:306
std::string getNotesString()
Returns the content of the "notes" subelement of this object as a string.
Definition: SBase.cpp:771
bool isSetNotes() const
Predicate returning true if this object's "notes" subelement exists and has content.
Definition: SBase.cpp:1143
#define LIBSBML_EXTERN
LIBSBML_EXTERN is used under Windows to simplify exporting functions from a DLL.
Definition: extern.h:102