This class usually is used as a base class for types that need to manage simple plug-ins. Within ALib itself, for example classes Configuration and Compiler inherit from this class.
Plug-ins are organized with a prioritization. This means, that plug-ins which are inserted with a higher priority are 'asked' first, and those with a lower value become 'asked' only if higher prioritized plug-ins did not answer.
However, a derived class can deviate from this behavior. Using the typical ALib class design, all internal fields are protected
, hence freely accessible by derived classes.
pTPlugin | The type of the plug-ins managed. This type is publicly exposed as TPlugin. |
pTPriorities | The enumeration type providing the default "plug-in slots" and priorities of the plug-ins managed. This type is publicly exposed as TPriorities. |
Definition at line 53 of file lang/plugins.hpp.
#include <plugins.hpp>
Inner Type Index: | |
struct | Slot |
Public Type Index: | |
using | TPlugin = pTPlugin |
using | TPriorities = pTPriorities |
Public Method Index: | |
~PluginContainer () | |
integer | CountPlugins () |
TPlugin * | GetPlugin (integer number) |
TPlugin * | GetPlugin (TPriorities priority) |
template<typename TPluginType > | |
TPluginType * | GetPluginTypeSafe () |
template<typename TPluginType > | |
TPluginType * | GetPluginTypeSafe (TPriorities priority) |
bool | HasPlugins () |
void | InsertPlugin (TPlugin *plugin, TPriorities priority, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender) |
void | RemovePlugin (integer idx) |
bool | RemovePlugin (TPlugin *plugIn) |
TPlugin * | RemovePlugin (TPriorities priority) |
using TPlugin = pTPlugin |
This exposes the template parameter pTPlugin to the outer world.
Definition at line 61 of file lang/plugins.hpp.
using TPriorities = pTPriorities |
This exposes the template parameter pTPlugin to the outer world.
Definition at line 64 of file lang/plugins.hpp.
|
protected |
The plug-ins we have attached in descending priority order.
Definition at line 81 of file lang/plugins.hpp.
|
inline |
Destructor. All plug-ins that were inserted with parameter responsibility set to Responsibility::Transfer will be deleted.
Definition at line 91 of file lang/plugins.hpp.
|
inline |
Returns the number of plug-ins attached.
Definition at line 237 of file lang/plugins.hpp.
Returns the plug-in with the given internal number. Valid numbers are 0..[CountPlugins]. No internal checks for valid plug-in numbers are made.
number | The number of the plug-in requested. |
nullptr
if not available. Definition at line 249 of file lang/plugins.hpp.
|
inline |
Returns the plug-in with the given priority. If the plug-in does not exist, nullptr
is returned.
priority | The priority of the plug-in to return. |
nullptr
if not available. Definition at line 262 of file lang/plugins.hpp.
|
inline |
Searches the list of plug-ins for the first found with type TPluginType .
TPluginType | The type of the plugin to search. |
nullptr
if not available. Definition at line 295 of file lang/plugins.hpp.
|
inline |
Same as GetPlugin, but converts the plug-in found to the template type, which has to be explicitly provided with the invocation of this method.
A type-check is performed using standard C++ dynamic_cast
mechanics. If the plugin has a different type, nullptr
is returned.
TPluginType | The type of the plugin to search. |
priority | The priority of the plug-in to return. |
nullptr
if not available. Definition at line 283 of file lang/plugins.hpp.
|
inline |
Checks if any plug-in is attached. This is useful if optional configuration objects are used. In case no plug-in was attached (by a third party), the effort to declare and search a variable can be omitted.
true
if this object has any plugin set, false
otherwise. Definition at line 228 of file lang/plugins.hpp.
|
inline |
Adds the given plug-in to the list of plug-ins.. Higher numbers for parameter priority, prioritize this plug-in against those with lower values.
Default values may be provided in case template type TPriorities is an arithmetical enumeration .
plugin | The plug-in to insert. |
priority | The priority of the plug-in. |
responsibility | If Responsibility::Transfer , the given plugin will be deleted with destruction of this object. Defaults to Responsibility::KeepWithSender which denotes that the life-cycle of the given external buffer is managed elsewhere. |
Definition at line 119 of file lang/plugins.hpp.
|
inline |
Remove the plug-in at the given idx from the list of plug-ins.
Responsibility for deletion of removed plug-ins is passed to the remover in case the plug-in was inserted with parameter responsibility set to Responsibility::Transfer .
idx | The index of the plug-in to remove. |
Definition at line 181 of file lang/plugins.hpp.
|
inline |
Remove the given plug-in from the list of plug-ins.
Responsibility for deletion of removed plug-ins is passed to the remover in case the plug-in was inserted with parameter responsibility set to Responsibility::Transfer .
plugIn | The plug-in to be removed. |
true
if the plug-in was removed, else false
, which indicates that the given plug-in was not found. Definition at line 156 of file lang/plugins.hpp.
|
inline |
Remove the plug-in with the given priority.
Responsibility for deletion of removed plug-ins is passed to the remover in case the plug-in was inserted with parameter responsibility set to Responsibility::Transfer .
priority | The priority of the plug-in to remove. |
true
if the plug-in was removed, else false
, which indicates that no plug-in with the given priority was found. Definition at line 200 of file lang/plugins.hpp.