Skip to content

Commit 73584f4

Browse files
committed
PluginEntry: enable adding custom factories
to derived classes
1 parent d2ef4a8 commit 73584f4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/clap/helpers/plugin-entry.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ namespace clap { namespace helpers {
4141
virtual void deinit() noexcept {}
4242
virtual const void *getFactory(const char *factoryId) const noexcept { return nullptr; };
4343
virtual bool enableDraftFactories() const noexcept { return false; }
44+
// needed for adding custom factories to a class derived from PluginEntry
45+
template <typename T,
46+
typename = typename std::enable_if<std::is_base_of<PluginEntry, T>::value &&
47+
std::is_default_constructible<T>::value>::type>
48+
static const T &getInstance() noexcept;
4449

4550
// clap_plugin_factory
4651
virtual bool implementsPluginFactory() const noexcept { return false; }

include/clap/helpers/plugin-entry.hxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ namespace clap { namespace helpers {
2525
};
2626
}
2727

28+
template <MisbehaviourHandler h, CheckingLevel l>
29+
template <typename T, typename ValidImpl>
30+
const T &PluginEntry<h, l>::getInstance() noexcept {
31+
assert(_instance &&
32+
"make sure to call this only between plugin_entry.init and plugin_entry.deinit");
33+
return *static_cast<const T *>(_instance.get());
34+
}
35+
2836
template <MisbehaviourHandler h, CheckingLevel l>
2937
int32_t PluginEntry<h, l>::getPluginIndexForPluginId(const char *pluginId) const noexcept {
3038
const auto count = pluginFactoryGetPluginCount();

0 commit comments

Comments
 (0)