libSBML C API  5.18.0
SBasePlugin_t Class Reference

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_t class is libSBML's base class for extensions of core SBML component objects. SBasePlugin_t 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_t for a package implementation

LibSBML package extensions can extend existing libSBML objects such as Model_t using SBasePlugin_t as a base class, to hold attributes and/or subcomponents necessary for the SBML package being implemented. Package developers must implement an SBasePlugin_t extended class for each element to be extended (e.g., Model_t, Reaction_t, 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_t 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_t, Reaction_t, etc., will be the ones that need to be extended using SBasePlugin_t.

For example, the Layout_t package makes additions to Model_t, SpeciesReference_t, and the <sbml> element (which is represented in libSBML by SBMLDocument_t). This means that the Layout_t package extension in libSBML needs to define extended versions of Model_t, SpeciesReference_t and SBMLDocument_t. Elements other than the SBML document need to be implemented using SBasePlugin_t; the document component must be implemented using SBMLDocumentPlugin_t instead.

2. Create a SBasePlugin_t subclass for each extended SBML component

A new class definition that subclasses SBasePlugin_t needs to be created for each SBML component to be extended by the package. For instance, the Layout_t package needs LayoutModelPlugin_t and LayoutSpeciesReferencePlugin_t. (As mentioned above, the Layout_t class also needs LayoutSBMLDocumentPlugin_t, but this one is implemented using SBMLDocumentPlugin_t instead of SBasePlugin_t.) Below, we describe in detail the different parts of an SBasePlugin_t 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_t class or from SBase_t.

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_t class (in the file GroupsModelPlugin.h):

2.2 Override SBasePlugin_t class-related methods

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

2.3 Override SBasePlugin_t 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_t 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_t& 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_t& 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_t to achieve this.

2.4 Override SBasePlugin_t 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_t methods and provide appropriate implementations:

  • createObject(XMLInputStream_t& stream): Subclasses must override this method to create, store, and then return an SBML object corresponding to the next XMLToken_t in the XMLInputStream_t. To do this, implementations can use methods like peek() on XMLInputStream_t to test if the next object in the stream is something expected for the package. For example, LayoutModelPlugin_t uses peek() to examine the next element in the input stream, then tests that element against the Layout_t namespace and the element name "listOfLayouts" to see if it's the single subcomponent (ListOfLayouts_t) permitted on a Model_t object using the Layout_t package. If it is, it returns the appropriate object.
  • connectToParent(SBase_t *sbase): This creates a parent-child relationship between a given extended component and its subcomponent(s).
  • setSBMLDocument(SBMLDocument_t* d): This method should set the parent SBMLDocument_t object on the subcomponent object instances, so that the subcomponent instances know which SBMLDocument_t 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_t& 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_t* parentObject, XMLInputStream_t& stream): This function should be overridden if elements of annotation, notes, MathML content, etc., need to be directly parsed from the given XMLInputStream_t 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_t 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_t& 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

SBasePlugin_tSBasePlugin_clone (SBasePlugin_t *plugin)
 Creates a deep copy of the given SBasePlugin_t structure. More...
 
int SBasePlugin_connectToParent (SBasePlugin_t *plugin, SBase_t *sbase)
 Sets the parent SBML structure of this plugin structure to this structure and child elements (if any). More...
 
SBase_tSBasePlugin_createObject (SBasePlugin_t *plugin, XMLInputStream_t *stream)
 Subclasses must override this method to create, store, and then return an SBML structure corresponding to the next XMLToken_t in the XMLInputStream_t if they have their specific elements. More...
 
int SBasePlugin_free (SBasePlugin_t *plugin)
 Frees the given SBasePlugin_t structure. More...
 
unsigned int SBasePlugin_getLevel (SBasePlugin_t *plugin)
 Returns the SBML level of the package extension of this plugin structure. More...
 
const char * SBasePlugin_getPackageName (SBasePlugin_t *plugin)
 Returns the package name of the given plugin structure. More...
 
unsigned int SBasePlugin_getPackageVersion (SBasePlugin_t *plugin)
 Returns the package version of the package extension of this plugin structure. More...
 
SBase_tSBasePlugin_getParentSBMLObject (SBasePlugin_t *plugin)
 Returns the parent SBase_t structure to which this plugin structure is connected. More...
 
const char * SBasePlugin_getPrefix (SBasePlugin_t *plugin)
 Returns the prefix of the given plugin structure. More...
 
