12#include "MantidAPI/DllConfig.h"
18#include <unordered_map>
19#include <unordered_set>
55 std::shared_ptr<Algorithm>
create(
const std::string &,
const int &)
const;
59 template <
class C> std::pair<std::string, int>
subscribe() {
60 std::unique_ptr<Kernel::AbstractInstantiator<Algorithm>> newI =
61 std::make_unique<Kernel::Instantiator<C, Algorithm>>();
62 return this->subscribe(std::move(newI));
76 const auto tempAlg = instantiator->createInstance();
77 const int version = extractAlgVersion(tempAlg);
78 const std::string className = extractAlgName(tempAlg);
79 const std::string alias = extractAlgAlias(tempAlg);
80 typename VersionMap::const_iterator it = m_vmap.find(className);
81 if (!className.empty()) {
82 const std::string key = createName(className, version);
83 if (it == m_vmap.end()) {
84 m_vmap[className] = version;
86 if (version == it->second && replaceExisting == ErrorIfExists) {
87 std::ostringstream os;
88 os <<
"Cannot register algorithm " << className <<
" twice with the same version\n";
89 throw std::runtime_error(os.str());
91 if (version > it->second) {
92 m_vmap[className] = version;
97 throw std::invalid_argument(
"Cannot register empty algorithm name");
99 auto nameAndVersion = std::make_pair(className, version);
102 m_amap[alias] = nameAndVersion;
104 return nameAndVersion;
107 void unsubscribe(
const std::string &algorithmName,
const int version);
109 bool exists(
const std::string &algorithmName,
const int version = -1);
112 const std::vector<std::string> getKeys()
const override;
113 const std::vector<std::string> getKeys(
bool includeHidden)
const;
116 std::optional<std::pair<std::string, int>> getRealNameFromAlias(
const std::string &alias)
const noexcept;
119 int highestVersion(
const std::string &algorithmName)
const;
122 const std::unordered_set<std::string> getCategories(
bool includeHidden =
false)
const;
125 const std::map<std::string, bool> getCategoriesWithState()
const;
128 std::vector<AlgorithmDescriptor> getDescriptors(
bool includeHidden =
false,
bool includeAliases =
false)
const;
131 std::pair<std::string, int> decodeName(
const std::string &mangledName)
const;
137 const std::string extractAlgName(
const std::shared_ptr<IAlgorithm> &alg)
const;
139 int extractAlgVersion(
const std::shared_ptr<IAlgorithm> &alg)
const;
141 const std::string extractAlgAlias(
const std::shared_ptr<IAlgorithm> &alg)
const;
144 std::shared_ptr<Algorithm> createAlgorithm(
const std::string &
name,
const int version)
const;
151 std::string createName(
const std::string &,
const int &)
const;
153 void fillHiddenCategories(std::unordered_set<std::string> *categorySet)
const;
160 using AliasMap = std::unordered_map<std::string, std::pair<std::string, int>>;
170 const Poco::AutoPtr<Mantid::Kernel::DynamicFactory<Algorithm>::UpdateNotification> &;
The AlgorithmFactory class is in charge of the creation of concrete instances of Algorithms.
VersionMap m_vmap
The map holding the registered class names and their highest versions.
std::unordered_map< std::string, std::pair< std::string, int > > AliasMap
A typedef for the map of algorithm aliases.
std::map< std::string, int > VersionMap
A typedef for the map of algorithm versions.
AlgorithmFactoryImpl & operator=(const AlgorithmFactoryImpl &)=delete
~AlgorithmFactoryImpl() override
Private Destructor.
AlgorithmFactoryImpl(const AlgorithmFactoryImpl &)=delete
AliasMap m_amap
The map holding the alias names of registered algorithms.
std::pair< std::string, int > subscribe(std::unique_ptr< Kernel::AbstractInstantiator< T > > instantiator, const SubscribeAction replaceExisting=ErrorIfExists)
Subscribes an algorithm using a custom instantiator.
std::pair< std::string, int > subscribe()
algorithm factory specific function to subscribe algorithms, calls the dynamic factory subscribe func...
Base class from which all concrete algorithm classes should be derived.
IAlgorithm is the interface implemented by the Algorithm base class.
The base class for instantiators.
A notification that the factory has been updated.
The dynamic factory is a base dynamic factory for serving up objects in response to requests from oth...
SubscribeAction
Defines replacement behaviour.
Manage the lifetime of a class intended to be a singleton.
const Poco::AutoPtr< Mantid::Kernel::DynamicFactory< Algorithm >::UpdateNotification > & AlgorithmFactoryUpdateNotification_ptr
Mantid::Kernel::SingletonHolder< AlgorithmFactoryImpl > AlgorithmFactory
bool exists(Nexus::File &file, const std::string &name)
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
Helper class which provides the Collimation Length for SANS instruments.
Structure uniquely describing an algorithm with its name, category and version.
std::string category
category
std::string name
Algorithm Name.
Policy class controlling creation of the singleton Implementation classes should mark their default c...