MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / standardString

Method standardString

src/utilities/units/Unit.cpp:131–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129 }
130
131 std::string Unit_Impl::standardString(bool withScale) const {
132 if (withScale && (scale().abbr.empty())) {
133 withScale = false;
134 }
135
136 std::stringstream result;
137 bool parentheses(false);
138
139 // determine number of non-zero, positive, and negative baseUnits
140 int nnz(0);
141 int npos(0);
142 std::vector<UnitElement>::const_iterator unitsIter;
143 std::vector<UnitElement>::const_iterator firstPosIter;
144 std::vector<UnitElement>::const_iterator firstNegIter;
145 auto unitsEnd = m_units.end();
146
147 firstPosIter = unitsEnd;
148 firstNegIter = unitsEnd;
149
150 for (unitsIter = m_units.begin(); unitsIter != unitsEnd; ++unitsIter) {
151 if (unitsIter->second > 0) {
152 ++npos;
153 ++nnz;
154 if (firstPosIter == unitsEnd) {
155 firstPosIter = unitsIter;
156 }
157 }
158 if (unitsIter->second < 0) {
159 ++nnz;
160 if (firstNegIter == unitsEnd) {
161 firstNegIter = unitsIter;
162 }
163 }
164 }
165
166 if (withScale) {
167 if (nnz == 0) {
168 parentheses = true;
169 result << scale().abbr << "(";
170 } else {
171 ScaleConstant printScale = m_scale;
172 if (npos > 0) {
173 if (firstPosIter->second > 1) {
174 parentheses = true;
175 // see if can pull scale into exponent
176 if (scale().exponent % firstPosIter->second == 0) {
177 ScaleConstant candidateScale = ScaleFactory::instance().createScale(scale().exponent / firstPosIter->second);
178 if (candidateScale().value != 0.0) {
179 printScale = candidateScale;
180 parentheses = false;
181 }
182 }
183 }
184 result << printScale().abbr;
185 if (parentheses) {
186 result << "(";
187 }
188 } else {

Callers 15

test_UnitConstructorsMethod · 0.80
getUnitsMethod · 0.80
TEST_FFunction · 0.80
registerUnitMethod · 0.80
prettyStringMethod · 0.80
operator*=Method · 0.80
powMethod · 0.80
standardUnitsStringMethod · 0.80
IddUnitStringMethod · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80
TEST_FFunction · 0.80

Calls 5

beginMethod · 0.80
createScaleMethod · 0.80
emptyMethod · 0.45
endMethod · 0.45
strMethod · 0.45

Tested by 10

test_UnitConstructorsMethod · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64
TEST_FFunction · 0.64