SBMLDocument_tSBasePlugin_getSBMLDocument (SBasePlugin_t *plugin)
 Returns the parent SBMLDocument_t of this plugin structure. More...
 
const char * SBasePlugin_getURI (SBasePlugin_t *plugin)
 Returns the XML namespace (URI) of the package extension of the given plugin structure. More...
 
unsigned int SBasePlugin_getVersion (SBasePlugin_t *plugin)
 Returns the SBML version of the package extension of this plugin structure. More...
 
int SBasePlugin_hasRequiredAttributes (SBasePlugin_t *plugin)
 Checks if the plugin structure has all the required attributes. More...
 
int SBasePlugin_hasRequiredElements (SBasePlugin_t *plugin)
 Checks if the plugin structure has all the required elements. More...
 
int SBasePlugin_readOtherXML (SBasePlugin_t *plugin, SBase_t *parentObject, XMLInputStream_t *stream)
 Subclasses should override this method to read (and store) XHTML, MathML, etc. More...
 
int SBasePlugin_setSBMLDocument (SBasePlugin_t *plugin, SBMLDocument_t *d)
 Sets the parent SBMLDocument_t of th plugin structure. More...
 
int SBasePlugin_writeAttributes (SBasePlugin_t *plugin, XMLOutputStream_t *stream)
 Subclasses must override this method to write their XML attributes to the XMLOutputStream_t if they have their specific attributes. More...
 
int SBasePlugin_writeElements (SBasePlugin_t *plugin, XMLInputStream_t *stream)
 Subclasses must override this method to write out their contained SBML structures as XML elements if they have their specific elements. More...
 
int SBasePlugin_writeXMLNS (SBasePlugin_t *plugin, XMLOutputStream_t *stream)
 Subclasses should override this method to write required xmlns attributes to the XMLOutputStream_t (if any). More...
 
SBasePluginCreatorBase_tSBasePluginCreator_clone (SBasePluginCreatorBase_t *creator)
 Creates a deep copy of the given SBasePluginCreatorBase_t structure. More...
 
SBasePlugin_tSBasePluginCreator_createPlugin (SBasePluginCreatorBase_t *creator, const char *uri, const char *prefix, const XMLNamespaces_t *xmlns)
 Creates an SBasePlugin_t structure with the given uri and the prefix of the target package extension. More...
 
int SBasePluginCreator_free (SBasePluginCreatorBase_t *creator)
 Frees the given SBasePluginCreatorBase_t structure. More...
 
unsigned int SBasePluginCreator_getNumOfSupportedPackageURI (SBasePluginCreatorBase_t *creator)
 Returns the number of supported packages by the given creator structure. More...
 
char * SBasePluginCreator_getSupportedPackageURI (SBasePluginCreatorBase_t *creator, unsigned int index)
 Returns a copy of the package uri with the specified index. More...
 
const SBaseExtensionPoint_tSBasePluginCreator_getTargetExtensionPoint (SBasePluginCreatorBase_t *creator)
 Returns the SBaseExtensionPoint_t tied to this creator structure. More...
 
const char * SBasePluginCreator_getTargetPackageName (SBasePluginCreatorBase_t *creator)
 Returns the target package name of the creator structure. More...
 
int SBasePluginCreator_getTargetSBMLTypeCode (SBasePluginCreatorBase_t *creator)
 Returns the SBMLTypeCode_t tied to the creator structure. More...
 
int SBasePluginCreator_isSupported (SBasePluginCreatorBase_t *creator, const char *uri)
 Returns 1 (true) if a package with the given namespace is supported. More...
 

Member Function Documentation

SBasePlugin_t * SBasePlugin_clone ( SBasePlugin_t plugin)

Creates a deep copy of the given SBasePlugin_t structure.

Parameters
pluginthe SBasePlugin_t structure to be copied.
Returns
a (deep) copy of the given SBasePlugin_t structure.
int SBasePlugin_connectToParent ( SBasePlugin_t plugin,
SBase_t sbase 
)

Sets the parent SBML structure of this plugin structure to this structure and child elements (if any).

(Creates a child-parent relationship by this plugin structure)

This function is called when this structure is created by the parent element. Subclasses must override this this function if they have one or more child elements. Also, SBasePlugin_connectToParent() must be called in the overridden function.

Parameters
pluginthe SBasePlugin_t structure.
sbasethe SBase_t structure to use.
See also
SBasePlugin_setSBMLDocument
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
SBase_t * SBasePlugin_createObject ( SBasePlugin_t plugin,
XMLInputStream_t stream 
)

