Mantid
Loading...
Searching...
No Matches
PeakTransformSelector.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 +
8#include <stdexcept>
9
10namespace Mantid::Geometry {
13
19 m_candidateFactories.insert(candidate);
20}
21
26
33 if (numberRegistered() == 0) {
34 throw std::runtime_error("Nothing registered.");
35 }
36
38 bool found = false;
39 for (const auto &temp : m_candidateFactories) {
40 try {
41 temp->createDefaultTransform();
42 selected = temp;
43 found = true;
44 } catch (PeakTransformException &) {
45 }
46 }
47 if (!found) {
48 throw std::invalid_argument("PeakTransformSelector could not find a suitable transform");
49 }
50 return selected;
51}
52
60 const std::string &labelY) const {
61 if (labelX.empty()) {
62 throw std::invalid_argument("labelX is empty");
63 }
64 if (labelY.empty()) {
65 throw std::invalid_argument("labelY is empty");
66 }
67 if (numberRegistered() == 0) {
68 throw std::runtime_error("Nothing registered.");
69 }
70
72 bool found = false;
73 for (const auto &temp : m_candidateFactories) {
74 try {
75 temp->createTransform(labelX, labelY);
76 selected = temp;
77 found = true;
78 } catch (PeakTransformException &) {
79 }
80 }
81 if (!found) {
82 std::stringstream ss;
83 ss << "PeakTransformSelector could not find a suitable transform for "
84 "labelX "
85 << labelX << " labelY " << labelY;
86 throw std::invalid_argument(ss.str());
87 }
88 return selected;
89}
90
98bool PeakTransformSelector::hasFactoryForTransform(const std::string &labelX, const std::string &labelY) const {
99 bool hasFactoryForTransform = true;
100 try {
101 this->makeChoice(labelX, labelY);
102 } catch (std::invalid_argument &) {
104 }
106}
107} // namespace Mantid::Geometry
Exceptions occuring when PeakTransformations cannot be formed.
Definition: PeakTransform.h:66
PeakTransformFactory_sptr makeChoice(const std::string &labelX, const std::string &labelY) const
Make choice.
bool hasFactoryForTransform(const std::string &labelX, const std::string &labelY) const
Has a factory capable of the requested transform.
PeakTransformFactory_sptr makeDefaultChoice() const
Make default choice.
size_t numberRegistered() const
Get the number of registered factories.
void registerCandidate(const PeakTransformFactory_sptr &candidate)
Register a candidate factory.
std::shared_ptr< PeakTransformFactory > PeakTransformFactory_sptr
Factory Shared Pointer typedef.