RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
rtctk::componentFramework::FactoryRegistry< BaseIf > Class Template Referencefinal

A simple registry of various factory objects. More...

#include <factoryRegistry.hpp>

Classes

class  FactoryIf
 The base class for all factory objects that are registered in the FactoryRegistry. More...
 

Public Types

using AdapterIdType = typename BaseIf::AdapterIdType
 

Public Member Functions

 FactoryRegistry ()=default
 
 ~FactoryRegistry ()
 
void Register (const FactoryIf *factory)
 Register the factory if it was not already registered.
 
void Deregister (const FactoryIf *factory) noexcept
 Remove the factory from the registry if it was already registered.
 
const FactoryIfFindCompatibleFactory (const AdapterIdType &id) const noexcept
 Finds the first factory that can handle the given identifier.
 

Static Public Member Functions

static std::shared_ptr< FactoryRegistry< BaseIf > > GetInstance ()
 Returns the registry singleton.
 

Detailed Description

template<class BaseIf>
class rtctk::componentFramework::FactoryRegistry< BaseIf >

A simple registry of various factory objects.

This is effectively a polymorphic container of factory instances deriving from FactoryIf. The purpose of the registry is to allow registration in a single place of factories for service adapters, e.g. repository adapters, that are implemented in different shared libraries. There should be only one instance of a registry in the process for any particular abstract/base interface type given by BaseIf, i.e. for each template specialisation. Thus, various libraries should be accessing the registry through the singleton returned by the GetInstance() method, and not instantiating this class directly.

The factory registry is used to implement generic factory functions/methods for various services represented by a particular interface, e.g. to implement RuntimeRepoIf::CreateAdapter, which can have different adapters implemented for different supported backends, e.g. RuntimeRepoAdapter versus FileRuntimeRepoAdapter. By registering a factory for a particular adapter using the RegisterFactory helper class, it is possible to have different adapters implemented in different shared libraries and made available when the shared library is loaded dynamically or linked against, without needing to modify the generic factory function/method, e.g. the RuntimeRepoIf::CreateAdapter method in the above example.

Template Parameters
BaseIfThe abstract/base interface class of the service adapter instances created by the factories that are registered with the registry.

Member Typedef Documentation

◆ AdapterIdType

template<class BaseIf >
using rtctk::componentFramework::FactoryRegistry< BaseIf >::AdapterIdType = typename BaseIf::AdapterIdType

Constructor & Destructor Documentation

◆ FactoryRegistry()

template<class BaseIf >
rtctk::componentFramework::FactoryRegistry< BaseIf >::FactoryRegistry ( )
default

◆ ~FactoryRegistry()

Member Function Documentation

◆ Deregister()

template<class BaseIf >
void rtctk::componentFramework::FactoryRegistry< BaseIf >::Deregister ( const FactoryIf * factory)
noexcept

Remove the factory from the registry if it was already registered.

If the factory has been previously registered then it will be removed from the registry. Otherwise this is a no-op if the factory is not already registered.

Parameters
[in]factoryThe factory instance that should be deregistered.
Thread Safety
thread-safe

◆ FindCompatibleFactory()

template<class BaseIf >
const FactoryRegistry< BaseIf >::FactoryIf * rtctk::componentFramework::FactoryRegistry< BaseIf >::FindCompatibleFactory ( const AdapterIdType & id) const
noexcept

Finds the first factory that can handle the given identifier.

The available factories will be searched in the order that they were registered in, i.e. the shared library load order. The first one for which the FactoryIf::CanHandle method returns true will be returned by this method.

Parameters
[in]idThe identifier for which a compatible factory will be found. This could be a URI for example, depending on the AdapterIdType.
Returns
A factory instance that can create instances supporting the given identifier or a nullptr if no supporting factory can be found.
Thread Safety
thread-safe

◆ GetInstance()

template<class BaseIf >
std::shared_ptr< FactoryRegistry< BaseIf > > rtctk::componentFramework::FactoryRegistry< BaseIf >::GetInstance ( )
static

Returns the registry singleton.

This singleton should be used for registering, deregistering and finding supported factories.

Returns
A shared pointer to the singleton instance of the factory registry.
Thread Safety
thread-safe

◆ Register()

Register the factory if it was not already registered.

If the factory has not yet been added to the registry yet, it will be added. Otherwise this is a no-op if the factory is already registered.

Parameters
[in]factoryThe factory instance that should be registered.
Thread Safety
thread-safe

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