Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
Mantid::API::AlgorithmFactoryImpl Class Referencefinal

The AlgorithmFactory class is in charge of the creation of concrete instances of Algorithms. More...

#include <AlgorithmFactory.h>

Inheritance diagram for Mantid::API::AlgorithmFactoryImpl:
Mantid::Kernel::DynamicFactory< Algorithm >

Public Member Functions

 AlgorithmFactoryImpl (const AlgorithmFactoryImpl &)=delete
 
std::shared_ptr< Algorithmcreate (const std::string &, const int &) const
 Creates an instance of an algorithm. More...
 
std::pair< std::string, int > decodeName (const std::string &mangledName) const
 unmangles the names used as keys into the name and version More...
 
bool exists (const std::string &algorithmName, const int version=-1)
 Does an algorithm of the given name and version exist. More...
 
const std::unordered_set< std::string > getCategories (bool includeHidden=false) const
 Get the algorithm categories. More...
 
const std::map< std::string, bool > getCategoriesWithState () const
 Get the algorithm categories. More...
 
std::vector< AlgorithmDescriptorgetDescriptors (bool includeHidden=false, bool includeAliases=false) const
 Returns algorithm descriptors. More...
 
const std::vector< std::string > getKeys () const override
 Get the algorithm names and version - mangled use decodeName to separate. More...
 
const std::vector< std::string > getKeys (bool includeHidden) const
 Return the keys used for identifying algorithms. More...
 
boost::optional< std::string > getRealNameFromAlias (const std::string &alias) const noexcept
 Get an algorithms name from the alias map. More...
 
int highestVersion (const std::string &algorithmName) const
 Returns the highest version of the algorithm currently registered. More...
 
AlgorithmFactoryImploperator= (const AlgorithmFactoryImpl &)=delete
 
template<class C >
std::pair< std::string, int > subscribe ()
 algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe function internally More...
 
template<class T >
std::pair< std::string, int > subscribe (std::unique_ptr< Kernel::AbstractInstantiator< T > > instantiator, const SubscribeAction replaceExisting=ErrorIfExists)
 Subscribes an algorithm using a custom instantiator. More...
 
void unsubscribe (const std::string &algorithmName, const int version)
 Unsubscribe the given algorithm. More...
 
- Public Member Functions inherited from Mantid::Kernel::DynamicFactory< Algorithm >
virtual std::shared_ptr< Algorithmcreate (const std::string &className) const
 Creates a new instance of the class with the given name. More...
 
virtual AlgorithmcreateUnwrapped (const std::string &className) const
 Creates a new instance of the class with the given name, which is not wrapped in a boost shared_ptr. More...
 
void disableNotifications ()
 Disable notifications. More...
 
 DynamicFactory (const DynamicFactory &)=delete
 
void enableNotifications ()
 Enable notifications. More...
 
bool exists (const std::string &className) const
 Returns true if the given class is currently registered. More...
 
virtual const std::vector< std::string > getKeys () const
 Returns the keys in the map. More...
 
DynamicFactoryoperator= (const DynamicFactory &)=delete
 
void subscribe (const std::string &className)
 Registers the instantiator for the given class with the DynamicFactory. More...
 
void subscribe (const std::string &className, std::unique_ptr< AbstractFactory > pAbstractFactory, SubscribeAction replace=ErrorIfExists)
 Registers the instantiator for the given class with the DynamicFactory. More...
 
void unsubscribe (const std::string &className)
 Unregisters the given class and deletes the instantiator for the class. More...
 
virtual ~DynamicFactory ()=default
 Destroys the DynamicFactory and deletes the instantiators for all registered classes. More...
 

Private Types

using AliasMap = std::unordered_map< std::string, std::string >
 A typedef for the map of algorithm aliases. More...
 
using VersionMap = std::map< std::string, int >
 A typedef for the map of algorithm versions. More...
 

Private Member Functions

 AlgorithmFactoryImpl ()
 Private Constructor for singleton class. More...
 
std::shared_ptr< AlgorithmcreateAlgorithm (const std::string &name, const int version) const
 Create an algorithm object with the specified name. More...
 
std::string createName (const std::string &, const int &) const
 creates an algorithm name convolved from an name and version More...
 
const std::string extractAlgAlias (const std::shared_ptr< IAlgorithm > &alg) const
 Extract the alias of an algorithm. More...
 
const std::string extractAlgName (const std::shared_ptr< IAlgorithm > &alg) const
 Extract the name of an algorithm. More...
 
