Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
LuminousIntensity.hpp
Go to the documentation of this file.
1// Copyright © 2020-2024 Alexandre Coderre-Chabot
2//
3// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
4// models, and units of measure for scientific computing.
5//
6// Physical Quantities is hosted at:
7// https://github.com/acodcha/phq
8//
9// Physical Quantities is licensed under the MIT License:
10// https://mit-license.org
11//
12// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
13// associated documentation files (the "Software"), to deal in the Software without restriction,
14// including without limitation the rights to use, copy, modify, merge, publish, distribute,
15// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17// - The above copyright notice and this permission notice shall be included in all copies or
18// substantial portions of the Software.
19// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
20// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25#ifndef PHQ_DIMENSION_LUMINOUS_INTENSITY_HPP
26#define PHQ_DIMENSION_LUMINOUS_INTENSITY_HPP
27
28#include <cstddef>
29#include <cstdint>
30#include <functional>
31#include <iostream>
32#include <string>
33#include <string_view>
34
35namespace PhQ::Dimension {
36
37/// \brief Base physical dimension of luminous intensity. Typically denoted "J". One of seven
38/// independent base physical dimensions that form the physical dimension set of any unit of measure
39/// or physical quantity. Part of PhQ::Dimensions.
41public:
42 /// \brief Default constructor. Constructs a base physical dimension of luminous intensity with a
43 /// value of zero.
44 constexpr LuminousIntensity() = default;
45
46 /// \brief Constructor. Constructs a base physical dimension of luminous intensity with a given
47 /// value.
48 explicit constexpr LuminousIntensity(const int8_t value) : value(value) {}
49
50 /// \brief Destructor. Destroys this base physical dimension of luminous intensity.
51 ~LuminousIntensity() noexcept = default;
52
53 /// \brief Copy constructor. Constructs a base physical dimension of luminous intensity by copying
54 /// another one.
55 constexpr LuminousIntensity(const LuminousIntensity& other) = default;
56
57 /// \brief Copy assignment operator. Assigns the value of this base physical dimension of luminous
58 /// intensity by copying from another one.
59 constexpr LuminousIntensity& operator=(const LuminousIntensity& other) = default;
60
61 /// \brief Move constructor. Constructs a base physical dimension of luminous intensity by moving
62 /// another one.
63 constexpr LuminousIntensity(LuminousIntensity&& other) noexcept = default;
64
65 /// \brief Move assignment operator. Assigns the value of this base physical dimension of luminous
66 /// intensity by moving another one.
67 constexpr LuminousIntensity& operator=(LuminousIntensity&& other) noexcept = default;
68
69 /// \brief Value of this base physical dimension.
70 [[nodiscard]] constexpr int8_t Value() const noexcept {
71 return value;
72 }
73
74 /// \brief Abbreviation of this base physical dimension.
75 static std::string_view Abbreviation() noexcept {
76 return "J";
77 }
78
79 /// \brief Label of this base physical dimension.
80 static std::string_view Label() noexcept {
81 return "Luminous Intensity";
82 }
83
84 /// \brief Prints this base physical dimension as a string.
85 [[nodiscard]] std::string Print() const noexcept {
86 if (value == 0) {
87 return {};
88 }
89 std::string string{Abbreviation()};
90 if (value > 1) {
91 string.append("^" + std::to_string(value));
92 } else if (value < 0) {
93 string.append("^(" + std::to_string(value) + ")");
94 }
95 return string;
96 }
97
98private:
99 /// \brief Value of this base physical dimension.
100 int8_t value{0};
101};
102
103inline constexpr bool operator==(
104 const LuminousIntensity& left, const LuminousIntensity& right) noexcept {
105 return left.Value() == right.Value();
106}
107
108inline constexpr bool operator!=(
109 const LuminousIntensity& left, const LuminousIntensity& right) noexcept {
110 return left.Value() != right.Value();
111}
112
113inline constexpr bool operator<(
114 const LuminousIntensity& left, const LuminousIntensity& right) noexcept {
115 return left.Value() < right.Value();
116}
117
118inline constexpr bool operator>(
119 const LuminousIntensity& left, const LuminousIntensity& right) noexcept {
120 return left.Value() > right.Value();
121}
122
123inline constexpr bool operator<=(
124 const LuminousIntensity& left, const LuminousIntensity& right) noexcept {
125 return left.Value() <= right.Value();
126}
127
128inline constexpr bool operator>=(
129 const LuminousIntensity& left, const LuminousIntensity& right) noexcept {
130 return left.Value() >= right.Value();
131}
132
133inline std::ostream& operator<<(std::ostream& stream, const LuminousIntensity& intensity) {
134 stream << intensity.Print();
135 return stream;
136}
137
138} // namespace PhQ::Dimension
139
140namespace std {
141
142template <>
143struct hash<PhQ::Dimension::LuminousIntensity> {
144 inline size_t operator()(const PhQ::Dimension::LuminousIntensity& intensity) const {
145 return hash<int8_t>()(intensity.Value());
146 }
147};
148
149} // namespace std
150
151#endif // PHQ_DIMENSION_LUMINOUS_INTENSITY_HPP
Base physical dimension of luminous intensity. Typically denoted "J". One of seven independent base p...
static std::string_view Label() noexcept
Label of this base physical dimension.
constexpr LuminousIntensity()=default
Default constructor. Constructs a base physical dimension of luminous intensity with a value of zero.
static std::string_view Abbreviation() noexcept
Abbreviation of this base physical dimension.
constexpr int8_t Value() const noexcept
Value of this base physical dimension.
std::string Print() const noexcept
Prints this base physical dimension as a string.
int8_t value
Value of this base physical dimension.
constexpr LuminousIntensity(const int8_t value)
Constructor. Constructs a base physical dimension of luminous intensity with a given value.
~LuminousIntensity() noexcept=default
Destructor. Destroys this base physical dimension of luminous intensity.
Namespace that contains base physical dimensions.
Definition Base.hpp:72
constexpr bool operator!=(const ElectricCurrent &left, const ElectricCurrent &right) noexcept
constexpr bool operator>(const ElectricCurrent &left, const ElectricCurrent &right) noexcept
constexpr bool operator<(const ElectricCurrent &left, const ElectricCurrent &right) noexcept
constexpr bool operator<=(const ElectricCurrent &left, const ElectricCurrent &right) noexcept
constexpr bool operator==(const ElectricCurrent &left, const ElectricCurrent &right) noexcept
constexpr bool operator>=(const ElectricCurrent &left, const ElectricCurrent &right) noexcept
std::ostream & operator<<(std::ostream &stream, const ElectricCurrent &current)
Namespace that encompasses all of the Physical Quantities library's content.