10#ifndef HPP_ALIB_LANG_PLUGINS
11#define HPP_ALIB_LANG_PLUGINS 1
19#include "alib/lang/commonenumdefs.hpp"
46template<
typename TPlugin,
typename TPriorities>
88template<
typename TPlugin,
typename TPriorities>
151 ALIB_ASSERT_ERROR( plugin !=
nullptr,
"FSPLUGINS",
"Nullptr provided for plugin." )
154 std::has_virtual_destructor<TPlugin>::value
156 "Can't take responsibility for plug-in destruction. TPlugin has no virtual destructor.")
162 [plugin,
this](
Slot& ppp)
164 ALIB_ASSERT_ERROR( ppp.plugin->GetPriority() != plugin->GetPriority(),
"FSPLUGINS",
165 "PluginContainer::InsertPlugin(): Plug-in with same priority exists" )
167 return ppp.plugin->GetPriority() < plugin->GetPriority();
170 Slot { plugin, responsibility == lang::Responsibility::Transfer }
191 return pair.plugin == plugIn;
199 ALIB_WARNING(
"PluginContainer::RemovePlugin(): Plug-in not found for removal." )
215 "FSPLUGINS",
"PluginContainer::RemovePlugin(): Index out of bounds: ", idx )
233 TPlugin* plugin=
nullptr;
235 [priority, &plugin](
Slot& entry)
237 if( entry.priority == priority)
239 plugin= entry.plugin;
247 "PluginContainer::RemovePlugin(): No Plug-in was removed " )
282 return plugins[size_t(number)].plugin;
294 return plugins[size_t(number)].priority;
308 [priority](
Slot& pair) { return pair.priority == priority; } );
325 template<
typename TPluginType>
328 return dynamic_cast<TPluginType*
>(
GetPlugin( priority ) );
337 template<
typename TPluginType>
340 TPluginType* cast=
nullptr;
342 if( (cast=
dynamic_cast<TPluginType*
>( ppp.plugin )) !=
nullptr )
void RemovePlugin(integer idx)
TPlugin * GetPlugin(integer number)
TPlugin PluginType
This exposes the template parameter pTPlugin to the outer world.
TPriorities GetPriority(integer number)
bool RemovePlugin(TPlugin *plugIn)
void InsertPlugin(TPlugin *plugin, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
TPlugin * RemovePlugin(TPriorities priority)
TPriorities PrioritiesType
This exposes the template parameter pTPlugin to the outer world.
TPlugin * GetPlugin(TPriorities priority)
TPluginType * GetPluginTypeSafe()
std::vector< Slot > plugins
The plug-ins we have attached in descending priority order.
TPluginType * GetPluginTypeSafe(TPriorities priority)
Plugin(PrioritiesType pPriority)
TPlugin PluginType
This exposes the template parameter TPlugin to the outer world.
PrioritiesType GetPriority() const
PrioritiesType priority
The priority of this plug-in.
TPriorities PrioritiesType
This exposes the template parameter pTPlugin to the outer world.
#define ALIB_WARNING(...)
#define ALIB_ASSERT_MODULE(modulename)
#define ALIB_WARNINGS_IGNORE_UNUSED_LAMBDA_CAPTURE
#define ALIB_WARNINGS_RESTORE
#define ALIB_STATIC_ASSERT(CondVariable, Cond, Message)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_ASSERT_WARNING(cond,...)
platform_specific integer
@ KeepWithSender
Keeps responsibility, e.g., when passing an object.
Type definition for elements of the list of plug-ins with their priority.
TPlugin * plugin
The plug-in.