Mantid
Loading...
Searching...
No Matches
UnitLabel.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 <codecvt>
9#include <cstring>
10#include <locale>
11#include <utility>
12
13namespace Mantid::Kernel {
14
21 : m_ascii(std::move(ascii)), m_utf8(std::move(unicode)), m_latex(std::move(latex)) {}
22
27UnitLabel::UnitLabel(const AsciiString &ascii) : m_ascii(ascii), m_latex(ascii) {
28 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
29 m_utf8 = converter.from_bytes(m_ascii);
30}
36UnitLabel::UnitLabel(const char *ascii) : UnitLabel(AsciiString(ascii)) {}
37
44 return (this->ascii() == rhs.ascii() && this->utf8() == rhs.utf8());
45}
46
53bool UnitLabel::operator==(const std::string &rhs) const { return (this->ascii() == rhs); }
54
61bool UnitLabel::operator==(const char *rhs) const { return (strcmp(ascii().c_str(), rhs) == 0); }
62
69bool UnitLabel::operator==(const std::wstring &rhs) const { return (this->utf8() == rhs); }
70
76bool UnitLabel::operator!=(const UnitLabel &rhs) const { return !(*this == rhs); }
77
84bool UnitLabel::operator!=(const std::string &rhs) const { return !(*this == rhs); }
85
92bool UnitLabel::operator!=(const char *rhs) const { return !(*this == rhs); }
93
100bool UnitLabel::operator!=(const std::wstring &rhs) const { return !(*this == rhs); }
101
106
111
116
120UnitLabel::operator std::string() const { return this->ascii(); }
121
122} // namespace Mantid::Kernel
const std::vector< double > & rhs
A base-class for the a class that is able to return unit labels in different representations.
Definition: UnitLabel.h:20
std::wstring m_utf8
Value of utf-8 encoded string.
Definition: UnitLabel.h:70
std::string AsciiString
Type that contains a plain-text string.
Definition: UnitLabel.h:25
std::string m_ascii
Value of plain-text label.
Definition: UnitLabel.h:68
const AsciiString & ascii() const
Return an ascii label for unit.
Definition: UnitLabel.cpp:105
bool operator==(const UnitLabel &rhs) const
Equality operator with other label.
Definition: UnitLabel.cpp:43
std::string m_latex
Value of latex label.
Definition: UnitLabel.h:72
std::wstring Utf8String
Type that can hold a unicode string.
Definition: UnitLabel.h:29
bool operator!=(const UnitLabel &rhs) const
Inqquality operator with other label.
Definition: UnitLabel.cpp:76
const Utf8String & utf8() const
Return a utf-8 encoded label for unit.
Definition: UnitLabel.cpp:110
const AsciiString & latex() const
Return an ascii latex compatible label for unit.
Definition: UnitLabel.cpp:115
STL namespace.