int extractAlgVersion (const std::shared_ptr< IAlgorithm > &alg) const
 Extract the version of an algorithm. More...
 
void fillHiddenCategories (std::unordered_set< std::string > *categorySet) const
 fills a set with the hidden categories More...
 
 ~AlgorithmFactoryImpl () override
 Private Destructor. More...
 

Private Attributes

AliasMap m_amap
 The map holding the alias names of registered algorithms. More...
 
VersionMap m_vmap
 The map holding the registered class names and their highest versions. More...
 

Friends

struct Mantid::Kernel::CreateUsingNew< AlgorithmFactoryImpl >
 

Additional Inherited Members

- Public Types inherited from Mantid::Kernel::DynamicFactory< Algorithm >
using AbstractFactory = AbstractInstantiator< Algorithm >
 A typedef for the instantiator. More...
 
enum  NotificationStatus
 Defines the whether notifications are dispatched. More...
 
enum  SubscribeAction
 Defines replacement behaviour. More...
 
- Public Attributes inherited from Mantid::Kernel::DynamicFactory< Algorithm >
Poco::NotificationCenter notificationCenter
 Sends notifications to observers. More...
 
- Protected Member Functions inherited from Mantid::Kernel::DynamicFactory< Algorithm >
 DynamicFactory ()
 Protected constructor for base class. More...
 

Detailed Description

The AlgorithmFactory class is in charge of the creation of concrete instances of Algorithms.

It inherits most of its implementation from the Dynamic Factory base class. It is implemented as a singleton class.

Author
Russell Taylor, Tessella Support Services plc
Date
21/09/2007

Definition at line 48 of file AlgorithmFactory.h.

Member Typedef Documentation

◆ AliasMap

using Mantid::API::AlgorithmFactoryImpl::AliasMap = std::unordered_map<std::string, std::string>
private

A typedef for the map of algorithm aliases.

Definition at line 159 of file AlgorithmFactory.h.

◆ VersionMap

using Mantid::API::AlgorithmFactoryImpl::VersionMap = std::map<std::string, int>
private

A typedef for the map of algorithm versions.

Definition at line 155 of file AlgorithmFactory.h.

Constructor & Destructor Documentation

◆ AlgorithmFactoryImpl() [1/2]

Mantid::API::AlgorithmFactoryImpl::AlgorithmFactoryImpl ( const AlgorithmFactoryImpl )
delete

◆ AlgorithmFactoryImpl() [2/2]

Mantid::API::AlgorithmFactoryImpl::AlgorithmFactoryImpl ( )
private

Private Constructor for singleton class.

Definition at line 27 of file AlgorithmFactory.cpp.

References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and Mantid::Kernel::SingletonHolder< T >::Instance().

◆ ~AlgorithmFactoryImpl()

Mantid::API::AlgorithmFactoryImpl::~AlgorithmFactoryImpl ( )
overrideprivatedefault

Private Destructor.

Member Function Documentation

◆ create()

std::shared_ptr< Algorithm > Mantid::API::AlgorithmFactoryImpl::create ( const std::string &  name,
const int &  version 
) const

Creates an instance of an algorithm.

Parameters
name:: the name of the Algorithm to create
version:: the version of the algorithm to create
Returns
a shared pointer to the created algorithm

Definition at line 42 of file AlgorithmFactory.cpp.

References createAlgorithm(), createName(), Mantid::Kernel::Logger::error(), Mantid::API::g_log, getRealNameFromAlias(), and highestVersion().

Referenced by getCategoriesWithState(), getDescriptors(), and getKeys().

◆ createAlgorithm()

std::shared_ptr< Algorithm > Mantid::API::AlgorithmFactoryImpl::createAlgorithm ( const std::string &  name,
const int  version 
) const
private

Create an algorithm object with the specified name.

Create a shared pointer to an algorithm object with the given name and version.

If the algorithm is one registered with a clean pointer rather than an instantiator then a clone is returned.

Parameters
name:: Algorithm name
version:: Algorithm version
Returns
A shared pointer to the algorithm object

Definition at line 443 of file AlgorithmFactory.cpp.

References Mantid::Kernel::DynamicFactory< Base, Comparator >::create(), and createName().

Referenced by create().

◆ createName()

std::string Mantid::API::AlgorithmFactoryImpl::createName ( const std::string &  name,
const int &  version 
) const
private

creates an algorithm name convolved from an name and version

Creates a mangled name for interal storage.

Parameters
name:: the name of the Algrorithm
version:: the version of the algroithm
Returns
a mangled name string

