12#include "MantidAPI/DllConfig.h"
15#include <boost/optional.hpp>
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");
101 m_amap[alias] = className;
103 return std::make_pair(className, version);
106 void unsubscribe(
const std::string &algorithmName,
const int version);
108 bool exists(
const std::string &algorithmName,
const int version = -1);
111 const std::vector<std::string> getKeys()
const override;
112 const std::vector<std::string> getKeys(
bool includeHidden)
const;
115 boost::optional<std::string> getRealNameFromAlias(
const std::string &alias)
const noexcept;
118 int highestVersion(
const std::string &algorithmName)
const;
121 const std::unordered_set<std::string> getCategories(
bool includeHidden =
false)
const;
124 const std::map<std::string, bool> getCategoriesWithState()
const;
127 std::vector<AlgorithmDescriptor> getDescriptors(
bool includeHidden =
false,
bool includeAliases =
false)
const;
130 std::pair<std::string, int> decodeName(
const std::string &mangledName)
const;
136 const std::string extractAlgName(
const std::shared_ptr<IAlgorithm> &alg)
const;
138 int extractAlgVersion(
const std::shared_ptr<IAlgorithm> &alg)
const;
140 const std::string extractAlgAlias(
const std::shared_ptr<IAlgorithm> &alg)
const;
143 std::shared_ptr<Algorithm> createAlgorithm(
const std::string &name,
const int version)
const;
150 std::string createName(
const std::string &,
const int &)
const;
152 void fillHiddenCategories(std::unordered_set<std::string> *categorySet)
const;
159 using AliasMap = std::unordered_map<std::string, std::string>;
169 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::string > 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
bool exists(::NeXus::File &file, const std::string &name)
Based on the current group in the file, does the named sub-entry exist?
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...