Mantid
|
The AlgorithmFactory class is in charge of the creation of concrete instances of Algorithms. More...
#include <AlgorithmFactory.h>
Public Member Functions | |
AlgorithmFactoryImpl (const AlgorithmFactoryImpl &)=delete | |
std::shared_ptr< Algorithm > | create (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< AlgorithmDescriptor > | getDescriptors (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... | |
AlgorithmFactoryImpl & | operator= (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< Algorithm > | create (const std::string &className) const |
Creates a new instance of the class with the given name. More... | |
virtual Algorithm * | createUnwrapped (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... | |
DynamicFactory & | operator= (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< Algorithm > | createAlgorithm (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... | |
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.
Definition at line 48 of file AlgorithmFactory.h.
|
private |
A typedef for the map of algorithm aliases.
Definition at line 159 of file AlgorithmFactory.h.
|
private |
A typedef for the map of algorithm versions.
Definition at line 155 of file AlgorithmFactory.h.
|
delete |
|
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().
|
overrideprivatedefault |
Private Destructor.
std::shared_ptr< Algorithm > Mantid::API::AlgorithmFactoryImpl::create | ( | const std::string & | name, |
const int & | version | ||
) | const |
Creates an instance of an algorithm.
name | :: the name of the Algorithm to create |
version | :: the version of the algorithm to create |
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().
|
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.
Definition at line 443 of file AlgorithmFactory.cpp.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::create(), and createName().
Referenced by create().
|
private |
creates an algorithm name convolved from an name and version
Creates a mangled name for interal storage.
name | :: the name of the Algrorithm |
version | :: the version of the algroithm |
Definition at line 125 of file AlgorithmFactory.cpp.
Referenced by create(), createAlgorithm(), exists(), and unsubscribe().
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.
mangledName | :: the mangled name of the Algrorithm |
Definition at line 135 of file AlgorithmFactory.cpp.
References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.
Referenced by getCategoriesWithState(), and getKeys().
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.
algorithmName | :: The name of the algorithm |
version | :: The version number. -1 checks whether anything exists |
Definition at line 110 of file AlgorithmFactory.cpp.
References createName(), Mantid::Kernel::DynamicFactory< Base, Comparator >::exists(), and m_vmap.
Referenced by export_AlgorithmFactory().
|
private |
Extract the alias of an algorithm.
alg | :: the Algorithm to use |
Definition at line 431 of file AlgorithmFactory.cpp.
|
private |
Extract the name of an algorithm.
alg | :: the Algrorithm to use |
Definition at line 417 of file AlgorithmFactory.cpp.
|
private |
Extract the version of an algorithm.
alg | :: the Algrorithm to use |
Definition at line 425 of file AlgorithmFactory.cpp.
|
private |
fills a set with the hidden categories
Definition at line 405 of file AlgorithmFactory.cpp.
References Mantid::Kernel::StringTokenizer::begin(), Mantid::Kernel::StringTokenizer::end(), Mantid::Kernel::SingletonHolder< T >::Instance(), Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY, and Mantid::Kernel::StringTokenizer::TOK_TRIM.
Referenced by getCategoriesWithState(), getDescriptors(), and getKeys().
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.
includeHidden | true includes the hidden algorithm names and is faster, the default is false |
Definition at line 300 of file AlgorithmFactory.cpp.
References 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.
Definition at line 256 of file AlgorithmFactory.cpp.
References create(), decodeName(), fillHiddenCategories(), and getKeys().
Referenced by getCategories().
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.
includeHidden | true includes the hidden algorithm names and is faster, the default is false |
includeAliases | true includes alias names of algorithms which aren't empty to the vector of descriptors, the default is true |
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.
|
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.
Reimplemented from Mantid::Kernel::DynamicFactory< Algorithm >.
Definition at line 154 of file AlgorithmFactory.cpp.
References getKeys().
Referenced by getCategoriesWithState(), getDescriptors(), and getKeys().
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.
includeHidden | true includes the hidden algorithm names and is faster, the default is false |
Definition at line 170 of file AlgorithmFactory.cpp.
References create(), decodeName(), fillHiddenCategories(), and Mantid::Kernel::DynamicFactory< Base, Comparator >::getKeys().
|
noexcept |
Get an algorithms name from the alias map.
alias | The name of the algorithm to look up in the alias map |
Definition at line 217 of file AlgorithmFactory.cpp.
Referenced by create(), and highestVersion().
int Mantid::API::AlgorithmFactoryImpl::highestVersion | ( | const std::string & | algorithmName | ) | const |
Returns the highest version of the algorithm currently registered.
algorithmName | The name of an algorithm registered with the factory |
std::invalid_argument | if the algorithm cannot be found |
Definition at line 230 of file AlgorithmFactory.cpp.
References getRealNameFromAlias(), and m_vmap.
Referenced by create(), and export_AlgorithmFactory().
|
delete |
References Mantid::DataObjects::create().
|
inline |
algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe function internally
Definition at line 59 of file AlgorithmFactory.h.
|
inline |
Subscribes an algorithm using a custom instantiator.
This object takes ownership of the instantiator
instantiator | - A pointer to a custom instantiator |
replaceExisting | - Defines what happens if an algorithm of the same name/version already exists, see SubscribeAction |
Definition at line 74 of file AlgorithmFactory.h.
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.
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().
|
friend |
Definition at line 130 of file AlgorithmFactory.h.
|
private |
The map holding the alias names of registered algorithms.
Definition at line 161 of file AlgorithmFactory.h.
|
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().