libSBML C++ API  5.20.4
SBasePlugin Class Reference
Inheritance diagram for SBasePlugin:
[legend]

Detailed Description

Base class for extending SBML objects in packages.

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 SBasePlugin class is libSBML's base class for extensions of core SBML component objects. SBasePlugin defines basic virtual methods for reading/writing/checking additional attributes and/or subobjects; these methods should be overridden by subclasses to implement the necessary features of an extended SBML object.

How to extend SBasePlugin for a package implementation

LibSBML package extensions can extend existing libSBML objects such as Model using SBasePlugin as a base class, to hold attributes and/or subcomponents necessary for the SBML package being implemented. Package developers must implement an SBasePlugin extended class for each element to be extended (e.g., Model, Reaction, and others) where additional attributes and/or top-level objects of the package extension are directly contained. The following subsections detail the basic steps necessary to use SBasePlugin for the implementation of a class extension.

1. Identify the SBML components that need to be extended

The specification for a SBML Level 3 package will define the attributes and subojects that make up the package constructs. Those constructs that modify existing SBML components such as Model, Reaction, etc., will be the ones that need to be extended using SBasePlugin.

For example, the Layout package makes additions to Model, SpeciesReference, and the <sbml> element (which is represented in libSBML by SBMLDocument). This means that the Layout package extension in libSBML needs to define extended versions of Model, SpeciesReference and SBMLDocument. Elements other than the SBML document need to be implemented using SBasePlugin; the document component must be implemented using SBMLDocumentPlugin instead.

2. Create a SBasePlugin subclass for each extended SBML component

A new class definition that subclasses SBasePlugin needs to be created for each SBML component to be extended by the package. For instance, the Layout package needs LayoutModelPlugin and LayoutSpeciesReferencePlugin. (As mentioned above, the Layout class also needs LayoutSBMLDocumentPlugin, but this one is implemented using SBMLDocumentPlugin instead of SBasePlugin.) Below, we describe in detail the different parts of an SBasePlugin subclass definition.

2.1 Define protected data members

Data attributes on each extended class in an SBML package will have one of the data types std::string, double, int, or bool. Subelements/subobjects will normally be derived from the ListOf class or from SBase.

The additional data members must be properly initialized in the class constructor, and must be properly copied in the copy constructor and assignment operator. For example, the following data member is defined in the GroupsModelPlugin class (in the file GroupsModelPlugin.h):

ListOfGroups mGroups;
Definition: ListOfGroups.h:85

2.2 Override SBasePlugin class-related methods

The derived class must override the constructor, copy constructor, assignment operator (operator=) and clone() methods from SBasePlugin.

2.3 Override SBasePlugin virtual methods for attributes

If the extended component is defined by the SBML Level 3 package to have attributes, then the extended class definition needs to override the following internal methods on SBasePlugin and provide appropriate implementations:

  • addExpectedAttributes(ExpectedAttributes& attributes): This method should add the attributes that are expected to be found on this kind of extended component in an SBML file or data stream.
  • readAttributes(XMLAttributes& attributes, ExpectedAttributes& expectedAttributes): This method should read the attributes expected to be found on this kind of extended component in an SBML file or data stream.
  • hasRequiredAttributes(): This method should return true if all of the required attribute for this extended component are present on instance of the object.
  • writeAttributes(XMLOutputStream& stream): This method should write out the attributes of an extended component. The implementation should use the different kinds of writeAttribute methods defined by XMLOutputStream to achieve this.

2.4 Override SBasePlugin virtual methods for subcomponents

If the extended component is defined by the Level 3 package to have subcomponents (i.e., full XML elements rather than mere attributes), then the extended class definition needs to override the following internal SBasePlugin methods and provide appropriate implementations:

  • createObject(XMLInputStream& stream): Subclasses must override this method to create, store, and then return an SBML object corresponding to the next XMLToken in the XMLInputStream. To do this, implementations can use methods like peek() on XMLInputStream to test if the next object in the stream is something expected for the package. For example, LayoutModelPlugin uses peek() to examine the next element in the input stream, then tests that element against the Layout namespace and the element name "listOfLayouts" to see if it's the single subcomponent (ListOfLayouts) permitted on a Model object using the Layout package. If it is, it returns the appropriate object.
  • connectToParent(SBase *sbase): This creates a parent-child relationship between a given extended component and its subcomponent(s).
  • setSBMLDocument(SBMLDocument* d): This method should set the parent SBMLDocument object on the subcomponent object instances, so that the subcomponent instances know which SBMLDocument contains them.
  • enablePackageInternal(std::string& pkgURI, std::string& pkgPrefix, bool flag): This method should enable or disable the subcomponent based on whether a given XML namespace is active.
  • writeElements(XMLOutputStream& stream): This method must be overridden to provide an implementation that will write out the expected subcomponents/subelements to the XML output stream.
  • readOtherXML(SBase* parentObject, XMLInputStream& stream): This function should be overridden if elements of annotation, notes, MathML content, etc., need to be directly parsed from the given XMLInputStream object.
  • hasRequiredElements(): This method should return true if a given object contains all the required subcomponents defined by the specification for that SBML Level 3 package.

