Mantid
Loading...
Searching...
No Matches
DeprecatedAlgorithm.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include "MantidTypes/Core/DateAndTimeHelpers.h"
11#include <sstream>
12
13namespace Mantid::API {
14namespace {
16Kernel::Logger g_log("DeprecatedAlgorithm");
17} // namespace
18
20DeprecatedAlgorithm::DeprecatedAlgorithm() : m_replacementAlgorithm(), m_replacementVersion(-1), m_deprecatedDate() {}
21
24
28void DeprecatedAlgorithm::useAlgorithm(const std::string &replacement, const int version) {
29 // Replacement is not checked here as we cannot guarantee all algorithms have
30 // been
31 // registered when we are called. It is checked when the message is about to
32 // be printed
33 if (!replacement.empty())
34 this->m_replacementAlgorithm = replacement;
35 else
36 this->m_replacementAlgorithm = "";
37
38 m_replacementVersion = version;
39}
40
42void DeprecatedAlgorithm::deprecatedDate(const std::string &date) {
43 this->m_deprecatedDate = "";
44 if (date.empty()) {
45 // TODO warn people that it wasn't set
46 return;
47 }
48 if (!Types::Core::DateAndTimeHelpers::stringIsISO8601(date)) {
49 // TODO warn people that it wasn't set
50 return;
51 }
52 this->m_deprecatedDate = date;
53}
54
57 std::stringstream msg;
58 if (algo != nullptr)
59 msg << algo->name() << " is ";
60
61 msg << "deprecated";
62
63 if (!this->m_deprecatedDate.empty())
64 msg << " (on " << this->m_deprecatedDate << ")";
65
66 if (this->m_replacementAlgorithm.empty()) {
67 msg << " and has no replacement.";
68 } else {
69 // sanity check
71 std::ostringstream invalidReplacementMsg;
72 invalidReplacementMsg << "Invalid replacement algorithm '" + this->m_replacementAlgorithm + "'";
73 if (this->m_replacementVersion > 0)
74 invalidReplacementMsg << " version " << this->m_replacementVersion << "\n";
75 invalidReplacementMsg << "Replacement algorithm not registered.";
76 g_log.warning(invalidReplacementMsg.str());
77 }
78
79 msg << ". Use " << this->m_replacementAlgorithm;
80 if (this->m_replacementVersion > 0)
81 msg << " version " << this->m_replacementVersion;
82 msg << " instead.";
83 }
84
85 return msg.str();
86}
87} // namespace Mantid::API
DeprecatedAlgorithm()
Does nothing other than make the compiler happy.
std::string deprecationMsg(const IAlgorithm *)
This merely prints the deprecation error for people to see.
std::string m_deprecatedDate
The date that the algorithm was first deprecated.
std::string m_replacementAlgorithm
The algorithm to use instead of this one.
void deprecatedDate(const std::string &)
The date the algorithm was deprecated on.
void useAlgorithm(const std::string &, const int version=-1)
The algorithm to use instead of this one.
virtual ~DeprecatedAlgorithm()
Does nothing other than make the compiler happy.
int m_replacementVersion
Replacement version, -1 indicates latest.
IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:45
virtual const std::string name() const =0
function to return a name of the algorithm, must be overridden in all algorithms
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Kernel::Logger g_log("ExperimentInfo")
static logger object
bool exists(::NeXus::File &file, const std::string &name)
Based on the current group in the file, does the named sub-entry exist?