ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::lang::PluginContainer< TPlugin, TPriorities > Class Template Reference

Description:

template<typename TPlugin, typename TPriorities>
class alib::lang::PluginContainer< TPlugin, TPriorities >

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.

Template Parameters
TPluginThe type of the plug-ins managed. This type is publicly exposed as PluginType.
TPrioritiesThe enumeration type providing the default "plug-in slots" and priorities of the plug-ins managed. This type is publicly exposed as PrioritiesType.

Definition at line 68 of file plugins.inl.

Collaboration diagram for alib::lang::PluginContainer< TPlugin, TPriorities >:
[legend]

Inner Type Index:

struct  Slot
 Type definition for elements of the list of plug-ins with their priority. More...
 

Public Type Index:

using PluginList = std::vector<Slot>
 The list that stores the plugins.
 
using PluginType = TPlugin
 This exposes the template parameter pTPlugin to the outer world.
 
using PrioritiesType = TPriorities
 This exposes the template parameter pTPlugin to the outer world.
 

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)
 
TPriorities GetPriority (integer number)
 
bool HasPlugins ()
 
void InsertPlugin (TPlugin *plugin, lang::Responsibility responsibility=lang::Responsibility::KeepWithSender)
 
void RemovePlugin (integer idx)
 
bool RemovePlugin (TPlugin *plugIn)
 
TPlugin * RemovePlugin (TPriorities priority)
 

Protected Field Index:

PluginList plugins
 The plug-ins we have attached in descending priority order.
 

Type Definition Details:

◆ PluginList

template<typename TPlugin, typename TPriorities>
using alib::lang::PluginContainer< TPlugin, TPriorities >::PluginList = std::vector<Slot>

The list that stores the plugins.

Definition at line 89 of file plugins.inl.

◆ PluginType

template<typename TPlugin, typename TPriorities>
using alib::lang::PluginContainer< TPlugin, TPriorities >::PluginType = TPlugin

This exposes the template parameter pTPlugin to the outer world.

Definition at line 75 of file plugins.inl.

◆ PrioritiesType

template<typename TPlugin, typename TPriorities>
using alib::lang::PluginContainer< TPlugin, TPriorities >::PrioritiesType = TPriorities

This exposes the template parameter pTPlugin to the outer world.

Definition at line 78 of file plugins.inl.

Field Details:

◆ plugins

template<typename TPlugin, typename TPriorities>
PluginList alib::lang::PluginContainer< TPlugin, TPriorities >::plugins
protected

The plug-ins we have attached in descending priority order.

Definition at line 97 of file plugins.inl.

Constructor(s) / Destructor Details:

◆ ~PluginContainer()

template<typename TPlugin, typename TPriorities>
alib::lang::PluginContainer< TPlugin, TPriorities >::~PluginContainer ( )
inline

Destructor. All plug-ins that were inserted with parameter responsibility set to Responsibility::Transfer will be deleted.

Definition at line 107 of file plugins.inl.

Method Details:

◆ CountPlugins()

template<typename TPlugin, typename TPriorities>
integer alib::lang::PluginContainer< TPlugin, TPriorities >::CountPlugins ( )
inline

Returns the number of plug-ins attached.

Returns
The quantity of attached plug-ins.

Definition at line 247 of file plugins.inl.

◆ GetPlugin() [1/2]

template<typename TPlugin, typename TPriorities>
TPlugin * alib::lang::PluginContainer< TPlugin, TPriorities >::GetPlugin ( integer number)
inline

Returns the plug-in with the given internal number. Valid numbers are 0..[CountPlugins]. No internal checks for valid plug-in numbers are made.

Parameters
numberThe number of the plug-in requested.
Returns
The plug-in requested.

Definition at line 259 of file plugins.inl.

◆ GetPlugin() [2/2]

template<typename TPlugin, typename TPriorities>
TPlugin * alib::lang::PluginContainer< TPlugin, TPriorities >::GetPlugin ( TPriorities priority)
inline

Returns the plug-in with the given priority. If the plug-in does not exist, nullptr is returned.

Parameters
priorityThe priority of the plug-in to return.
Returns
The plug-in requested or nullptr if not available.

Definition at line 284 of file plugins.inl.

◆ GetPluginTypeSafe() [1/2]

template<typename TPlugin, typename TPriorities>
template<typename TPluginType>
TPluginType * alib::lang::PluginContainer< TPlugin, TPriorities >::GetPluginTypeSafe ( )
inline

Searches the list of plug-ins for the first found with type TPluginType.

Template Parameters
TPluginTypeThe type of the plugin to search.
Returns
The plug-in of requested type. nullptr if not available.

Definition at line 317 of file plugins.inl.

◆ GetPluginTypeSafe() [2/2]

template<typename TPlugin, typename TPriorities>
template<typename TPluginType>
TPluginType * alib::lang::PluginContainer< TPlugin, TPriorities >::GetPluginTypeSafe ( TPriorities priority)
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.

Template Parameters
TPluginTypeThe type of the plugin to search.
Parameters
priorityThe priority of the plug-in to return.
Returns
The plug-in of requested type and priority. nullptr if not available.

Definition at line 305 of file plugins.inl.

Here is the call graph for this function:

◆ GetPriority()

template<typename TPlugin, typename TPriorities>
TPriorities alib::lang::PluginContainer< TPlugin, TPriorities >::GetPriority ( integer number)
inline

Returns the priority of the plug-in with the given internal number. Valid numbers are 0..[CountPlugins]. No internal checks for valid plug-in numbers are made.

Parameters
numberThe number of the plug-in requested.
Returns
The priortiy of the plug-in.

Definition at line 271 of file plugins.inl.

◆ HasPlugins()

template<typename TPlugin, typename TPriorities>
bool alib::lang::PluginContainer< TPlugin, TPriorities >::HasPlugins ( )
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.

Returns
true if this object has any plugin set, false otherwise.

Definition at line 238 of file plugins.inl.

Here is the call graph for this function:

◆ InsertPlugin()

template<typename TPlugin, typename TPriorities>
void alib::lang::PluginContainer< TPlugin, TPriorities >::InsertPlugin ( TPlugin * plugin,
lang::Responsibility responsibility = lang::Responsibility::KeepWithSender )
inline

Adds the given plug-in to the list of plug-ins.

Parameters
pluginThe plug-in to insert.
responsibilityIf 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 129 of file plugins.inl.

◆ RemovePlugin() [1/3]

template<typename TPlugin, typename TPriorities>
void alib::lang::PluginContainer< TPlugin, TPriorities >::RemovePlugin ( integer idx)
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.

Parameters
idxThe index of the plug-in to remove.

Definition at line 192 of file plugins.inl.

Here is the call graph for this function:

◆ RemovePlugin() [2/3]

template<typename TPlugin, typename TPriorities>
bool alib::lang::PluginContainer< TPlugin, TPriorities >::RemovePlugin ( TPlugin * plugIn)
inline

Removes 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.

Parameters
plugInThe plug-in to be removed.
Returns
true if the plug-in was removed, else false, which indicates that the given plug-in was not found.

Definition at line 167 of file plugins.inl.

◆ RemovePlugin() [3/3]

template<typename TPlugin, typename TPriorities>
TPlugin * alib::lang::PluginContainer< TPlugin, TPriorities >::RemovePlugin ( TPriorities priority)
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.

Parameters
priorityThe priority of the plug-in to remove.
Returns
true if the plug-in was removed, else false, which indicates that no plug-in with the given priority was found.

Definition at line 211 of file plugins.inl.


The documentation for this class was generated from the following file: