Mantid
Loading...
Searching...
No Matches
HKL.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 {
11
12void checkUnitCompatibility(Mantid::Kernel::MDUnit const *const unit) {
13 if (!unit->isQUnit()) {
14 throw std::invalid_argument("HKL unit must be a QUnit");
15 }
16}
17} // namespace
18
19namespace Mantid::Geometry {
20
21const std::string HKL::HKLName = "HKL";
22
27HKL::HKL(std::unique_ptr<Kernel::MDUnit> &unit) {
28 checkUnitCompatibility(unit.get());
29 // Only change ownership once we are happy. Gives exception safety for input
30 // unit.
31 m_unit.swap(unit);
32}
33
38HKL::HKL(Kernel::MDUnit *unit) : m_unit(unit) { checkUnitCompatibility(unit); }
39
45HKL::HKL(const HKL &other) : m_unit(other.getMDUnit().clone()) {}
46
47HKL &HKL::operator=(const HKL &other) {
48 if (this == &other) {
49 this->m_unit = std::unique_ptr<Mantid::Kernel::MDUnit>(other.getMDUnit().clone());
50 }
51 return *this;
52}
53
54Kernel::UnitLabel HKL::getUnitLabel() const { return m_unit->getUnitLabel(); }
55
56const Kernel::MDUnit &HKL::getMDUnit() const { return *m_unit; }
57
59 m_unit = std::unique_ptr<Kernel::MDUnit>(newUnit.clone());
60 return true;
61}
62
63bool HKL::canConvertTo(const Kernel::MDUnit &otherUnit) const { return this->m_unit->canConvertTo(otherUnit); }
64
65std::string HKL::name() const { return HKLName; }
66
67HKL *HKL::clone() const { return new HKL(m_unit->clone()); }
68
71}
72
73bool HKL::isQ() const { return true; }
74
75bool HKL::isSameType(const MDFrame &frame) const {
76 auto isSameType = true;
77 try {
78 const auto &tmp = dynamic_cast<const HKL &>(frame);
80 } catch (std::bad_cast &) {
81 isSameType = false;
82 }
83 return isSameType;
84}
85} // namespace Mantid::Geometry
gsl_vector * tmp
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
HKL : HKL MDFrame.
Definition: HKL.h:21
Mantid::Kernel::SpecialCoordinateSystem equivalientSpecialCoordinateSystem() const override
Definition: HKL.cpp:69
const Kernel::MDUnit & getMDUnit() const override
Definition: HKL.cpp:56
static const std::string HKLName
Definition: HKL.h:27
HKL(const HKL &other)
Assignment.
Definition: HKL.cpp:45
bool isSameType(const MDFrame &frame) const override
Definition: HKL.cpp:75
HKL * clone() const override
Definition: HKL.cpp:67
Kernel::UnitLabel getUnitLabel() const override
Definition: HKL.cpp:54
HKL & operator=(const HKL &other)
Definition: HKL.cpp:47
bool isQ() const override
Definition: HKL.cpp:73
bool canConvertTo(const Kernel::MDUnit &otherUnit) const override
Definition: HKL.cpp:63
bool setMDUnit(const Mantid::Kernel::MDUnit &newUnit) override
Definition: HKL.cpp:58
std::string name() const override
Definition: HKL.cpp:65
std::unique_ptr< Kernel::MDUnit > m_unit
Definition: HKL.h:41
MDFrame : The coordinate frame for a dimension, or set of dimensions in a multidimensional workspace.
Definition: MDFrame.h:22
MDUnit : Unit type for multidimensional data types.
Definition: MDUnit.h:20
virtual MDUnit * clone() const =0
virtual bool isQUnit() const =0
A base-class for the a class that is able to return unit labels in different representations.
Definition: UnitLabel.h:20
SpecialCoordinateSystem
Special coordinate systems for Q3D.