namespace plugin {
    template< class Base >
    class Plugin;
}

Defined in <plugin/Plugin.hh>.

Plugin<Base> is the base every plugin hierarchy derives from, passing itself as Base (CRTP):

class Shape : public plugin::Plugin<Shape> { /* ... */ };

It contributes a small static interface bound to Base and nothing else — no data members, a defaulted copy/move, and a virtual destructor so derived objects delete correctly through a Base*.

Member type

TypeDefinition
key_typetypename PluginCatalog<Base>::key_type — i.e. std::string

Static member functions

FunctionPage
create( key )Plugin::create
create( key, config )Plugin::create
load( sharedObjectName )Plugin::load, ::catalog
catalog()Plugin::load, ::catalog

Special members

Plugin(), copy ctor, move ctor, copy assignment, move assignment are all = default. ~Plugin() is virtual and defaulted. There is no state to copy; the defaults exist so a derived class can = default its own.

The CATALOG macro

#define CATALOG( BASE ) plugin::Plugin< BASE >::catalog( )

A shorthand for reaching the catalog directly — e.g. CATALOG(Shape).size(). Equivalent to plugin::Plugin<Shape>::catalog() and to Shape::catalog() (inherited).

Example

// Shape.hh
#include <plugin/Plugin.hh>

class Shape : public plugin::Plugin<Shape>
{
public:
    virtual void printOn( std::ostream& ) const = 0;
};

// somewhere in the host
Shape::load( "./libCircle.so" );
auto s = Shape::create( "Circle" );

Notes

  • Plugin<Base> declares catalog() but does not define it. Exactly one translation unit must provide the definition with CREATECATALOG(Base), or the link fails with an undefined reference to Plugin<Base>::catalog().
  • create and load are ordinary static functions — call them as Shape::create(...) or plugin::Plugin<Shape>::create(...).
  • PLUGIN_EXPORT on the class controls symbol visibility; it expands to the platform's default-visibility attribute (<dso/DSOVisibility.hh>).