Definition at line 125 of file AlgorithmFactory.cpp.

Referenced by create(), createAlgorithm(), exists(), and unsubscribe().

◆ decodeName()

std::pair< std::string, int > Mantid::API::AlgorithmFactoryImpl::decodeName ( const std::string &  mangledName) const

unmangles the names used as keys into the name and version

Decodes a mangled name for interal storage.

Parameters
mangledName:: the mangled name of the Algrorithm
Returns
a pair of the name and version

Definition at line 135 of file AlgorithmFactory.cpp.

References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.

Referenced by getCategoriesWithState(), and getKeys().

◆ exists()

bool Mantid::API::AlgorithmFactoryImpl::exists ( const std::string &  algorithmName,
const int  version = -1 
)

Does an algorithm of the given name and version exist.

Does an algorithm of the given name and version exist already.

Parameters
algorithmName:: The name of the algorithm
version:: The version number. -1 checks whether anything exists
Returns
True if a matching registration is found

Definition at line 110 of file AlgorithmFactory.cpp.

References createName(), Mantid::Kernel::DynamicFactory< Base, Comparator >::exists(), and m_vmap.

Referenced by export_AlgorithmFactory().

◆ extractAlgAlias()

const std::string Mantid::API::AlgorithmFactoryImpl::extractAlgAlias ( const std::shared_ptr< IAlgorithm > &  alg) const
private

Extract the alias of an algorithm.

Parameters
alg:: the Algorithm to use
Returns
the alias of the algorithm

Definition at line 431 of file AlgorithmFactory.cpp.

◆ extractAlgName()

const std::string Mantid::API::AlgorithmFactoryImpl::extractAlgName ( const std::shared_ptr< IAlgorithm > &  alg) const
private

Extract the name of an algorithm.

Parameters
alg:: the Algrorithm to use
Returns
the name of the algroithm

Definition at line 417 of file AlgorithmFactory.cpp.

◆ extractAlgVersion()

int Mantid::API::AlgorithmFactoryImpl::extractAlgVersion ( const std::shared_ptr< IAlgorithm > &  alg) const
private

Extract the version of an algorithm.

Parameters
alg:: the Algrorithm to use
Returns
the version of the algroithm

Definition at line 425 of file AlgorithmFactory.cpp.

◆ fillHiddenCategories()

void Mantid::API::AlgorithmFactoryImpl::fillHiddenCategories ( std::unordered_set< std::string > *  categorySet) const
private

◆ getCategories()

const std::unordered_set< std::string > Mantid::API::AlgorithmFactoryImpl::getCategories ( bool  includeHidden = false) const

Get the algorithm categories.

Return the categories of the algorithms.

This includes those within the Factory itself and any cleanly constructed algorithms stored here.

Parameters
includeHiddentrue includes the hidden algorithm names and is faster, the default is false
Returns
The category strings

Definition at line 300 of file AlgorithmFactory.cpp.

References getCategoriesWithState().

◆ getCategoriesWithState()

const std::map< std::string, bool > Mantid::API::AlgorithmFactoryImpl::getCategoriesWithState ( ) const

Get the algorithm categories.

Return the categories of the algorithms.

This includes those within the Factory itself and any cleanly constructed algorithms stored here.

Returns
The map of the categories, together with a true false value difining if they are hidden

Definition at line 256 of file AlgorithmFactory.cpp.

References create(), decodeName(), fillHiddenCategories(), and getKeys().

Referenced by getCategories().

◆ getDescriptors()

std::vector< AlgorithmDescriptor > Mantid::API::AlgorithmFactoryImpl::getDescriptors ( bool  includeHidden = false,
bool  includeAliases = false 
) const

Returns algorithm descriptors.

Get a list of descriptor objects used to order the algorithms in the stored map where an algorithm has multiple categories it will be represented using multiple descriptors.

Parameters
includeHiddentrue includes the hidden algorithm names and is faster, the default is false
includeAliasestrue includes alias names of algorithms which aren't empty to the vector of descriptors, the default is true
Returns
A vector of descriptor objects

Definition at line 328 of file AlgorithmFactory.cpp.

References Mantid::API::AlgorithmDescriptor::alias, Mantid::API::AlgorithmDescriptor::category, create(), fillHiddenCategories(), getKeys(), Mantid::API::AlgorithmDescriptor::name, and Mantid::API::AlgorithmDescriptor::version.

◆ getKeys() [1/2]

const std::vector< std::string > Mantid::API::AlgorithmFactoryImpl::getKeys ( ) const
overridevirtual

