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
44HKL::HKL(const HKL &other) : m_unit(other.getMDUnit().clone()) {}
45
46HKL &HKL::operator=(const HKL &other) {
47 if (this == &other) {
48 this->m_unit = std::unique_ptr<Mantid::Kernel::MDUnit>(other.getMDUnit().clone());
49 }
50 return *this;
51}
52
53Kernel::UnitLabel HKL::getUnitLabel() const { return m_unit->getUnitLabel(); }
54
55const Kernel::MDUnit &HKL::getMDUnit() const { return *m_unit; }
56
58 m_unit = std::unique_ptr<Kernel::MDUnit>(newUnit.clone());
59 return true;
60}
61
62bool HKL::canConvertTo(const Kernel::MDUnit &otherUnit) const { return this->m_unit->canConvertTo(otherUnit); }
63
64std::string HKL::name() const { return HKLName; }
65
66HKL *HKL::clone() const { return new HKL(m_unit->clone()); }
67
71
72bool HKL::isQ() const { return true; }
73
74bool HKL::isSameType(const MDFrame &frame) const {
75 auto isSameType = true;
76 try {
77 const auto &tmp = dynamic_cast<const HKL &>(frame);
79 } catch (std::bad_cast &) {
80 isSameType = false;
81 }
82 return isSameType;
83}
84} // 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:48
HKL : HKL MDFrame.
Definition HKL.h:20
Mantid::Kernel::SpecialCoordinateSystem equivalientSpecialCoordinateSystem() const override
Definition HKL.cpp:68
const Kernel::MDUnit & getMDUnit() const override
Definition HKL.cpp:55
static const std::string HKLName
Definition HKL.h:26
HKL(const HKL &other)
Assignment.
Definition HKL.cpp:44
bool isSameType(const MDFrame &frame) const override
Definition HKL.cpp:74
HKL * clone() const override
Definition HKL.cpp:66
Kernel::UnitLabel getUnitLabel() const override
Definition HKL.cpp:53
HKL & operator=(const HKL &other)
Definition HKL.cpp:46
bool isQ() const override
Definition HKL.cpp:72
bool canConvertTo(const Kernel::MDUnit &otherUnit) const override
Definition HKL.cpp:62
bool setMDUnit(const Mantid::Kernel::MDUnit &newUnit) override
Definition HKL.cpp:57
std::string name() const override
Definition HKL.cpp:64
std::unique_ptr< Kernel::MDUnit > m_unit
Definition HKL.h:40
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.