src/utilities/units/MPHUnit.cpp
| 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 | #include "MPHUnit.hpp" | ||
| 7 | #include "MPHUnit_Impl.hpp" | ||
| 8 | |||
| 9 | #include "../core/Assert.hpp" | ||
| 10 | |||
| 11 | namespace openstudio { | ||
| 12 | namespace detail { | ||
| 13 | |||
| 14 | 1368 | MPHUnit_Impl::MPHUnit_Impl(const MPHExpnt& exponents, int scaleExponent, const std::string& prettyString) | |
| 15 |
2/2✓ Branch 1 taken 1368 times.
✓ Branch 4 taken 1368 times.
|
1368 | : Unit_Impl(scaleExponent, prettyString, 12, UnitSystem::MPH) { |
| 16 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[0].first = "inHg"; |
| 17 | 1368 | m_units[0].second = exponents.m_inHg; | |
| 18 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[1].first = "mi"; |
| 19 | 1368 | m_units[1].second = exponents.m_mi; | |
| 20 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[2].first = "h"; |
| 21 | 1368 | m_units[2].second = exponents.m_h; | |
| 22 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[3].first = "R"; |
| 23 | 1368 | m_units[3].second = exponents.m_R; | |
| 24 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[4].first = "A"; |
| 25 | 1368 | m_units[4].second = exponents.m_A; | |
| 26 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[5].first = "cd"; |
| 27 | 1368 | m_units[5].second = exponents.m_cd; | |
| 28 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[6].first = "lbmol"; |
| 29 | 1368 | m_units[6].second = exponents.m_lbmol; | |
| 30 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[7].first = "deg"; |
| 31 | 1368 | m_units[7].second = exponents.m_deg; | |
| 32 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[8].first = "sr"; |
| 33 | 1368 | m_units[8].second = exponents.m_sr; | |
| 34 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[9].first = "people"; |
| 35 | 1368 | m_units[9].second = exponents.m_people; | |
| 36 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[10].first = "cycle"; |
| 37 | 1368 | m_units[10].second = exponents.m_cycle; | |
| 38 |
1/1✓ Branch 2 taken 1368 times.
|
1368 | m_units[11].first = "$"; |
| 39 | 1368 | m_units[11].second = exponents.m_dollar; | |
| 40 | 1368 | } | |
| 41 | |||
| 42 | ✗ | MPHUnit_Impl::MPHUnit_Impl(const std::string& scaleAbbreviation, const MPHExpnt& exponents, const std::string& prettyString) | |
| 43 | ✗ | : Unit_Impl(scaleAbbreviation, prettyString, 12, UnitSystem::MPH) { | |
| 44 | ✗ | m_units[0].first = "inHg"; | |
| 45 | ✗ | m_units[0].second = exponents.m_inHg; | |
| 46 | ✗ | m_units[1].first = "mi"; | |
| 47 | ✗ | m_units[1].second = exponents.m_mi; | |
| 48 | ✗ | m_units[2].first = "h"; | |
| 49 | ✗ | m_units[2].second = exponents.m_h; | |
| 50 | ✗ | m_units[3].first = "R"; | |
| 51 | ✗ | m_units[3].second = exponents.m_R; | |
| 52 | ✗ | m_units[4].first = "A"; | |
| 53 | ✗ | m_units[4].second = exponents.m_A; | |
| 54 | ✗ | m_units[5].first = "cd"; | |
| 55 | ✗ | m_units[5].second = exponents.m_cd; | |
| 56 | ✗ | m_units[6].first = "lbmol"; | |
| 57 | ✗ | m_units[6].second = exponents.m_lbmol; | |
| 58 | ✗ | m_units[7].first = "deg"; | |
| 59 | ✗ | m_units[7].second = exponents.m_deg; | |
| 60 | ✗ | m_units[8].first = "sr"; | |
| 61 | ✗ | m_units[8].second = exponents.m_sr; | |
| 62 | ✗ | m_units[9].first = "people"; | |
| 63 | ✗ | m_units[9].second = exponents.m_people; | |
| 64 | ✗ | m_units[10].first = "cycle"; | |
| 65 | ✗ | m_units[10].second = exponents.m_cycle; | |
| 66 | ✗ | m_units[11].first = "$"; | |
| 67 | ✗ | m_units[11].second = exponents.m_dollar; | |
| 68 | ✗ | } | |
| 69 | |||
| 70 | 313 | Unit MPHUnit_Impl::clone() const { | |
| 71 |
3/5✓ Branch 1 taken 313 times.
✓ Branch 4 taken 313 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 313 times.
✗ Branch 10 not taken.
|
313 | OS_ASSERT(system() == UnitSystem::MPH); |
| 72 |
3/5✓ Branch 1 taken 313 times.
✓ Branch 4 taken 313 times.
✓ Branch 7 taken 313 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
313 | std::shared_ptr<MPHUnit_Impl> impl(new MPHUnit_Impl(*this)); |
| 73 |
2/2✓ Branch 2 taken 313 times.
✓ Branch 5 taken 313 times.
|
626 | return MPHUnit(impl).cast<Unit>(); |
| 74 | 313 | } | |
| 75 | |||
| 76 | ✗ | void MPHUnit_Impl::setBaseUnitExponent(const std::string& baseUnit, int exponent) { | |
| 77 | ✗ | auto loc = findBaseUnit(baseUnit); | |
| 78 | ✗ | if (loc != m_units.end()) { | |
| 79 | ✗ | loc->second = exponent; | |
| 80 | } else { | ||
| 81 | ✗ | LOG_AND_THROW("Cannot add base units to an instance of MPHUnit."); | |
| 82 | } | ||
| 83 | ✗ | } | |
| 84 | |||
| 85 | } // namespace detail | ||
| 86 | |||
| 87 | 1368 | MPHUnit::MPHUnit(const MPHExpnt& exponents, int scaleExponent, const std::string& prettyString) | |
| 88 |
4/6✓ Branch 1 taken 1368 times.
✓ Branch 4 taken 1368 times.
✓ Branch 7 taken 1368 times.
✓ Branch 10 taken 1368 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
1368 | : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::MPHUnit_Impl(exponents, scaleExponent, prettyString))) {} |
| 89 | |||
| 90 | ✗ | MPHUnit::MPHUnit(const std::string& scaleAbbreviation, const MPHExpnt& exponents, const std::string& prettyString) | |
| 91 | ✗ | : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::MPHUnit_Impl(scaleAbbreviation, exponents, prettyString))) {} | |
| 92 | |||
| 93 | /// @cond | ||
| 94 |
1/1✓ Branch 2 taken 313 times.
|
313 | MPHUnit::MPHUnit(std::shared_ptr<detail::MPHUnit_Impl> impl) : Unit(std::dynamic_pointer_cast<detail::Unit_Impl>(impl)) {} |
| 95 | /// @endcond | ||
| 96 | |||
| 97 | 101 | MPHUnit createMPHPressure() { | |
| 98 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
|
202 | return MPHUnit(MPHExpnt(1)); |
| 99 | } | ||
| 100 | |||
| 101 | 107 | MPHUnit createMPHLength() { | |
| 102 |
2/2✓ Branch 1 taken 107 times.
✓ Branch 5 taken 107 times.
|
214 | return MPHUnit(MPHExpnt(0, 1)); |
| 103 | } | ||
| 104 | |||
| 105 | 108 | MPHUnit createMPHTime() { | |
| 106 |
2/2✓ Branch 1 taken 108 times.
✓ Branch 5 taken 108 times.
|
216 | return MPHUnit(MPHExpnt(0, 0, 1)); |
| 107 | } | ||
| 108 | |||
| 109 | 100 | MPHUnit createMPHTemperature() { | |
| 110 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 1)); |
| 111 | } | ||
| 112 | |||
| 113 | 100 | MPHUnit createMPHElectricCurrent() { | |
| 114 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 1)); |
| 115 | } | ||
| 116 | |||
| 117 | 100 | MPHUnit createMPHLuminousIntensity() { | |
| 118 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 1)); |
| 119 | } | ||
| 120 | |||
| 121 | 100 | MPHUnit createMPHAmountOfSubstance() { | |
| 122 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 0, 1)); |
| 123 | } | ||
| 124 | |||
| 125 | 100 | MPHUnit createMPHAngle() { | |
| 126 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 0, 0, 1)); |
| 127 | } | ||
| 128 | |||
| 129 | 100 | MPHUnit createMPHSolidAngle() { | |
| 130 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 131 | } | ||
| 132 | |||
| 133 | 102 | MPHUnit createMPHPeople() { | |
| 134 |
2/2✓ Branch 1 taken 102 times.
✓ Branch 5 taken 102 times.
|
204 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 135 | } | ||
| 136 | |||
| 137 | 100 | MPHUnit createMPHCycle() { | |
| 138 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); |
| 139 | } | ||
| 140 | |||
| 141 | ✗ | MPHUnit createMPHCurrency() { | |
| 142 | ✗ | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)); | |
| 143 | } | ||
| 144 | |||
| 145 | 100 | MPHUnit createMPHVelocity() { | |
| 146 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 1, -1), 0, "mph"); |
| 147 | } | ||
| 148 | |||
| 149 | 100 | MPHUnit createMPHLuminousFlux() { | |
| 150 |
2/2✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
|
200 | return MPHUnit(MPHExpnt(0, 0, 0, 0, 0, 1, 0, 0, 1), 0, "lm"); |
| 151 | } | ||
| 152 | |||
| 153 | } // namespace openstudio | ||
| 154 |