libSBML C API
5.18.0
|
This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.
The SBMLExtension_t class is a component of the libSBML package extension mechanism. It is an abstract class that is extended by each package extension implementation. The SBMLExtension_t class provides methods for managing common attributes of package extensions (e.g., package name, package version), registration of instantiated SBasePluginCreator_t objects, and initialization/registration of package extensions when the library code for the package is loaded.
GroupsExtension_t
serves this purpose for the SBML Level 3 Groups package extension in libSBML. The following subsections detail the basic steps involved in implementing such an extended class.Define a method named getPackageName()
that returns the name of the package as a string. The following is an example from the implementation of the Groups package extension:
Define a set of methods that return the default SBML Level, SBML Version and version of the package. These methods must be named getDefaultLevel()
, getDefaultVersion()
and getDefaultPackageVersion()
, respectively. The following are examples drawn from the Groups package implementation:
Define methods that return strings representing the XML namespace URI for the package. One method should be defined for each SBML Level/Version combination for which the package can be used. For instance, if a package is only usable in SBML Level 3 Version 1, and the libSBML extension for the package implements version 1 of the package, the necessary method is getXmlnsL3V1V1()
.
Define other similar methods to return additional namespace URIs if the package extension implements other package versions or supports other SBML Level/Version combinations.
Override the following pure virtual methods on SBMLExtension_t:
virtual const std::string& getName() const =0
. This method returns the nickname of the package (e.g., "layout", "groups").virtual unsigned int getLevel(const std::string &uri) const =0
. This method returns the SBML Level with the given URI of this package.virtual unsigned int getVersion(const std::string &uri) const =0
. This method returns the SBML Version with the given URI of this package.virtual unsigned int getPackageVersion(const std::string &uri) const =0
. This method returns the package version with the given URI of this package.virtual unsigned int getURI(unsigned int sbmlLevel, unsigned int sbmlVersion, unsigned int pkgVersion) const =0
. This method returns the URI (namespace) of the package corresponding to the combination of the given SBML Level, SBML Version, and package versionvirtual SBMLExtension_t* clone() const = 0
. This method creates and returns a deep copy of this derived object.As an example, the following are the versions of these methods for the Groups package:
Constructor, copy constructor, and destructor methods also must be overridden if additional data members are defined in the derived class.
Define typedef and template instantiation code for a package-specific subclass of the SBMLExtensionNamespaces_t template class. The SBMLExtensionNamespaces_t template class is a derived class of SBMLNamespaces_t and can be used as an argument of constructors of SBase_t-derived classes defined in the package extensions.
Define a typedef. For example, the typedef for GroupsExtension_t
is implemented in the file GroupsExtension.h
as follows:
Define a template instantiation for the typedef. For example, the template instantiation code for GroupsExtension_t is
implemented in the file GroupsExtension.cpp
as follows:
Here is example of how the resulting class is used. The definitions above allow a GroupsPkgNamespaces_t
object to be used when creating a new Group_t
object. The GroupsPkgNamespaces_t
is handed to the constructor as an argument, as shown below:
The GroupsPkgNamespaces_t
object can also be used when creating an SBMLDocument_t object with the Groups package. The code fragment below shows an example of this:
Override the pure virtual method getSBMLExtensionNamespaces()
, which returns an SBMLNamespaces_t derived object. For example, the method is overridden in the class GroupsExtension_t
as follows:
Define an enum type for representing the type code of the objects defined in the package extension. For example, the enumeration SBMLGroupsTypeCode_t
for the Groups package is defined in GroupsExtension.h
as follows:
In the enumeration above, SBML_GROUPS_GROUP
corresponds to the Group_t
class (for the <group>
element defined by the SBML Level 3 Groups package) and SBML_GROUPS_MEMBER
corresponds to the Member_t
class (for the <member>
element defined by the Level 3 Groups package), respectively.
Similarly, SBMLLayoutTypeCode_t for the Layout_t package is defined in the file LayoutExtension.h
as follows:
These enum values are returned by corresponding getTypeCode()
methods. (E.g., SBML_GROUPS_GROUP
is returned in Group_t::getTypeCode()
.)
Note that libSBML does not require that type codes are unique across all packages—the same type codes may be used within individual package extensions. LibSBML development must permit this because package implementations are developed by separate groups at different times; coordinating the type codes used is impractical. It does mean that callers must check two things when identifying objects: to distinguish the type codes of different packages, callers much check not only the return value of the method getTypeCode()
method but also that of the method getPackageName()
. Here is an example of doing that:
Readers may have noticed that in the SBMLLayoutTypeCode_t and SBMLGroupsTypeCode_t
enumerations above, unique values are in fact assigned to the enumeration values. This can be convenient when it can be arranged, but it is not required by libSBML.
Override the pure virtual method getStringFromTypeCode()
, which returns a string corresponding to the given type code. Here is an example, again drawn from the implementation of the Groups package:
For example, the method for the Groups extension is implemented as shown below:
Implement a static void init()
method in the derived class. This method serves to encapsulate initialization code that creates an instance of the derived class and registration code that registers the instance with the SBMLExtensionRegistry_t class.
For example, the init()
method for the Groups package is implemented as follows:
Instantiate a global SBMLExtensionRegister_t object using the class derived from SBMLExtension_t (discussed above). Here is an example for the Groups package extension, for the object GroupsExtension_t
. This could is placed in the GroupsExtension.cpp
:
The init()
method on GroupsExtension_t
is automatically invoked when the "register" object is instantiated. This results in initialization and registration of the package extension with libSBML.
This has the following consequence. If an application queries for the presence of Layout in an SBML Level 2 document by testing only for the existence of the plugin object, it will always get a positive result; in other words, the presence of a Layout extension object is not an indication of whether a read-in Level 2 document does or does not use SBML Layout. Instead, callers have to query explicitly for the existence of layout information. An example of such a query is the following code:
The special, always-available Level 2 Layout behavior was motivated by a desire to support legacy applications. In SBML Level 3, the Layout package uses the normal SBML Level 3 scheme of requiring declarations on the SBML document element. This means that upon reading a model, libSBML knows right away whether it contains layout information. In SBML Level 2, there is no top-level declaration because layout is stored as annotations in the body of the model. Detecting the presence of layout information when reading a Level 2 model requires parsing the annotations. For efficiency reasons, libSBML normally does not parse annotations automatically when reading a model. However, applications that predated the introduction of Level 3 Layout and the updated version of libSBML never had to do anything special to enable parsing layout; the facilities were always available for every Level 2 model as long as libSBML was compiled with Layout support. To avoid burdening developers of legacy applications with the need to modify their software, libSBML provides backward compatibility by always preloading the Layout package extension when reading Level 2 models. The same applies to the creation of Level 2 models: with the plugin-oriented libSBML, applications normally would have to take deliberate steps to activate package code, instantiate objects, manage namespaces, and so on. LibSBML again loads the Layout package plugin automatically when creating a Level 2 model, thereby making the APIs available to legacy applications without further work on their part.
The mechanisms for triggering this Level 2-specific behavior involves a set of virtual methods on the SBMLExtension_t class that must be implemented by individual package extensions. These methods are SBMLExtension_t::addL2Namespaces(), SBMLExtension_t::removeL2Namespaces(), and SBMLExtension_t::enableL2NamespaceForDocument().
Public Member Functions | |
int | SBMLExtension_addSBasePluginCreator (SBMLExtension_t *ext, SBasePluginCreatorBase_t *sbaseExt) |
Adds the given SBasePluginCreatorBase_t structure to this package extension. More... | |
SBMLExtension_t * | SBMLExtension_clone (SBMLExtension_t *ext) |
Creates a deep copy of the given SBMLExtension_t structure. More... | |
int | SBMLExtension_free (SBMLExtension_t *ext) |
Frees the given SBMLExtension_t structure. More... | |
unsigned int | SBMLExtension_getLevel (SBMLExtension_t *ext, const char *uri) |
Returns the SBML level associated with the given URI of this package. More... | |
const char * | SBMLExtension_getName (SBMLExtension_t *ext) |
Returns the name of the package extension. More... | |
int | SBMLExtension_getNumOfSBasePlugins (SBMLExtension_t *ext) |
Returns the number of SBasePlugin_t structures stored in the structure. More... | |
int | SBMLExtension_getNumOfSupportedPackageURI (SBMLExtension_t *ext) |
Returns the number of supported package namespaces (package versions) for this package extension. More... | |
unsigned int | SBMLExtension_getPackageVersion (SBMLExtension_t *ext, const char *uri) |
Returns the package version associated with the given URI of this package. More... | |
SBasePluginCreatorBase_t * | SBMLExtension_getSBasePluginCreator (SBMLExtension_t *ext, SBaseExtensionPoint_t *extPoint) |
Returns an SBasePluginCreatorBase_t structure of this package extension bound to the given extension point. More... | |
SBasePluginCreatorBase_t * | SBMLExtension_getSBasePluginCreatorByIndex (SBMLExtension_t *ext, unsigned int index) |
Returns an SBasePluginCreatorBase_t structure of this package extension with the given index. More... | |
SBMLNamespaces_t * | SBMLExtension_getSBMLExtensionNamespaces (SBMLExtension_t *ext, const char *uri) |
Returns an SBMLNamespaces_t structure corresponding to the given uri. More... | |
const char * | SBMLExtension_getStringFromTypeCode (SBMLExtension_t *ext, int typeCode) |
This method takes a type code of this package and returns a string representing the code. More... | |
const char * | SBMLExtension_getSupportedPackageURI (SBMLExtension_t *ext, unsigned int index) |
Returns the package URI (package version) for the given index. More... | |
const char * | SBMLExtension_getURI (SBMLExtension_t *ext, unsigned int sbmlLevel, unsigned int sbmlVersion, unsigned int pkgVersion) |
Returns the uri corresponding to the given SBML level, SBML version, and package version for this extension. More... | |
unsigned int | SBMLExtension_getVersion (SBMLExtension_t *ext, const char *uri) |
Returns the SBML version associated with the given URI of this package. More... | |
int | SBMLExtension_isEnabled (SBMLExtension_t *ext) |
Check if this package is enabled or disabled. More... | |
int | SBMLExtension_isSupported (SBMLExtension_t *ext, const char *uri) |
Returns a flag indicating whether the given URI (package version) is supported by this package extension. More... | |
int | SBMLExtension_setEnabled (SBMLExtension_t *ext, int isEnabled) |
Enable/disable this package. More... | |
int SBMLExtension_addSBasePluginCreator | ( | SBMLExtension_t * | ext, |
SBasePluginCreatorBase_t * | sbaseExt | ||
) |
Adds the given SBasePluginCreatorBase_t structure to this package extension.
ext | the SBMLExtension_t structure to be freed. |
sbaseExt | the SBasePluginCreatorBase_t structure bound to some SBML element and creates a corresponding SBasePlugin_t structure of this package extension. |
SBMLExtension_t * SBMLExtension_clone | ( | SBMLExtension_t * | ext | ) |
Creates a deep copy of the given SBMLExtension_t structure.
ext | the SBMLExtension_t structure to be copied. |
int SBMLExtension_free | ( | SBMLExtension_t * | ext | ) |
Frees the given SBMLExtension_t structure.
ext | the SBMLExtension_t structure to be freed. |
unsigned int SBMLExtension_getLevel | ( | SBMLExtension_t * | ext, |
const char * | uri | ||
) |
Returns the SBML level associated with the given URI of this package.
ext | the SBMLExtension_t structure. |
uri | the string of URI that represents a versions of the package. |
const char * SBMLExtension_getName | ( | SBMLExtension_t * | ext | ) |
Returns the name of the package extension.
(e.g. "layout", "multi").
ext | the SBMLExtension_t structure. |
int SBMLExtension_getNumOfSBasePlugins | ( | SBMLExtension_t * | ext | ) |
Returns the number of SBasePlugin_t structures stored in the structure.
ext | the SBMLExtension_t structure. |
int SBMLExtension_getNumOfSupportedPackageURI | ( | SBMLExtension_t * | ext | ) |
Returns the number of supported package namespaces (package versions) for this package extension.
ext | the SBMLExtension_t structure. |
unsigned int SBMLExtension_getPackageVersion | ( | SBMLExtension_t * | ext, |
const char * | uri | ||
) |
Returns the package version associated with the given URI of this package.
ext | the SBMLExtension_t structure. |
uri | the string of URI that represents a versions of the package. |
SBasePluginCreatorBase_t * SBMLExtension_getSBasePluginCreator | ( | SBMLExtension_t * | ext, |
SBaseExtensionPoint_t * | extPoint | ||
) |
Returns an SBasePluginCreatorBase_t structure of this package extension bound to the given extension point.
ext | the SBMLExtension_t structure. |
extPoint | the SBaseExtensionPoint_t to which the returned SBasePluginCreatorBase_t structure bound. |
NULL
for invalid extension of extension point. SBasePluginCreatorBase_t * SBMLExtension_getSBasePluginCreatorByIndex | ( | SBMLExtension_t * | ext, |
unsigned int | index | ||
) |
Returns an SBasePluginCreatorBase_t structure of this package extension with the given index.
ext | the SBMLExtension_t structure. |
index | the index of the returned SBasePluginCreatorBase_t structure for this package extension. |
NULL
for an invalid extension structure. SBMLNamespaces_t * SBMLExtension_getSBMLExtensionNamespaces | ( | SBMLExtension_t * | ext, |
const char * | uri | ||
) |
Returns an SBMLNamespaces_t structure corresponding to the given uri.
NULL will be returned if the given uri is not defined in the corresponding package.
ext | the SBMLExtension_t structure. |
uri | the string of URI that represents one of versions of the package. |
const char * SBMLExtension_getStringFromTypeCode | ( | SBMLExtension_t * | ext, |
int | typeCode | ||
) |
This method takes a type code of this package and returns a string representing the code.
ext | the SBMLExtension_t structure. |
typeCode | the typeCode supported by the package. |
NULL
in case an invalid extension was provided. const char * SBMLExtension_getSupportedPackageURI | ( | SBMLExtension_t * | ext, |
unsigned int | index | ||
) |
Returns the package URI (package version) for the given index.
ext | the SBMLExtension_t structure. |
index | the index of the supported package uri to return. |
NULL
. const char * SBMLExtension_getURI | ( | SBMLExtension_t * | ext, |
unsigned int | sbmlLevel, | ||
unsigned int | sbmlVersion, | ||
unsigned int | pkgVersion | ||
) |
Returns the uri corresponding to the given SBML level, SBML version, and package version for this extension.
ext | the SBMLExtension_t structure. |
sbmlLevel | the level of SBML. |
sbmlVersion | the version of SBML. |
pkgVersion | the version of the package. |
unsigned int SBMLExtension_getVersion | ( | SBMLExtension_t * | ext, |
const char * | uri | ||
) |
Returns the SBML version associated with the given URI of this package.
ext | the SBMLExtension_t structure. |
uri | the string of URI that represents a versions of the package. |
int SBMLExtension_isEnabled | ( | SBMLExtension_t * | ext | ) |
Check if this package is enabled or disabled.
ext | the SBMLExtension_t structure. |
1
(true) if the package is enabled, otherwise 0
(false) is returned. If the extension is invalid, LIBSBML_INVALID_OBJECT will be returned. int SBMLExtension_isSupported | ( | SBMLExtension_t * | ext, |
const char * | uri | ||
) |
Returns a flag indicating whether the given URI (package version) is supported by this package extension.
ext | the SBMLExtension_t structure. |
uri | the package uri. |
1
(true) if the given URI (package version) is supported by this package extension, otherwise 0
(false) is returned. int SBMLExtension_setEnabled | ( | SBMLExtension_t * | ext, |
int | isEnabled | ||
) |
Enable/disable this package.
ext | the SBMLExtension_t structure. |
isEnabled | the value to set : 1 (true; enabled) or 0 (false; disabled). |
1
(true) if this function call succeeded, otherwise 0
(false) is returned. If the extension is invalid, LIBSBML_INVALID_OBJECT will be returned.