2.5 Override SBasePlugin virtual methods for XML namespaces

If the package needs to add additional xmlns attributes to declare additional XML namespace URIs, the extended class should override the following method:

  • writeXMLNS(XMLOutputStream& stream): This method should write out any additional XML namespaces that might be needed by a package implementation.

2.6 Implement additional methods as needed

Extended component implementations can add whatever additional utility methods are useful for their implementation.

Public Member Functions

virtual SBasePluginclone () const
 Creates and returns a deep copy of this SBasePlugin object. More...
 
virtual ListgetAllElements (ElementFilter *filter=NULL)
 Returns all child objects of this object. More...
 
virtual SBasegetElementByMetaId (const std::string &metaid)
 Return the first child object found with a given meta identifier. More...
 
virtual SBasegetElementBySId (const std::string &id)
 Return the first child object found with a given identifier. More...
 
const std::string & getElementNamespace () const
 Returns the namespace URI of the package to which this plugin object belongs. More...
 
unsigned int getLevel () const
 Returns the SBML Level of the package extension of this plugin object. More...
 
const std::string & getPackageName () const
 Returns the short-form name of the package to which this plugin object belongs. More...
 
unsigned int getPackageVersion () const
 Returns the package version of the package extension of this plugin object. More...
 
SBasegetParentSBMLObject ()
 Returns the parent object to which this plugin object is connected. More...
 
const SBasegetParentSBMLObject () const
 Returns the parent object to which this plugin object is connected. More...
 
const std::string & getPrefix () const
 Returns the XML namespace prefix of the package to which this plugin object belongs. More...
 
SBMLDocumentgetSBMLDocument ()
 Returns the SBMLDocument object containing this object instance. More...
 
const SBMLDocumentgetSBMLDocument () const
 Returns the SBMLDocument object containing this object instance. More...
 
std::string getURI () const
 Returns the XML namespace URI for the package to which this object belongs. More...
 
unsigned int getVersion () const
 Returns the Version within the SBML Level of the package extension of this plugin object. More...
 
virtual bool isValidTypeForList (SBase *item) const
 
SBasePluginoperator= (const SBasePlugin &orig)
 Assignment operator for SBasePlugin. More...
 
virtual void renameMetaIdRefs (const std::string &oldid, const std::string &newid)
 
virtual void renameSIdRefs (const std::string &oldid, const std::string &newid)
 
virtual void renameUnitSIdRefs (const std::string &oldid, const std::string &newid)
 
int setElementNamespace (const std::string &uri)
 Sets the XML namespace to which this object belongs. More...
 
virtual ~SBasePlugin ()
 Destroy this SBasePlugin object. More...
 

Constructor & Destructor Documentation

◆ ~SBasePlugin()

SBasePlugin::~SBasePlugin ( )
virtual

Destroy this SBasePlugin object.

Member Function Documentation

◆ clone()

◆ getAllElements()

List * SBasePlugin::getAllElements ( ElementFilter filter = NULL)
virtual

Returns all child objects of this object.

This returns a List object containing all child SBase objects of this one, at any nesting depth. Optionally, callers can supply a filter that will establish the search criteria for matching objects.

Parameters
filtera pointer to an ElementFilter, which causes the function to return only elements that match a particular set of constraints. If NULL (the default), the function will return all child objects.
Returns
a List of pointers to all children objects.

Reimplemented in SpatialParameterPlugin, SpatialModelPlugin, SpatialCompartmentPlugin, RenderListOfLayoutsPlugin, RenderLayoutPlugin, QualModelPlugin, MultiSpeciesReferencePlugin, MultiSpeciesPlugin, MultiSimpleSpeciesReferencePlugin, MultiModelPlugin, MultiCompartmentPlugin, LayoutModelPlugin, GroupsModelPlugin, FbcSBasePlugin, FbcReactionPlugin, FbcModelPlugin, DistribSBasePlugin, CompSBMLDocumentPlugin, CompSBasePlugin, and CompModelPlugin.

◆ getElementByMetaId()

SBase * SBasePlugin::getElementByMetaId ( const std::string &  metaid)
virtual

Return the first child object found with a given meta identifier.

This method searches all the subobjects under this one, compares their meta identifiers to metaid, and returns the first one that machines.

Parameters
metaidstring, the metaid of the object to find.
Returns
pointer to the first object found with the given metaid.

