libSBML Python API
5.20.2
|
GroupsExtension
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:
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* 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 template class. The SBMLExtensionNamespaces template class is a derived class of SBMLNamespaces and can be used as an argument of constructors of SBase-derived classes defined in the package extensions.
Define a typedef. For example, the typedef for GroupsExtension
is implemented in the file GroupsExtension.h
as follows:
Define a template instantiation for the typedef. For example, the template instantiation code for GroupsExtension 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
object to be used when creating a new Group
object. The GroupsPkgNamespaces
is handed to the constructor as an argument, as shown below:
The GroupsPkgNamespaces
object can also be used when creating an SBMLDocument object with the Groups package. The code fragment below shows an example of this:
Override the pure virtual method getSBMLExtensionNamespaces()
, which returns an SBMLNamespaces derived object. For example, the method is overridden in the class GroupsExtension
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
class (for the <group>
element defined by the SBML Level 3 Groups package) and SBML_GROUPS_MEMBER
corresponds to the Member
class (for the <member>
element defined by the Level 3 Groups package), respectively.
Similarly, #SBMLLayoutTypeCode_t for the Layout 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::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 class.
For example, the init()
method for the Groups package is implemented as follows:
Instantiate a global SBMLExtensionRegister object using the class derived from SBMLExtension (discussed above). Here is an example for the Groups package extension, for the object GroupsExtension
. This could is placed in the GroupsExtension.cpp
:
The init()
method on GroupsExtension
is automatically invoked when the "register" object is instantiated. This results in initialization and registration of the package extension with libSBML.