Skip to content
Snippets Groups Projects
Commit c76ef7be authored by David Fairbrother's avatar David Fairbrother
Browse files

Re #22788 Use highestVersion instead of own in AlgFactory

parent 9411910e
No related branches found
No related tags found
No related merge requests found
......@@ -133,9 +133,6 @@ public:
/// Get the algorithm categories
const std::map<std::string, bool> getCategoriesWithState() const;
/// Returns a single algorithm descriptor
int getAlgLatestVersion(const std::string &algName) const;
/// Returns algorithm descriptors.
std::vector<AlgorithmDescriptor>
getDescriptors(bool includeHidden = false) const;
......
......@@ -306,26 +306,6 @@ AlgorithmFactoryImpl::getCategories(bool includeHidden) const {
return validCategories;
}
/**
* Returns a the latest version number of the given algorithm
*
* @param algName The name of the algorithm to get a version for
* @param throwIfNotRegistered (Default true) Throw if the algorithm is not
*registered
* @return Integer of the latest algorithm version or -1 if it does not exist
* @throws std::runtime_error if algorithm does not exist and throw is true
*/
int AlgorithmFactoryImpl::getAlgLatestVersion(
const std::string &algName) const {
auto it = m_vmap.find(algName);
if (it == m_vmap.end()) {
throw std::runtime_error("Algorithm not registered " + algName);
}
return it->second;
}
/**
* Get a list of descriptor objects used to order the algorithms in the stored
* map
......
......@@ -124,7 +124,7 @@ NotebookBuilder::buildAlgorithmString(AlgorithmHistory_const_sptr algHistory) {
//...or only specify algorithm versions when they're not the newest version
const auto &algName = algHistory->name();
int latestVersion =
AlgorithmFactory::Instance().getAlgLatestVersion(algName);
AlgorithmFactory::Instance().highestVersion(algName);
// If a newer version of this algorithm exists, then this must be an old
// version.
if (latestVersion > algHistory->version()) {
......
......@@ -198,7 +198,7 @@ ScriptBuilder::buildAlgorithmString(AlgorithmHistory_const_sptr algHistory) {
//...or only specify algorithm versions when they're not the newest version
const auto &algName = algHistory->name();
int latestVersion =
AlgorithmFactory::Instance().getAlgLatestVersion(algName);
AlgorithmFactory::Instance().highestVersion(algName);
// If a newer version of this algorithm exists, then this must be an old
// version.
if (latestVersion > algHistory->version()) {
......
......@@ -187,25 +187,6 @@ public:
TS_ASSERT_EQUALS(noOfAlgs - 1, descriptors.size());
}
void testGetLatestVersion() {
auto &algFactory = AlgorithmFactory::Instance();
const std::string algName = "ToyAlgorithm";
algFactory.subscribe<ToyAlgorithm>();
algFactory.subscribe<ToyAlgorithmTwo>();
int version = -1;
TS_ASSERT_THROWS_NOTHING(version = algFactory.getAlgLatestVersion(algName));
TS_ASSERT_EQUALS(version, 2);
algFactory.unsubscribe(algName, 1);
algFactory.unsubscribe(algName, 2);
TS_ASSERT_THROWS(algFactory.getAlgLatestVersion(algName),
std::runtime_error);
}
void testGetCategories() {
auto &algFactory = AlgorithmFactory::Instance();
algFactory.subscribe<CategoryAlgorithm>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment