Defined in <plugin/PluginRegister.hh>.

Registration is done by a file-scope object whose constructor adds an entry to the catalog and whose destructor removes it. Two class templates provide the behaviour; four families of macros generate the objects.

The class templates

template< class T, class Base >              class PluginRegisterer;
template< class T, class Base, class Config > class PluginRegistererWithConfig;
InsertsStatic factory helpers
PluginRegisterer<T, Base>Creator<Base>( CreateDefault, copy )static Base* CreateDefault()new T()
PluginRegistererWithConfig<T, Base, Config>Creator<Base>( CreateDefault, CreateFromConfig, copy )+ static Base* CreateFromConfig(std::any const&)new T( std::any_cast<Config const&>(cfg) )

Constructor signature (both):

explicit PluginRegisterer( PluginCatalog<Base>::key_type const& name, bool copy = false );

name is the catalog key. copy becomes the Creator's isAlias flag — true for the alias macros. Move construction and move assignment are = delete; the object is meant to live at file scope for the DSO's lifetime. The destructor calls Base::catalog().erase(key).

The macros

MacroKeyConfigAliasPage
REGISTER(Class, Base)"Class"noREGISTER, REGISTERBYNAME
REGISTERBYNAME(NAME, Class, Base)"NAME"noREGISTER, REGISTERBYNAME
REGISTER_WITH_CONFIG(Class, Base, Config)"Class"ConfignoREGISTERWITHCONFIG
REGISTERBYNAME_WITH_CONFIG(NAME, Class, Base, Config)"NAME"ConfignoREGISTERWITHCONFIG
REGISTERAS(NAME, Class, Base)"NAME"yesREGISTERAS, REGISTERBYNICK
REGISTERBYNICK(CNAME, Class, Base)CNAME (expression)yesREGISTERAS, REGISTERBYNICK
CREATECATALOG(Base)CREATECATALOG, CATALOG

What a macro expands to

#define REGISTER(CLASS, BASE) REGISTERBYNAME(CLASS, CLASS, BASE)

#define REGISTERBYNAME(NAME, CLASS, BASE)                                 \
  namespace {                                                             \
    static const volatile plugin::PluginRegisterer< CLASS, BASE >         \
      PLUGIN_CONCAT( REGISTERER_##NAME##_, __LINE__ )( #NAME, false );    \
  }
  • anonymous namespace — internal linkage, no cross-TU collision.
  • static const volatilevolatile stops the optimiser removing an object it thinks is unused; const documents intent.
  • __LINE__ suffix — two registrations in one file get distinct names.

Put a registration in the plugin's .cpp, at file scope, once.