|
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. | |
| std::pair< std::string, int > | decodeName (const std::string &mangledName) const |
| unmangles the names used as keys into the name and version | |
| bool | exists (const std::string &algorithmName, const int version=-1) |
| Does an algorithm of the given name and version exist. | |
| const std::unordered_set< std::string > | getCategories (bool includeHidden=false) const |
| Get the algorithm categories. | |
| const std::map< std::string, bool > | getCategoriesWithState () const |
| Get the algorithm categories. | |
| std::vector< AlgorithmDescriptor > | getDescriptors (bool includeHidden=false, bool includeAliases=false) const |
| Returns algorithm descriptors. | |
| const std::vector< std::string > | getKeys () const override |
| Get the algorithm names and version - mangled use decodeName to separate. | |
| const std::vector< std::string > | getKeys (bool includeHidden) const |
| Return the keys used for identifying algorithms. | |
| std::optional< std::pair< std::string, int > > | getRealNameFromAlias (const std::string &alias) const noexcept |
| Get an algorithms name and version from the alias map. | |
| int | highestVersion (const std::string &algorithmName) const |
| Returns the highest version of the algorithm currently registered. | |
| 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 | |
| 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. | |
| void | unsubscribe (const std::string &algorithmName, const int version) |
| Unsubscribe the given algorithm. | |
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. | |
| 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. | |
| void | disableNotifications () |
| Disable notifications. | |
| DynamicFactory (const DynamicFactory &)=delete | |
| void | enableNotifications () |
| Enable notifications. | |
| bool | exists (const std::string &className) const |
| Returns true if the given class is currently registered. | |
| DynamicFactory & | operator= (const DynamicFactory &)=delete |
| void | subscribe (const std::string &className) |
| Registers the instantiator for the given class with the DynamicFactory. | |
| void | subscribe (const std::string &className, std::unique_ptr< AbstractFactory > pAbstractFactory, SubscribeAction replace=ErrorIfExists) |
| Registers the instantiator for the given class with the DynamicFactory. | |
| void | unsubscribe (const std::string &className) |
| Unregisters the given class and deletes the instantiator for the class. | |
| virtual | ~DynamicFactory ()=default |
| Destroys the DynamicFactory and deletes the instantiators for all registered classes. | |
Private Types | |
| using | AliasMap = std::unordered_map< std::string, std::pair< std::string, int > > |
| A typedef for the map of algorithm aliases. | |
| using | VersionMap = std::map< std::string, int > |
| A typedef for the map of algorithm versions. | |
Private Member Functions | |
| AlgorithmFactoryImpl () | |
| Private Constructor for singleton class. | |
| std::shared_ptr< Algorithm > | createAlgorithm (const std::string &name, const int version) const |
| Create an algorithm object with the specified name. | |
| std::string | createName (const std::string &, const int &) const |
| creates an algorithm name convolved from an name and version | |
| const std::string | extractAlgAlias (const std::shared_ptr< IAlgorithm > &alg) const |
| Extract the alias of an algorithm. | |
| const std::string | extractAlgName (const std::shared_ptr< IAlgorithm > &alg) const |
| Extract the name of an algorithm. | |
| int | extractAlgVersion (const std::shared_ptr< IAlgorithm > &alg) const |
| Extract the version of an algorithm. | |
| void | fillHiddenCategories (std::unordered_set< std::string > *categorySet) const |
| fills a set with the hidden categories | |
| ~AlgorithmFactoryImpl () override | |
| Private Destructor. | |
Private Attributes | |
| AliasMap | m_amap |
| The map holding the alias names of registered algorithms. | |
| VersionMap | m_vmap |
| The map holding the registered class names and their highest versions. | |
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. | |
| 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. | |
Protected Member Functions inherited from Mantid::Kernel::DynamicFactory< Algorithm > | |
| DynamicFactory () | |
| Protected constructor for base class. | |
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 160 of file AlgorithmFactory.h.
|
private |
A typedef for the map of algorithm versions.
Definition at line 156 of file AlgorithmFactory.h.
|
delete |
|
private |
Private Constructor for singleton class.
Definition at line 27 of file AlgorithmFactory.cpp.
References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.
|
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(), highestVersion(), and name.
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 439 of file AlgorithmFactory.cpp.
References Mantid::Kernel::DynamicFactory< Base, Comparator >::create(), createName(), and name.
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 124 of file AlgorithmFactory.cpp.
References name.
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 134 of file AlgorithmFactory.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and name.
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 109 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 427 of file AlgorithmFactory.cpp.
|
private |
Extract the name of an algorithm.
| alg | :: the Algrorithm to use |
Definition at line 413 of file AlgorithmFactory.cpp.
|
private |
Extract the version of an algorithm.
| alg | :: the Algrorithm to use |
Definition at line 421 of file AlgorithmFactory.cpp.
|
private |
fills a set with the hidden categories
Definition at line 401 of file AlgorithmFactory.cpp.
References Mantid::Kernel::StringTokenizer::begin(), Mantid::Kernel::StringTokenizer::end(), 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 296 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 252 of file AlgorithmFactory.cpp.
References create(), decodeName(), fillHiddenCategories(), getKeys(), and name.
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 324 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 153 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 169 of file AlgorithmFactory.cpp.
References create(), decodeName(), fillHiddenCategories(), Mantid::Kernel::DynamicFactory< Base, Comparator >::getKeys(), and name.
|
noexcept |
Get an algorithms name and version 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 83 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 131 of file AlgorithmFactory.h.
|
private |
The map holding the alias names of registered algorithms.
Definition at line 162 of file AlgorithmFactory.h.
|
private |
The map holding the registered class names and their highest versions.
Definition at line 158 of file AlgorithmFactory.h.
Referenced by exists(), highestVersion(), and unsubscribe().