libSBML C++ API  5.18.0
SBMLExtensionNamespaces< SBMLExtensionType > Class Template Reference
Inheritance diagram for SBMLExtensionNamespaces< SBMLExtensionType >:
[legend]

Detailed Description

template<class SBMLExtensionType>
class SBMLExtensionNamespaces< SBMLExtensionType >

Set of SBML Level + Version + namespace triples.

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.

SBMLExtensionNamespaces is a template class. It is extended from SBMLNamespaces and is meant to be used by package extensions to store the SBML Level, Version within a Level, and package version of the SBML Level 3 package implemented by a libSBML package extension.

How to use SBMLExtensionNamespaces for a package implementation

Each package extension in libSBML needs to extend and instantiate the template class SBMLExtensionNamespaces, as well as declare a specific typedef. The following sections explain these steps in detail.

1. Define the typedef

Each package needs to declare a package-specific version of the SBMLExtensionNamespaces class using a typedef. The following example code demonstrates how this is done in the case of the Layout package:

typedef SBMLExtensionNamespaces<LayoutExtension> LayoutPkgNamespaces;

This creates a new type called LayoutPkgNamespaces. The code above is usually placed in the same file that contains the SBMLExtension-derived definition of the package extension base class. In the case of the Layout package, this is in the file src/packages/layout/extension/LayoutExtension.h in the libSBML source distribution.

2. Instantiate a template instance

Each package needs to instantiate a template instance of the SBMLExtensionNamespaces class. The following example code demonstrates how this is done in the case of the Layout package:

template class LIBSBML_EXTERN SBMLExtensionNamespaces<LayoutExtension>;

In the case of the Layout package, the code above is located in the file src/packages/layout/extension/LayoutExtension.cpp in the libSBML source distribution.

3. Create constructors that accept the class

Each SBase-derived class in the package extension should implement a constructor that accepts the SBMLExtensionNamespaces-derived class as an argument. For example, in the Layout package, the class BoundBox has a constructor declared as follows

BoundingBox(LayoutPkgNamespaces* layoutns);

The implementation of this constructor must, among other things, take the argument namespace object and use it to set the XML namespace URI for the object. Again, for the BoundingBox example:

BoundingBox::BoundingBox(LayoutPkgNamespaces* layoutns)
: SBase(layoutns)
,mPosition(layoutns)
,mDimensions(layoutns)
,mPositionExplicitlySet (false)
,mDimensionsExplicitlySet (false)
{
// Standard extension actions.
setElementNamespace(layoutns->getURI());
connectToChild();
// Package-specific actions.
mPosition.setElementName("position");
// Load package extensions bound with this object (if any).
loadPlugins(layoutns);
}

Public Member Functions

int addNamespace (const std::string &uri, const std::string &prefix)
 Add an XML namespace (a pair of URI and prefix) to the set of namespaces within this SBMLNamespaces object. More...
 
int addNamespaces (const XMLNamespaces *xmlns)
 Add the given XML namespaces list to the set of namespaces within this SBMLNamespaces object. More...
 
int addPackageNamespace (const std::string &pkgName, unsigned int pkgVersion, const std::string &prefix="")
 Add an XML namespace (a pair of URI and prefix) of a package extension to the set of namespaces within this SBMLNamespaces object. More...
 
int addPackageNamespaces (const XMLNamespaces *xmlns)
 Add the XML namespaces of package extensions in the given XMLNamespace object to the set of namespaces within this SBMLNamespaces object (Non-package XML namespaces are not added by this function). More...
 
virtual ISBMLExtensionNamespaces * clone () const
 Creates and returns a deep copy of this SBMLExtensionNamespaces object. More...
 
unsigned int getLevel ()
 Get the SBML Level of this SBMLNamespaces object. More...
 
unsigned int getLevel () const
 Get the SBML Level of this SBMLNamespaces object. More...
 
XMLNamespacesgetNamespaces ()
 Get the XML namespaces list for this SBMLNamespaces object. More...
 
const XMLNamespacesgetNamespaces () const
 Get the XML namespaces list for this SBMLNamespaces object. More...
 
virtual const std::string & getPackageName () const
 Returns the name of the SBML package represented by this namespace object. More...
 
unsigned int getPackageVersion () const
 Returns the version of the SBML package represented by this namespace object. More...
 