Subclasses must override this method to create, store, and then return an SBML structure corresponding to the next XMLToken_t in the XMLInputStream_t if they have their specific elements.

Parameters
pluginthe SBasePlugin_t structure.
streamthe XMLInputStream_t structure to read from.
Returns
the SBML structure corresponding to next XMLToken_t in the XMLInputStream_t or NULL if the token was not recognized or plugin or stream were NULL.
int SBasePlugin_free ( SBasePlugin_t plugin)

Frees the given SBasePlugin_t structure.

Parameters
pluginthe SBasePlugin_t structure to be freed.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
unsigned int SBasePlugin_getLevel ( SBasePlugin_t plugin)

Returns the SBML level of the package extension of this plugin structure.

Parameters
pluginthe SBasePlugin_t structure.
Returns
the SBML level of the package extension of this plugin structure or SBML_INT_MAX if the structure is invalid.
const char * SBasePlugin_getPackageName ( SBasePlugin_t plugin)

Returns the package name of the given plugin structure.

Parameters
pluginthe plugin structure.
Returns
the package name of the given plugin structure, or NULL in case an invalid plugin structure is provided.
unsigned int SBasePlugin_getPackageVersion ( SBasePlugin_t plugin)

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

Parameters
pluginthe SBasePlugin_t structure.
Returns
the package version of the package extension of this plugin structure or SBML_INT_MAX if the structure is invalid.
SBase_t * SBasePlugin_getParentSBMLObject ( SBasePlugin_t plugin)

Returns the parent SBase_t structure to which this plugin structure is connected.

Parameters
pluginthe SBasePlugin_t structure.
Returns
the parent SBase_t structure to which this plugin structure is connected or NULL if sbase structure is set, or the plugin structure is invalid.
const char * SBasePlugin_getPrefix ( SBasePlugin_t plugin)

Returns the prefix of the given plugin structure.

Parameters
pluginthe plugin structure.
Returns
the prefix of the given plugin structure, or NULL in case an invalid plugin structure is provided.
SBMLDocument_t * SBasePlugin_getSBMLDocument ( SBasePlugin_t plugin)

Returns the parent SBMLDocument_t of this plugin structure.

Parameters
pluginthe SBasePlugin_t structure.
Returns
the parent SBMLDocument_t structure of this plugin structure or NULL if no document is set, or the plugin structure is invalid.
const char * SBasePlugin_getURI ( SBasePlugin_t plugin)

Returns the XML namespace (URI) of the package extension of the given plugin structure.

Parameters
pluginthe plugin structure.
Returns
the URI of the package extension of this plugin structure, or NULL in case an invalid plugin structure is provided.
unsigned int SBasePlugin_getVersion ( SBasePlugin_t plugin)

Returns the SBML version of the package extension of this plugin structure.

Parameters
pluginthe SBasePlugin_t structure.
Returns
the SBML version of the package extension of this plugin structure or SBML_INT_MAX if the structure is invalid.
int SBasePlugin_hasRequiredAttributes ( SBasePlugin_t plugin)

Checks if the plugin structure has all the required attributes.

Subclasses should override this function if they have their specific attributes.

Parameters
pluginthe SBasePlugin_t structure.
Returns
1 (true) if this plugin structure has all the required attributes, otherwise 0 (false) will be returned. If an invalid plugin was provided LIBSBML_INVALID_OBJECT is returned.
int SBasePlugin_hasRequiredElements ( SBasePlugin_t plugin)

Checks if the plugin structure has all the required elements.

Subclasses should override this function if they have their specific elements.

Parameters
pluginthe SBasePlugin_t structure.
Returns
1 (true) if this plugin structure has all the required elements, otherwise 0 (false) will be returned. If an invalid plugin was provided LIBSBML_INVALID_OBJECT is returned.
int SBasePlugin_readOtherXML ( SBasePlugin_t plugin,
SBase_t parentObject,
XMLInputStream_t stream 
)

Subclasses should override this method to read (and store) XHTML, MathML, etc.

directly from the XMLInputStream_t if the target elements can't be parsed by SBase_t::readAnnotation() and/or SBase_readNotes() functions