Get the algorithm names and version - mangled use decodeName to separate.

Return the keys used for identifying algorithms.

This includes those within the Factory itself and any cleanly constructed algorithms stored here. Hidden algorithms are excluded.

Returns
The strings used to identify individual algorithms

Reimplemented from Mantid::Kernel::DynamicFactory< Algorithm >.

Definition at line 154 of file AlgorithmFactory.cpp.

References getKeys().

Referenced by getCategoriesWithState(), getDescriptors(), and getKeys().

◆ getKeys() [2/2]

const std::vector< std::string > Mantid::API::AlgorithmFactoryImpl::getKeys ( bool  includeHidden) const

Return the keys used for identifying algorithms.

This includes those within the Factory itself and any cleanly constructed algorithms stored here.

Parameters
includeHiddentrue includes the hidden algorithm names and is faster, the default is false
Returns
The strings used to identify individual algorithms

Definition at line 170 of file AlgorithmFactory.cpp.

References create(), decodeName(), fillHiddenCategories(), and Mantid::Kernel::DynamicFactory< Base, Comparator >::getKeys().

◆ getRealNameFromAlias()

boost::optional< std::string > Mantid::API::AlgorithmFactoryImpl::getRealNameFromAlias ( const std::string &  alias) const
noexcept

Get an algorithms name from the alias map.

Parameters
aliasThe name of the algorithm to look up in the alias map
Returns
Real name of algorithm if found

Definition at line 217 of file AlgorithmFactory.cpp.

Referenced by create(), and highestVersion().

◆ highestVersion()

int Mantid::API::AlgorithmFactoryImpl::highestVersion ( const std::string &  algorithmName) const

Returns the highest version of the algorithm currently registered.

Parameters
algorithmNameThe name of an algorithm registered with the factory
Returns
An integer corresponding to the highest version registered
Exceptions
std::invalid_argumentif the algorithm cannot be found

Definition at line 230 of file AlgorithmFactory.cpp.

References getRealNameFromAlias(), and m_vmap.

Referenced by create(), and export_AlgorithmFactory().

◆ operator=()

AlgorithmFactoryImpl & Mantid::API::AlgorithmFactoryImpl::operator= ( const AlgorithmFactoryImpl )
delete

◆ subscribe() [1/2]

template<class C >
std::pair< std::string, int > Mantid::API::AlgorithmFactoryImpl::subscribe ( )
inline

algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe function internally

Definition at line 59 of file AlgorithmFactory.h.

◆ subscribe() [2/2]

template<class T >
std::pair< std::string, int > Mantid::API::AlgorithmFactoryImpl::subscribe ( std::unique_ptr< Kernel::AbstractInstantiator< T > >  instantiator,
const SubscribeAction  replaceExisting = ErrorIfExists 
)
inline

Subscribes an algorithm using a custom instantiator.

This object takes ownership of the instantiator

Parameters
instantiator- A pointer to a custom instantiator
replaceExisting- Defines what happens if an algorithm of the same name/version already exists, see SubscribeAction
Returns
The classname that was registered

Definition at line 74 of file AlgorithmFactory.h.

◆ unsubscribe()

void Mantid::API::AlgorithmFactoryImpl::unsubscribe ( const std::string &  algorithmName,
const int  version 
)

Unsubscribe the given algorithm.

Override the unsubscribe method so that it knows how algorithm names are encoded in the factory.

Parameters
algorithmName:: The name of the algorithm to unsubscribe
version:: The version number of the algorithm to unsubscribe

Definition at line 84 of file AlgorithmFactory.cpp.

References createName(), Mantid::API::g_log, m_vmap, Mantid::Kernel::DynamicFactory< Base, Comparator >::unsubscribe(), and Mantid::Kernel::Logger::warning().

Referenced by export_AlgorithmFactory().

Friends And Related Function Documentation

◆ Mantid::Kernel::CreateUsingNew< AlgorithmFactoryImpl >

Definition at line 130 of file AlgorithmFactory.h.

Member Data Documentation

◆ m_amap

AliasMap Mantid::API::AlgorithmFactoryImpl::m_amap
private

The map holding the alias names of registered algorithms.

Definition at line 161 of file AlgorithmFactory.h.

◆ m_vmap

VersionMap Mantid::API::AlgorithmFactoryImpl::m_vmap
private

The map holding the registered class names and their highest versions.

Definition at line 157 of file AlgorithmFactory.h.

Referenced by exists(), highestVersion(), and unsubscribe().


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