Loading...
Searching...
No Matches
doc_extension_sbmlextensionnamespaces Class Reference

## Detailed Description

  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);
}