Parameters
pluginthe SBasePlugin_t structure.
parentObjectthe SBase_t structure that will store the annotation.
streamthe XMLInputStream_t structure to read from.
Returns
1 (true) if the subclass read from the stream, 0 (false) otherwise. If an invalid plugin or stream was provided LIBSBML_INVALID_OBJECT is returned.
int SBasePlugin_setSBMLDocument ( SBasePlugin_t plugin,
SBMLDocument_t d 
)

Sets the parent SBMLDocument_t of th plugin structure.

Subclasses which contain one or more SBase_t derived elements must override this function.

Parameters
pluginthe SBasePlugin_t structure.
dthe SBMLDocument_t structure to use.
See also
SBasePlugin_connectToParent
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
int SBasePlugin_writeAttributes ( SBasePlugin_t plugin,
XMLOutputStream_t stream 
)

Subclasses must override this method to write their XML attributes to the XMLOutputStream_t if they have their specific attributes.

Parameters
pluginthe SBasePlugin_t structure.
streamthe XMLOutputStream_t structure.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
int SBasePlugin_writeElements ( SBasePlugin_t plugin,
XMLInputStream_t stream 
)

Subclasses must override this method to write out their contained SBML structures as XML elements if they have their specific elements.

Parameters
pluginthe SBasePlugin_t structure.
streamthe XMLOutputStream_t structure to write to.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
int SBasePlugin_writeXMLNS ( SBasePlugin_t plugin,
XMLOutputStream_t stream 
)

Subclasses should override this method to write required xmlns attributes to the XMLOutputStream_t (if any).

The xmlns attribute will be written in the element to which the structure is connected. For example, xmlns attributes written by this function will be added to Model_t element if this plugin structure connected to the Model_t element.

Parameters
pluginthe SBasePlugin_t structure.
streamthe XMLOutputStream_t structure.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
SBasePluginCreatorBase_t * SBasePluginCreator_clone ( SBasePluginCreatorBase_t creator)

Creates a deep copy of the given SBasePluginCreatorBase_t structure.

Parameters
creatorthe SBasePluginCreatorBase_t structure to be copied.
Returns
a (deep) copy of the given SBasePluginCreatorBase_t structure.
SBasePlugin_t * SBasePluginCreator_createPlugin ( SBasePluginCreatorBase_t creator,
const char *  uri,
const char *  prefix,
const XMLNamespaces_t xmlns 
)

Creates an SBasePlugin_t structure with the given uri and the prefix of the target package extension.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
urithe package extension uri.
prefixthe package extension prefix.
xmlnsthe package extension namespaces.
Returns
an SBasePlugin_t structure with the given uri and the prefix of the target package extension, or NULL in case an invalid creator, uri or prefix was given.
int SBasePluginCreator_free ( SBasePluginCreatorBase_t creator)

Frees the given SBasePluginCreatorBase_t structure.

Parameters
creatorthe SBasePluginCreatorBase_t structure to be freed.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
unsigned int SBasePluginCreator_getNumOfSupportedPackageURI ( SBasePluginCreatorBase_t creator)

Returns the number of supported packages by the given creator structure.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
Returns
the number of supported packages by the given creator structure.
char * SBasePluginCreator_getSupportedPackageURI ( SBasePluginCreatorBase_t creator,
unsigned int  index 
)

Returns a copy of the package uri with the specified index.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
indexthe index of the package uri to return.
Returns
a copy of the package uri with the specified index (Has to be freed by the caller). If creator is invalid NULL will be returned.
const SBaseExtensionPoint_t * SBasePluginCreator_getTargetExtensionPoint ( SBasePluginCreatorBase_t creator)

Returns the SBaseExtensionPoint_t tied to this creator structure.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
Returns
the SBaseExtensionPoint_t of the creator structure, or NULL if creator is invalid.
const char * SBasePluginCreator_getTargetPackageName ( SBasePluginCreatorBase_t creator)

Returns the target package name of the creator structure.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
Returns
the target package name of the creator structure, or NULL if creator is invalid.
int SBasePluginCreator_getTargetSBMLTypeCode ( SBasePluginCreatorBase_t creator)

Returns the SBMLTypeCode_t tied to the creator structure.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
Returns
the SBMLTypeCode_t tied with the creator structure or LIBSBML_INVALID_OBJECT.
int SBasePluginCreator_isSupported ( SBasePluginCreatorBase_t creator,
const char *  uri 
)

Returns 1 (true) if a package with the given namespace is supported.

Parameters
creatorthe SBasePluginCreatorBase_t structure.
urithe package uri to test.
Returns
1 (true) if a package with the given namespace is supported, 0 (false) otherwise.