virtual std::string getURI () const
 Returns a string representing the SBML XML namespace of this package. More...
 
unsigned int getVersion ()
 Get the SBML Version of this SBMLNamespaces object. More...
 
unsigned int getVersion () const
 Get the SBML Version of this SBMLNamespaces object. More...
 
bool isValidCombination ()
 Predicate returning true if the given set of namespaces represent a valid set. More...
 
SBMLExtensionNamespacesoperator= (const SBMLExtensionNamespaces &rhs)
 Assignment operator for SBMLExtensionNamespaces. More...
 
int removeNamespace (const std::string &uri)
 Removes an XML namespace from the set of namespaces within this SBMLNamespaces object. More...
 
int removePackageNamespace (unsigned int level, unsigned version, const std::string &pkgName, unsigned int pkgVersion)
 Removes an XML namespace of a package extension from the set of namespaces within this SBMLNamespaces object. More...
 
 SBMLExtensionNamespaces (unsigned int level=SBMLExtensionType::getDefaultLevel(), unsigned int version=SBMLExtensionType::getDefaultVersion(), unsigned int pkgVersion=SBMLExtensionType::getDefaultPackageVersion(), const std::string &prefix=SBMLExtensionType::getPackageName())
 Creates a new SBMLExtensionNamespaces object corresponding to the given SBML level, version and package version. More...
 
 SBMLExtensionNamespaces (const SBMLExtensionNamespaces &orig)
 Copy constructor; creates a copy of a SBMLExtensionNamespaces. More...
 
virtual ~SBMLExtensionNamespaces ()
 Destroys this SBMLExtensionNamespaces object. More...
 

Static Public Member Functions

static void freeSBMLNamespaces (List *supportedNS)
 Frees the list of supported namespaces as generated by getSupportedNamespaces(). More...
 
static std::string getSBMLNamespaceURI (unsigned int level, unsigned int version)
 Returns a string representing the SBML XML namespace for the given level and version of SBML. More...
 
static const ListgetSupportedNamespaces ()
 Returns a list of all supported SBMLNamespaces in this version of libsbml. More...
 
static bool isSBMLNamespace (const std::string &uri)
 Predicate returning true if the given URL is one of SBML XML namespaces. More...
 

Constructor & Destructor Documentation

template<class SBMLExtensionType >
SBMLExtensionNamespaces< SBMLExtensionType >::SBMLExtensionNamespaces ( unsigned int  level = SBMLExtensionType::getDefaultLevel(),
unsigned int  version = SBMLExtensionType::getDefaultVersion(),
unsigned int  pkgVersion = SBMLExtensionType::getDefaultPackageVersion(),
const std::string &  prefix = SBMLExtensionType::getPackageName() 
)

Creates a new SBMLExtensionNamespaces object corresponding to the given SBML level, version and package version.

Parameters
levelthe SBML Level.
versionthe SBML Version.
pkgVersionthe package version.
prefixthe prefix of the package namespace (e.g. "layout", "multi") to be added. The package's name will be used if the given string is empty (default).
Exceptions
SBMLExtensionExceptionif the extension module that supports the combination of the given SBML Level, SBML Version, package name, and package version has not been registered.
template<class SBMLExtensionType >
virtual SBMLExtensionNamespaces< SBMLExtensionType >::~SBMLExtensionNamespaces ( )
virtual

Destroys this SBMLExtensionNamespaces object.

template<class SBMLExtensionType >
SBMLExtensionNamespaces< SBMLExtensionType >::SBMLExtensionNamespaces ( const SBMLExtensionNamespaces< SBMLExtensionType > &  orig)

Copy constructor; creates a copy of a SBMLExtensionNamespaces.

Parameters
origthe SBMLExtensionNamespaces instance to copy.

Member Function Documentation

int SBMLNamespaces::addNamespace ( const std::string &  uri,
const std::string &  prefix 
)
inherited

Add an XML namespace (a pair of URI and prefix) to the set of namespaces within this SBMLNamespaces object.

Parameters
urithe XML namespace to be added.
prefixthe prefix of the namespace to be added.
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:
Examples:
example1.cpp, example2.cpp, and example3.cpp.
int SBMLNamespaces::addNamespaces ( const XMLNamespaces xmlns)
inherited

