static std::unique_ptr<Base> create( key_type const& key ); // (1)
template< typename Config >
static std::unique_ptr<Base> create( key_type const& key, Config const& config ); // (2)
Member of plugin::Plugin<Base>.
Creates an instance of the plugin registered under key, and returns it as std::unique_ptr<Base>.
- Uses the plugin's default factory (
new T()). Available for every registered plugin. - Uses the plugin's config factory.
configis wrapped instd::anyand forwarded to the catalog; the registered factorystd::any_casts it back to the concrete type it was registered with and callsnew T( cfg ). Only available for plugins registered withREGISTER_WITH_CONFIG.
Both simply forward to catalog().create(...).
Parameters
| Name | Description |
|---|---|
key | The registered name. For REGISTER(T, Base) this is "T"; for REGISTERBYNAME(name, ...) it is "name". |
config | A config object whose type must match the Config in the plugin's REGISTER_WITH_CONFIG. Deduced as Config. |
Return value
A std::unique_ptr<Base> owning the new instance, or nullptr if key is not registered.
Exceptions
| Thrown | When |
|---|---|
std::runtime_error | (2) used on a plugin registered without a config factory. |
std::bad_any_cast | (2) config's type differs from the registered Config. |
anything T's constructor throws | propagated unchanged. |
key not found is not an exception — the return is nullptr.
Examples
// (1) default
auto sq = Shape::create( "Square" );
if( sq ) sq->setSize( 15 );
// (2) config
auto c = Shape::create( "Circle", Circle::Config{ .r = 42 } );
// unknown key
auto x = Shape::create( "Hexagon" ); // x == nullptr
// misuse
auto s = Shape::create( "Square", Circle::Config{ 1 } ); // throws std::runtime_error
auto e = Shape::create( "Circle", Ellipse::Config{ 1,2 } ); // throws std::bad_any_cast
Notes
- The
Configtemplate parameter is deduced from the argument; you never write it explicitly.create<Circle::Config>("Circle", cfg)also compiles but adds nothing. - A plugin registered with
REGISTER_WITH_CONFIGresponds to both overloads —create("Circle")callsCircle(). - Thread-safe:
createtakes the catalog's shared (read) lock.

