ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Public Types | Inner Classes | Public Methods | Protected Fields | List of all members
PluginContainer< pTPlugin, pTPriorities > Class Template Reference

#include <plugins.hpp>

Collaboration diagram for PluginContainer< pTPlugin, pTPriorities >:
[legend]

Class Description

template<typename pTPlugin, typename pTPriorities>
class aworx::lib::detail::PluginContainer< pTPlugin, pTPriorities >


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
pTPluginThe type of the plug-ins managed. This type is publicly exposed as TPlugin.
pTPrioritiesThe 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 59 of file lib/fs_plugins/plugins.hpp.

Public Types

using TPlugin = pTPlugin
 
using TPriorities = pTPriorities
 

Inner Classes

struct  Slot
 

Public Methods

 ~PluginContainer ()
 
integer CountPlugins ()
 
TPluginGetPlugin (integer number)
 
TPluginGetPlugin (TPriorities priority)
 
template<typename TPluginType >
TPluginType * GetPluginTypeSafe ()
 
template<typename TPluginType >
TPluginType * GetPluginTypeSafe (TPriorities priority)
 
bool HasPlugins ()
 
void InsertPlugin (TPlugin *plugin, TPriorities priority, Responsibility responsibility=Responsibility::KeepWithSender)
 
void RemovePlugin (integer idx)
 
bool RemovePlugin (TPlugin *plugIn)
 
TPluginRemovePlugin (TPriorities priority)
 

Protected Fields

std::vector< Slotplugins
 

Member Typedef Documentation

◆ TPlugin

using TPlugin = pTPlugin

This exposes the template parameter pTPlugin to the outer world.

Definition at line 67 of file lib/fs_plugins/plugins.hpp.

◆ TPriorities

using TPriorities = pTPriorities

This exposes the template parameter pTPlugin to the outer world.

Definition at line 70 of file lib/fs_plugins/plugins.hpp.

Constructor & Destructor Documentation

◆ ~PluginContainer()

~PluginContainer ( )
inline

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

Definition at line 97 of file lib/fs_plugins/plugins.hpp.

Member Function Documentation

◆ CountPlugins()

integer CountPlugins ( )
inline

Returns the number of plug-ins attached.

Returns
The quantity of attached plug-ins.

Definition at line 243 of file lib/fs_plugins/plugins.hpp.

◆ GetPlugin() [1/2]

TPlugin* 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 or nullptr if not available.

Definition at line 255 of file lib/fs_plugins/plugins.hpp.

◆ GetPlugin() [2/2]

TPlugin* 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 268 of file lib/fs_plugins/plugins.hpp.

◆ GetPluginTypeSafe() [1/2]

TPluginType* 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 301 of file lib/fs_plugins/plugins.hpp.

◆ GetPluginTypeSafe() [2/2]

TPluginType* 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 289 of file lib/fs_plugins/plugins.hpp.

◆ HasPlugins()

bool 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 234 of file lib/fs_plugins/plugins.hpp.

◆ InsertPlugin()

void InsertPlugin ( TPlugin plugin,
TPriorities  priority,
Responsibility  responsibility = Responsibility::KeepWithSender 
)
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.

Parameters
pluginThe plug-in to insert.
priorityThe priority of the plug-in.
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 125 of file lib/fs_plugins/plugins.hpp.

◆ RemovePlugin() [1/3]

void 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 187 of file lib/fs_plugins/plugins.hpp.

◆ RemovePlugin() [2/3]

bool RemovePlugin ( TPlugin plugIn)
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.

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 162 of file lib/fs_plugins/plugins.hpp.

◆ RemovePlugin() [3/3]

TPlugin* 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 206 of file lib/fs_plugins/plugins.hpp.

Member Data Documentation

◆ plugins

std::vector<Slot> plugins
protected

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

Definition at line 87 of file lib/fs_plugins/plugins.hpp.


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