Add the given XML namespaces list to the set of namespaces within this SBMLNamespaces object.

The following code gives an example of how one could add the XHTML namespace to the list of namespaces recorded by the top-level <sbml> element of a model. It gives the new namespace a prefix of html.

try
{
sd = new SBMLDocument(3, 1);
}
{
// Here, have code to handle a truly exceptional situation. Candidate
// causes include invalid combinations of SBML Level and Version
// (impossible if hardwired as given here), running out of memory, and
// unknown system exceptions.
}
if (sn != NULL)
{
sn->add("http://www.w3.org/1999/xhtml", "html");
}
else
{
// Handle another truly exceptional situation.
}
Parameters
xmlnsthe XML namespaces to be added.
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 SBMLNamespaces::addPackageNamespace ( const std::string &  pkgName,
unsigned int  pkgVersion,
const std::string &  prefix = "" 
)
inherited

Add an XML namespace (a pair of URI and prefix) of a package extension to the set of namespaces within this SBMLNamespaces object.

The SBML Level and SBML Version of this object is used.

Parameters
pkgNamethe string of package name (e.g. "layout", "multi").
pkgVersionthe package version.
prefixthe prefix of the package namespace to be added. The package's name will be used if the given string is empty (default).
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:
Note
An XML namespace of a non-registered package extension can't be added by this function (LIBSBML_INVALID_ATTRIBUTE_VALUE will be returned).
See also
addNamespace()
int SBMLNamespaces::addPackageNamespaces ( const XMLNamespaces xmlns)
inherited

Add the XML namespaces of package extensions in the given XMLNamespace object to the set of namespaces within this SBMLNamespaces object (Non-package XML namespaces are not added by this function).

Parameters
xmlnsthe XML namespaces to be added.
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:
Note
XML namespaces of a non-registered package extensions are not added (just ignored) by this function. LIBSBML_INVALID_ATTRIBUTE_VALUE will be returned if the given xmlns is NULL.
template<class SBMLExtensionType >
virtual ISBMLExtensionNamespaces* SBMLExtensionNamespaces< SBMLExtensionType >::clone ( ) const
virtual

Creates and returns a deep copy of this SBMLExtensionNamespaces object.

Returns
a (deep) copy of this SBMLExtensionNamespaces object.

Reimplemented from SBMLNamespaces.

void SBMLNamespaces::freeSBMLNamespaces ( List supportedNS)
staticinherited

Frees the list of supported namespaces as generated by getSupportedNamespaces().

Parameters
supportedNSthe list to be freed.
unsigned int SBMLNamespaces::getLevel ( )
inherited

Get the SBML Level of this SBMLNamespaces object.

Returns
the SBML Level of this SBMLNamespaces object.
Examples:
printSupported.cpp.
unsigned int SBMLNamespaces::getLevel ( ) const
inherited

Get the SBML Level of this SBMLNamespaces object.

Returns
the SBML Level of this SBMLNamespaces object.
XMLNamespaces * SBMLNamespaces::getNamespaces ( )
inherited

Get the XML namespaces list for this SBMLNamespaces object.

SBMLNamespaces objects are used in libSBML to communicate SBML Level and Version data between constructors and other methods. The SBMLNamespaces object class holds triples consisting of SBML Level, Version, and the corresponding SBML XML namespace. Most constructors for SBML objects in libSBML take a SBMLNamespaces object as an argument, thereby allowing the constructor to produce the proper combination of attributes and other internal data structures for the given SBML Level and Version.

The plural name (SBMLNamespaces) is not a mistake, because in SBML Level 3, objects may have extensions added by Level 3 packages used by a given model and therefore may have multiple namespaces associated with them. In SBML Levels below Level 3, the SBMLNamespaces object only records one SBML Level/Version/namespace combination at a time. Most constructors for SBML objects in libSBML take a SBMLNamespaces object as an argument, thereby allowing the constructor to produce the proper combination of attributes and other internal data structures for the given SBML Level and Version.

Returns
the XML namespaces of this SBMLNamespaces object.
const XMLNamespaces * SBMLNamespaces::getNamespaces ( ) const
inherited

Get the XML namespaces list for this SBMLNamespaces object.

SBMLNamespaces objects are used in libSBML to communicate SBML Level and Version data between constructors and other methods. The SBMLNamespaces object class holds triples consisting of SBML Level, Version, and the corresponding SBML XML namespace. Most constructors for SBML objects in libSBML take a SBMLNamespaces object as an argument, thereby allowing the constructor to produce the proper combination of attributes and other internal data structures for the given SBML Level and Version.

The plural name (SBMLNamespaces) is not a mistake, because in SBML Level 3, objects may have extensions added by Level 3 packages used by a given model and therefore may have multiple namespaces associated with them. In SBML Levels below Level 3, the SBMLNamespaces object only records one SBML Level/Version/namespace combination at a time. Most constructors for SBML objects in libSBML take a SBMLNamespaces object as an argument, thereby allowing the constructor to produce the proper combination of attributes and other internal data structures for the given SBML Level and Version.

Returns
the XML namespaces of this SBMLNamespaces object.
template<class SBMLExtensionType >
virtual const std::string& SBMLExtensionNamespaces< SBMLExtensionType >::getPackageName ( ) const
virtual

Returns the name of the SBML package represented by this namespace object.

Returns
a string, the name of package.

Reimplemented from SBMLNamespaces.

template<class SBMLExtensionType >
unsigned int SBMLExtensionNamespaces< SBMLExtensionType >::getPackageVersion ( ) const

Returns the version of the SBML package represented by this namespace object.

Returns
the SBML Package Version of this SBMLExtensionNamespaces object.
std::string SBMLNamespaces::getSBMLNamespaceURI ( unsigned int  level,
unsigned int  version 
)
staticinherited

Returns a string representing the SBML XML namespace for the given level and version of SBML.

Parameters
levelthe SBML level.
versionthe SBML version.
Returns
a string representing the SBML namespace that reflects the SBML Level and Version specified.
const List * SBMLNamespaces::getSupportedNamespaces ( )
staticinherited

Returns a list of all supported SBMLNamespaces in this version of libsbml.

Returns
a list with supported SBML namespaces.
Examples:
printSupported.cpp.
template<class SBMLExtensionType >
virtual std::string SBMLExtensionNamespaces< SBMLExtensionType >::getURI ( ) const
virtual

Returns a string representing the SBML XML namespace of this package.

Returns
a string representing the SBML namespace that reflects the SBML Level and Version, and package version, of this package.

Reimplemented from SBMLNamespaces.

unsigned int SBMLNamespaces::getVersion ( )
inherited

Get the SBML Version of this SBMLNamespaces object.

Returns
the SBML Version of this SBMLNamespaces object.
Examples:
printSupported.cpp.
unsigned int SBMLNamespaces::getVersion ( ) const
inherited

Get the SBML Version of this SBMLNamespaces object.

Returns
the SBML Version of this SBMLNamespaces object.
bool SBMLNamespaces::isSBMLNamespace ( const std::string &  uri)
staticinherited

Predicate returning true if the given URL is one of SBML XML namespaces.

Parameters
urithe URI of namespace.
Returns
true if the "uri" is one of SBML namespaces, false otherwise.
bool SBMLNamespaces::isValidCombination ( )
inherited

Predicate returning true if the given set of namespaces represent a valid set.

Returns
true if the set of namespaces is valid, false otherwise.
template<class SBMLExtensionType >
SBMLExtensionNamespaces& SBMLExtensionNamespaces< SBMLExtensionType >::operator= ( const SBMLExtensionNamespaces< SBMLExtensionType > &  rhs)

Assignment operator for SBMLExtensionNamespaces.

Parameters
rhsthe SBMLExtensionNamespaces instance to assign from.
int SBMLNamespaces::removeNamespace ( const std::string &  uri)
inherited

Removes an XML namespace from the set of namespaces within this SBMLNamespaces object.

Parameters
urithe XML namespace to be added.
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 SBMLNamespaces::removePackageNamespace ( unsigned int  level,
unsigned  version,
const std::string &  pkgName,
unsigned int  pkgVersion 
)
inherited

Removes an XML namespace of a package extension from the set of namespaces within this SBMLNamespaces object.

Parameters
levelthe SBML level.
versionthe SBML version.
pkgNamethe string of package name (e.g. "layout", "multi").
pkgVersionthe package version.
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: