Line data Source code
1 : // SPDX-License-Identifier: BSD-3-Clause 2 : // Copyright (c) 2023 Scipp contributors (https://github.com/scipp) 3 : /// @author Simon Heybrock 4 : #pragma once 5 : 6 : #include <cstdint> 7 : #include <functional> 8 : #include <string> 9 : 10 : #include "scipp-units_export.h" 11 : 12 : namespace scipp::units { 13 : 14 : class SCIPP_UNITS_EXPORT Dim { 15 : public: 16 : enum class Id : uint16_t { 17 : Invalid, 18 : None, 19 : InternalStructureComponent, 20 : InternalStructureRow, 21 : InternalStructureColumn, 22 : InternalHistogram, 23 : InternalSort, 24 : InternalAccumulate, 25 : InternalBinCoarse, 26 : InternalBinFine, 27 : InternalSubbin, 28 : Energy, 29 : Event, 30 : Group, 31 : Position, 32 : Row, 33 : Temperature, 34 : Time, 35 : Wavelength, 36 : X, 37 : Y, 38 : Z 39 : }; 40 : 41 : constexpr static auto Invalid = Id::Invalid; 42 : constexpr static auto None = Id::None; 43 : constexpr static auto InternalStructureComponent = 44 : Id::InternalStructureComponent; 45 : constexpr static auto InternalStructureRow = Id::InternalStructureRow; 46 : constexpr static auto InternalStructureColumn = Id::InternalStructureColumn; 47 : constexpr static auto InternalHistogram = Id::InternalHistogram; 48 : constexpr static auto InternalSort = Id::InternalSort; 49 : constexpr static auto InternalAccumulate = Id::InternalAccumulate; 50 : constexpr static auto InternalBinCoarse = Id::InternalBinCoarse; 51 : constexpr static auto InternalBinFine = Id::InternalBinFine; 52 : constexpr static auto InternalSubbin = Id::InternalSubbin; 53 : constexpr static auto Energy = Id::Energy; 54 : constexpr static auto Event = Id::Event; 55 : constexpr static auto Group = Id::Group; 56 : constexpr static auto Position = Id::Position; 57 : constexpr static auto Row = Id::Row; 58 : constexpr static auto Temperature = Id::Temperature; 59 : constexpr static auto Time = Id::Time; 60 : constexpr static auto Wavelength = Id::Wavelength; 61 : constexpr static auto X = Id::X; 62 : constexpr static auto Y = Id::Y; 63 : constexpr static auto Z = Id::Z; 64 : 65 : constexpr Dim() : m_id(Id::Invalid) {} 66 : // cppcheck-suppress noExplicitConstructor 67 17890617 : constexpr Dim(const Id id) : m_id(id) {} 68 : explicit Dim(const std::string &label); 69 : 70 : constexpr Id id() const noexcept { return m_id; } 71 : 72 : std::string name() const; 73 : 74 37159538 : constexpr bool operator==(const Dim &other) const noexcept { 75 37159538 : return m_id == other.m_id; 76 : } 77 9986040 : constexpr bool operator!=(const Dim &other) const noexcept { 78 9986040 : return m_id != other.m_id; 79 : } 80 57846 : constexpr bool operator<(const Dim &other) const noexcept { 81 57846 : return m_id < other.m_id; 82 : } 83 : 84 : private: 85 : Id m_id; 86 : }; 87 : 88 : SCIPP_UNITS_EXPORT std::string to_string(const Dim dim); 89 : 90 : } // namespace scipp::units 91 : 92 : // Hashing required temporarily while we use Dim as a key for the coord dict. 93 : namespace std { 94 : template <> struct hash<scipp::units::Dim> { 95 : std::size_t operator()(const scipp::units::Dim &k) const { 96 : return hash<scipp::units::Dim::Id>()(k.id()); 97 : } 98 : }; 99 : } // namespace std 100 : 101 : namespace scipp { 102 : using scipp::units::Dim; 103 : }