Reimplemented in SpatialParameterPlugin, SpatialModelPlugin, SpatialCompartmentPlugin, QualModelPlugin, GroupsModelPlugin, FbcSBasePlugin, FbcModelPlugin, DistribSBasePlugin, CompSBMLDocumentPlugin, CompSBasePlugin, and CompModelPlugin.

◆ getElementBySId()

SBase * SBasePlugin::getElementBySId ( const std::string &  id)
virtual

Return the first child object found with a given identifier.

This method searches all the subobjects under this one, compares their identifiers to id, and returns the first one that machines. It uses SBasePlugin::getAllElements(ElementFilter* filter) to get the list of identifiers, so the order in which identifiers are searched is the order in which they appear in the results returned by that method.

Normally, SId type identifier values are unique across a model in SBML. However, in some circumstances they may not be, such as if a model is invalid because of multiple objects having the same identifier.

Parameters
idstring representing the identifier of the object to find.
Returns
pointer to the first object with the given id.

Reimplemented in SpatialParameterPlugin, SpatialModelPlugin, SpatialCompartmentPlugin, QualModelPlugin, GroupsModelPlugin, FbcSBasePlugin, FbcModelPlugin, DistribSBasePlugin, CompSBMLDocumentPlugin, CompSBasePlugin, and CompModelPlugin.

◆ getElementNamespace()

const std::string & SBasePlugin::getElementNamespace ( ) const

Returns the namespace URI of the package to which this plugin object belongs.

Returns
the XML namespace URI of the SBML Level 3 package implemented by this libSBML package extension.

◆ getLevel()

unsigned int SBasePlugin::getLevel ( ) const

Returns the SBML Level of the package extension of this plugin object.

Returns
the SBML Level.
See also
getVersion()

◆ getPackageName()

const std::string & SBasePlugin::getPackageName ( ) const

Returns the short-form name of the package to which this plugin object belongs.

Returns
the short-form package name (or nickname) of the SBML package implemented by this package extension.

◆ getPackageVersion()

unsigned int SBasePlugin::getPackageVersion ( ) const

Returns the package version of the package extension of this plugin object.

Returns
the package version of the package extension of this plugin object.
See also
getLevel()
getVersion()

◆ getParentSBMLObject() [1/2]

SBase * SBasePlugin::getParentSBMLObject ( )

Returns the parent object to which this plugin object is connected.

Returns
the parent object of this object.

◆ getParentSBMLObject() [2/2]

const SBase * SBasePlugin::getParentSBMLObject ( ) const

Returns the parent object to which this plugin object is connected.

Returns
the parent object of this object.

◆ getPrefix()

const std::string & SBasePlugin::getPrefix ( ) const

Returns the XML namespace prefix of the package to which this plugin object belongs.

Returns
the XML namespace prefix of the SBML Level 3 package implemented by this libSBML package extension.

◆ getSBMLDocument() [1/2]

SBMLDocument * SBasePlugin::getSBMLDocument ( )

Returns the SBMLDocument object containing this object instance.

LibSBML uses the class SBMLDocument as a top-level container for storing SBML content and data associated with it (such as warnings and error messages). An SBML model in libSBML is contained inside an SBMLDocument object. SBMLDocument corresponds roughly to the class SBML defined in the SBML Level 3 and Level 2 specifications, but it does not have a direct correspondence in SBML Level 1. (But, it is created by libSBML no matter whether the model is Level 1, Level 2 or Level 3.)

This method allows the caller to obtain the SBMLDocument for the current object.

Returns
the parent SBMLDocument object of this plugin object.
See also
getParentSBMLObject()

◆ getSBMLDocument() [2/2]

const SBMLDocument * SBasePlugin::getSBMLDocument ( ) const

Returns the SBMLDocument object containing this object instance.

LibSBML uses the class SBMLDocument as a top-level container for storing SBML content and data associated with it (such as warnings and error messages). An SBML model in libSBML is contained inside an SBMLDocument object. SBMLDocument corresponds roughly to the class SBML defined in the SBML Level 3 and Level 2 specifications, but it does not have a direct correspondence in SBML Level 1. (But, it is created by libSBML no matter whether the model is Level 1, Level 2 or Level 3.)

This method allows the caller to obtain the SBMLDocument for the current object.

Returns
the parent SBMLDocument object of this plugin object.
See also
getParentSBMLObject()

◆ getURI()

std::string SBasePlugin::getURI ( ) const

Returns the XML namespace URI for the package to which this object belongs.

In the XML representation of an SBML document, XML namespaces are used to identify the origin of each XML construct used. XML namespaces are identified by their unique resource identifiers (URIs). The core SBML specifications stipulate the namespaces that must be used for core SBML constructs; for example, all XML elements that belong to SBML Level 3 Version 1 Core must be placed in the XML namespace identified by the URI "http://www.sbml.org/sbml/level3/version1/core". Individual SBML Level 3 packages define their own XML namespaces; for example, all elements belonging to the SBML Level 3 Layout Version 1 package must be placed in the XML namespace "http://www.sbml.org/sbml/level3/version1/layout/version1/".

