DeprecatedAlias.cpp 1.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +

#include "MantidAPI/DeprecatedAlias.h"
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidKernel/Logger.h"
#include "MantidTypes/Core/DateAndTimeHelpers.h"

namespace Mantid {
namespace API {

namespace {
Kernel::Logger g_log("DeprecatedAlias");
} // namespace

/// Constructor to ensure the compiler is happy
21
DeprecatedAlias::DeprecatedAlias() : m_deprecationDate() {}
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

/// Destructor to ensure the compiler is happy
DeprecatedAlias::~DeprecatedAlias() = default;

/**
 * @brief Set the deprecation date which will be used to inform the users
 *
 * @param date : deprecation date in ISO8601 format
 */
void DeprecatedAlias::setDeprecationDate(const std::string &date) {
  m_deprecationDate = "";
  if ((!date.empty()) && (Types::Core::DateAndTimeHelpers::stringIsISO8601(date))) {
    m_deprecationDate = date;
  } else {
    throw std::invalid_argument("DeprecatedAlias::DeprecationDate(): deprecation date must follow ISO8601.");
  }
}

/**
 * @brief Construct and return a full deprecation message
 *
 * @param algo
 * @return std::string
 */
std::string DeprecatedAlias::deprecationMessage(const IAlgorithm *algo) {
  std::stringstream msg;
48
49
50
51
52
53
54
55
56

  auto alias = algo->alias();

  if (alias.empty()) {
    throw std::runtime_error("Cannot find the deprecated alias for this algorithm.");
  } else {
    msg << "The algorithm '" << alias << "' is deprecated on " << m_deprecationDate << "."
        << "Please use '" << algo->name() << "' instead.";
  }
57
58
59
60
61
62

  return msg.str();
}

} // namespace API
} // namespace Mantid