Defined in <plugin/PluginRegister.hh>.

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

Register CLASS (which must derive from BASE and be default-constructible) so that BASE::create(key) returns a new CLASS.

  • REGISTER(Circle, Shape) — key is "Circle" (the stringised class name).
  • REGISTERBYNAME(rounded, Circle, Shape) — key is "rounded".

REGISTER(C, B) is exactly REGISTERBYNAME(C, C, B).

Requirements

  • CLASS is defined (complete type) at the point of the macro.
  • CLASS has an accessible CLASS() default constructor.
  • BASE has a catalog — some TU ran CREATECATALOG(BASE).

Placement

File scope, in the plugin's .cpp, once per key. Not in a header (it would register once per including TU — harmless but pointless — and pollute every TU's anonymous namespace).

Example

// Square.cpp  → libSquare.so
#include "Shape.hh"
#include <plugin/PluginRegister.hh>

namespace plugin::example {

class Square : public Shape {
    unsigned int size = 0;
public:
    Square() = default;
    void setSize( unsigned int v ) override { size = v; }
    unsigned int getSize() const override { return size; }
    void printOn( std::ostream& os ) const override { os << "Square a:" << size << '\n'; }
};

REGISTER( Square, Shape );   // key "Square"

}

Host side:

Shape::load( "./libSquare.so" );
auto sq = Shape::create( "Square" );   // new plugin::example::Square

Notes

  • The key is a string, not a symbol — create("Square"), and it is case-sensitive.
  • Registering two classes under one key: the DSO loaded last wins (insert overwrites). Use distinct or namespaced keys.
  • A class needing constructor arguments uses REGISTER_WITH_CONFIG instead.
  • To also expose the class under a second name, add REGISTERAS.