This method first looks into the SBMLNamespaces object possessed by the parent SBMLDocument object of the current object. If this cannot be found, this method returns the result of getElementNamespace().

Returns
a string, the URI of the XML namespace to which this object belongs.
See also
getPackageName()
getElementNamespace()
getSBMLDocument()

◆ getVersion()

unsigned int SBasePlugin::getVersion ( ) const

Returns the Version within the SBML Level of the package extension of this plugin object.

Returns
the SBML Version.
See also
getLevel()

◆ isValidTypeForList()

virtual bool SBasePlugin::isValidTypeForList ( SBase item) const
virtual

◆ operator=()

SBasePlugin & SBasePlugin::operator= ( const SBasePlugin orig)

Assignment operator for SBasePlugin.

Parameters
origthe object whose values are used as the basis of the assignment.

◆ renameMetaIdRefs()

virtual void SBasePlugin::renameMetaIdRefs ( const std::string &  oldid,
const std::string &  newid 
)
virtual

Replaces all uses of a given meta identifier attribute value with another value.
In SBML, object "meta" identifiers are of the XML data type ID; the SBML object attribute itself is typically named metaid. All attributes that hold values referring to values of type ID are of the XML data type IDREF. They are also sometimes informally referred to as "metaid refs", in analogy to the SBML-defined type SIdRef.

This method works by looking at all meta-identifier attribute values, comparing the identifiers to the value of oldid. If any matches are found, the matching identifiers are replaced with newid. The method does not descend into child elements.

Parameters
oldidthe old identifier.
newidthe new identifier.

◆ renameSIdRefs()

virtual void SBasePlugin::renameSIdRefs ( const std::string &  oldid,
const std::string &  newid 
)
virtual

Replaces all uses of a given SIdRef type attribute value with another value.

In SBML, object identifiers are of a data type called SId. In SBML Level 3, an explicit data type called SIdRef was introduced for attribute values that refer to SId values; in previous Levels of SBML, this data type did not exist and attributes were simply described to as "referring to an identifier", but the effective data type was the same as SIdRef in Level 3. These and other methods of libSBML refer to the type SIdRef for all Levels of SBML, even if the corresponding SBML specification did not explicitly name the data type.

This method works by looking at all attributes and (if appropriate) mathematical formulas in MathML content, comparing the referenced identifiers to the value of oldid. If any matches are found, the matching values are replaced with newid. The method does not descend into child elements.

Parameters
oldidthe old identifier.
newidthe new identifier.

Reimplemented in FbcReactionPlugin.

◆ renameUnitSIdRefs()

virtual void SBasePlugin::renameUnitSIdRefs ( const std::string &  oldid,
const std::string &  newid 
)
virtual

Replaces all uses of a given UnitSIdRef type attribute value with another value.
In SBML, unit definitions have identifiers of type UnitSId. In SBML Level 3, an explicit data type called UnitSIdRef was introduced for attribute values that refer to UnitSId values; in previous Levels of SBML, this data type did not exist and attributes were simply described to as "referring to a unit identifier", but the effective data type was the same as UnitSIdRef in Level 3. These and other methods of libSBML refer to the type UnitSIdRef for all Levels of SBML, even if the corresponding SBML specification did not explicitly name the data type.

This method works by looking at all unit identifier attribute values (including, if appropriate, inside mathematical formulas), comparing the referenced unit identifiers to the value of oldid. If any matches are found, the matching values are replaced with newid. The method does not descend into child elements.

Parameters
oldidthe old identifier.
newidthe new identifier.

◆ setElementNamespace()

int SBasePlugin::setElementNamespace ( const std::string &  uri)

Sets the XML namespace to which this object belongs.

In the XML representation of an SBML document, XML namespaces are used to identify the origin of each XML construct used. XML namespaces are identified by their unique resource identifiers (URIs). The core SBML specifications stipulate the namespaces that must be used for core SBML constructs; for example, all XML elements that belong to SBML Level 3 Version 1 Core must be placed in the XML namespace identified by the URI "http://www.sbml.org/sbml/level3/version1/core". Individual SBML Level 3 packages define their own XML namespaces; for example, all elements belonging to the SBML Level 3 Layout Version 1 package must be placed in the XML namespace "http://www.sbml.org/sbml/level3/version1/layout/version1/".
Parameters
urithe URI to assign to this object.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. This particular function only does one thing irrespective of user input or object state, and thus will only return a single value:
See also
getElementNamespace()
Examples
convertLayout.cpp.