GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 3 / 0 / 3
Functions: 100.0% 2 / 0 / 2
Branches: -% 0 / 0 / 0

src/utilities/units/SIUnit.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_UNITS_SIUNIT_HPP
7 #define UTILITIES_UNITS_SIUNIT_HPP
8
9 #include "../UtilitiesAPI.hpp"
10 #include "Unit.hpp"
11
12 namespace openstudio {
13 namespace detail {
14
15 class SIUnit_Impl;
16
17 } // namespace detail
18
19 /** Structure to hold SIUnit exponents needed for SIUnit construction. The first seven units
20 * are true base units in the SI system. The last four are, strictly speaking, derived and/or
21 * dimensionless units, but have meanings and conversions that are easier to express when they
22 * are broken out into distinct elements. \relates SIUnit */
23 struct UTILITIES_API SIExpnt
24 {
25 public:
26 18207 SIExpnt(int kg = 0, int m = 0, int s = 0, int K = 0, int A = 0, int cd = 0, int mol = 0, int rad = 0, int sr = 0, int people = 0, int cycle = 0,
27 int dollar = 0)
28 18207 : m_kg(kg), m_m(m), m_s(s), m_K(K), m_A(A), m_cd(cd), m_mol(mol), m_rad(rad), m_sr(sr), m_people(people), m_cycle(cycle), m_dollar(dollar) {}
29
30 private:
31 int m_kg;
32 int m_m;
33 int m_s;
34 int m_K;
35 int m_A;
36 int m_cd;
37 int m_mol;
38 int m_rad;
39 int m_sr;
40 int m_people;
41 int m_cycle;
42 int m_dollar;
43
44 friend class detail::SIUnit_Impl;
45 };
46
47 /** SIUnit is a Unit with baseUnits are fixed by its constructors, see SIExpnt. setBaseUnitExponent
48 * throws an exception if any other string is passed in as a baseUnit. SIUnit.hpp declares related
49 * operators and UnitFactory callback functions. */
50 class UTILITIES_API SIUnit : public Unit
51 {
52 public:
53 /** @name Constructors and Destructors */
54 //@{
55
56 /** Default constructor. Example: \verbatim
57 SIUnit myEnergy(SIExpnt(1,2,-2),3,"J");
58 std::cout << myEnergy; // produces "kJ" \endverbatim
59 *
60 * \param[in] exponents holds the exponents for each base unit.
61 * \param[in] scaleExponent exponent for scale. For instance 3 for kilo.
62 * \param[in] prettyString optional string to use in place of standardString. */
63 SIUnit(const SIExpnt& exponents = SIExpnt(), int scaleExponent = 0, const std::string& prettyString = "");
64
65 /** Alternate constructor. Specify the abbreviation of the scale, rather than its
66 * exponent. Example: \verbatim
67 SIUnit myEnergy("k",SIExpnt(1,2,-2),"J");
68 std::cout << myEnergy; // produces "kJ \endverbatim
69 *
70 * \param[in] scaleAbbreviation is string equal to a scale abbreviation. For instance
71 * "k" for kilo.
72 * \param[in] exponents holds the exponents for each base unit.
73 * \param[in] prettyString optional string to use in place of standardString. */
74 SIUnit(const std::string& scaleAbbreviation, const SIExpnt& exponents = SIExpnt(), const std::string& prettyString = "");
75
76 2494971 virtual ~SIUnit() override = default;
77
78 //@}
79 protected:
80 /// @cond
81 using ImplType = detail::SIUnit_Impl;
82
83 explicit SIUnit(std::shared_ptr<detail::SIUnit_Impl> impl);
84
85 friend class Unit;
86 friend class detail::SIUnit_Impl;
87
88 /// @endcond
89 private:
90 REGISTER_LOGGER("openstudio.units.SIUnit");
91 };
92
93 /** \relates SIUnit*/
94 using OptionalSIUnit = boost::optional<SIUnit>;
95
96 /** \relates SIUnit*/
97 using SIUnitVector = std::vector<SIUnit>;
98
99 /** @name Create Functions Used by UnitFactory */
100 //@{
101
102 // base units
103
104 /** \relates SIUnit */
105 UTILITIES_API SIUnit createSIMass();
106 /** \relates SIUnit */
107 UTILITIES_API SIUnit createSILength();
108 /** \relates SIUnit */
109 UTILITIES_API SIUnit createSITime();
110 /** \relates SIUnit */
111 UTILITIES_API SIUnit createSITemperature();
112 /** \relates SIUnit */
113 UTILITIES_API SIUnit createSIElectricCurrent();
114 /** \relates SIUnit */
115 UTILITIES_API SIUnit createSILuminousIntensity();
116 /** \relates SIUnit */
117 UTILITIES_API SIUnit createSIAmountOfSubstance();
118 /** \relates SIUnit */
119 UTILITIES_API SIUnit createSIAngle();
120 /** \relates SIUnit */
121 UTILITIES_API SIUnit createSISolidAngle();
122 /** \relates SIUnit */
123 UTILITIES_API SIUnit createSIPeople();
124 /** \relates SIUnit */
125 UTILITIES_API SIUnit createSICycle();
126 /** \relates SIUnit */
127 UTILITIES_API SIUnit createSICurrency();
128
129 // first order derived units
130
131 /** Newton (N) = kg*m/s^2. \relates SIUnit */
132 UTILITIES_API SIUnit createSIForce();
133 /** Joule (J) = N*m = kg*m^2/s^2. \relates SIUnit */
134 UTILITIES_API SIUnit createSIEnergy();
135 /** Watt (W) = J/s = N*m/s = kg*m^2/s^3. \relates SIUnit */
136 UTILITIES_API SIUnit createSIPower();
137 /** Coulomb (C) = s*A. \relates SIUnit */
138 UTILITIES_API SIUnit createSIElectricCharge();
139 /** Volt (V) = W/A = J/C = kg*m^2/s^3*A. \relates SIUnit */
140 UTILITIES_API SIUnit createSIElectricalPotential();
141 /** Farad (F) = C/V = C^2/J = s^4*A^2/kg*m^2. \relates SIUnit */
142 UTILITIES_API SIUnit createSIElectricCapacitance();
143 /** Ohm (ohm) = V/A = W/A^2 = kg*m^2/s^3*A^2. \relates SIUnit */
144 UTILITIES_API SIUnit createSIElectricResistance();
145 /** Weber (Wb) = J/A = kg*m^2/s^2*A. \relates SIUnit */
146 UTILITIES_API SIUnit createSIMagneticFlux();
147 /** Tesla (T) = Wb/m^2 = J/m^2*A = kg/s^2*A. \relates SIUnit */
148 UTILITIES_API SIUnit createSIMagneticFieldStrength();
149 /** Henry (H) = Wb/A = s*V/A = kg*m^2/s^2*A^2. \relates SIUnit */
150 UTILITIES_API SIUnit createSIInductance();
151 /** Lumen (lm) = cd*sr. \relates SIUnit */
152 UTILITIES_API SIUnit createSILuminousFlux();
153 /** Lux (lux or lx) = lm/m^2 = cd*sr/m^2. \relates SIUnit */
154 UTILITIES_API SIUnit createSIIlluminance();
155 /** Hertz (Hz) = cycles/s. Making the distinction between 1/s and cycles/s here mainly to be
156 * consistent with the rotations per minute (rpm) designation made elsewhere. \relates SIUnit */
157 UTILITIES_API SIUnit createSIFrequency();
158
159 // second order derived units
160
161 /** J/m^2 = kg/s^2. That this is measured on an annual basis is implied. \relates SIUnit */
162 UTILITIES_API SIUnit createSIEnergyUseIntensity();
163 /** W/m^2 = kg/s^3. \relates SIUnit */
164 UTILITIES_API SIUnit createSIPowerDensity();
165 /** W/person = kg*m^2/s^3*person. \relates SIUnit */
166 UTILITIES_API SIUnit createSIPowerPerPerson();
167 /** Pa = N/m^2 = kg/m*s^2. \relates SIUnit */
168 UTILITIES_API SIUnit createSIPressure();
169 /** W/m^2*K = kg/s^3*K \relates SIUnit */
170 UTILITIES_API SIUnit createSIThermalConductance();
171 /** m^2*K/W = s^3*K/kg \relates SIUnit */
172 UTILITIES_API SIUnit createSIThermalResistance();
173 /** J/m^2*K = kg/s^2*K \relates SIUnit */
174 UTILITIES_API SIUnit createSIHeatCapacity();
175
176 //@}
177
178 } // namespace openstudio
179
180 #endif // UTILITIES_UNITS_SIUNIT_HPP
181