Mantid
Loading...
Searching...
No Matches
MDUnit.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 +
9#include <boost/regex.hpp>
10#include <utility>
11
12namespace Mantid::Kernel {
13
14bool MDUnit::operator==(const MDUnit &other) const {
15 return typeid(*this) == typeid(other) && this->canConvertTo(other);
16}
17
18//----------------------------------------------------------------------------------------------
19// QUnit
20//----------------------------------------------------------------------------------------------
21
22bool QUnit::isQUnit() const { return true; }
23
24//----------------------------------------------------------------------------------------------
25// End QUnit
26//----------------------------------------------------------------------------------------------
27
28//----------------------------------------------------------------------------------------------
29// RLU
30//----------------------------------------------------------------------------------------------
32
33ReciprocalLatticeUnit::ReciprocalLatticeUnit(UnitLabel unitLabel) : m_unitLabel(std::move(unitLabel)) {}
34
37 return m_unitLabel;
38 } else {
39 return Units::Symbol::RLU;
40 }
41}
42
43bool ReciprocalLatticeUnit::canConvertTo(const MDUnit &other) const { return other.isQUnit(); }
44
48 } else {
49 return new ReciprocalLatticeUnit;
50 }
51}
52
54 boost::regex pattern("in.*A.*\\^-1");
55 return boost::regex_match(m_unitLabel.ascii(), pattern);
56}
57
58//----------------------------------------------------------------------------------------------
59// End RLU
60//----------------------------------------------------------------------------------------------
61
62//----------------------------------------------------------------------------------------------
63// Inverse Angstrom Unit
64//----------------------------------------------------------------------------------------------
65
67
68bool InverseAngstromsUnit::canConvertTo(const MDUnit &other) const { return other.isQUnit(); }
69
71
72//----------------------------------------------------------------------------------------------
73// Inverse Angstrom Unit
74//----------------------------------------------------------------------------------------------
75
76//----------------------------------------------------------------------------------------------
77// LabelUnit
78//----------------------------------------------------------------------------------------------
79
80LabelUnit::LabelUnit(UnitLabel unitLabel) : m_unitLabel(std::move(unitLabel)) {}
81
83
84bool LabelUnit::canConvertTo(const MDUnit &other) const { return this->getUnitLabel() == other.getUnitLabel(); }
85
86bool LabelUnit::isQUnit() const {
87 boost::regex pattern("(A\\^-1)");
88 boost::smatch match; // Unused.
89 return boost::regex_search(m_unitLabel.ascii(), match, pattern);
90}
91
93
94//----------------------------------------------------------------------------------------------
95// End RLU
96//----------------------------------------------------------------------------------------------
97
98} // namespace Mantid::Kernel
Inverse Angstroms unit.
Definition: MDUnit.h:51
bool canConvertTo(const MDUnit &other) const override
Definition: MDUnit.cpp:68
UnitLabel getUnitLabel() const override
Definition: MDUnit.cpp:66
InverseAngstromsUnit * clone() const override
Definition: MDUnit.cpp:70
UnitLabel getUnitLabel() const override
Definition: MDUnit.cpp:82
LabelUnit * clone() const override
Definition: MDUnit.cpp:92
LabelUnit(UnitLabel unitLabel)
Definition: MDUnit.cpp:80
bool isQUnit() const override
Definition: MDUnit.cpp:86
bool canConvertTo(const MDUnit &other) const override
Definition: MDUnit.cpp:84
UnitLabel m_unitLabel
Definition: MDUnit.h:60
MDUnit : Unit type for multidimensional data types.
Definition: MDUnit.h:20
virtual UnitLabel getUnitLabel() const =0
virtual bool canConvertTo(const MDUnit &other) const =0
bool operator==(const MDUnit &other) const
Definition: MDUnit.cpp:14
bool isQUnit() const override
Definition: MDUnit.cpp:22
UnitLabel getUnitLabel() const override
Definition: MDUnit.cpp:35
ReciprocalLatticeUnit * clone() const override
Definition: MDUnit.cpp:45
bool canConvertTo(const MDUnit &other) const override
Definition: MDUnit.cpp:43
A base-class for the a class that is able to return unit labels in different representations.
Definition: UnitLabel.h:20
const AsciiString & ascii() const
Return an ascii label for unit.
Definition: UnitLabel.cpp:105
static const UnitLabel InverseAngstrom
InverseAngstrom.
static const UnitLabel RLU
Reciprocal lattice units.
STL namespace.