GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 92.7% 380 / 0 / 410
Functions: 92.1% 35 / 0 / 38
Branches: 64.1% 535 / 0 / 835

src/utilities/idd/IddField.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 "IddField.hpp"
7 #include "IddField_Impl.hpp"
8
9 #include "IddRegex.hpp"
10 #include "CommentRegex.hpp"
11 #include <utilities/idd/IddFactory.hxx>
12
13 #include "../units/UnitFactory.hpp"
14 #include "../units/IddUnitString.hpp"
15 #include "../units/QuantityConverter.hpp"
16 #include "../units/SIUnit.hpp"
17 #include "../units/IPUnit.hpp"
18 #include "../units/Quantity.hpp"
19
20 #include "../core/ASCIIStrings.hpp"
21 #include "../core/Assert.hpp"
22 #include "../core/Containers.hpp"
23
24 #include <boost/lexical_cast.hpp>
25
26 using boost::algorithm::trim;
27
28 namespace openstudio {
29
30 namespace detail {
31
32 // CONSTRUCTORS
33
34 /// default constructor for serialization
35 ✗ IddField_Impl::IddField_Impl() = default;
36
37
2/2
✓ Branch 3 taken 13995333 times.
✓ Branch 6 taken 13995333 times.
13995333 IddField_Impl::IddField_Impl(const std::string& name, const std::string& objectName) : m_name(name), m_objectName(objectName) {}
38
39 // GETTERS
40
41 18410021 std::string IddField_Impl::name() const {
42 18410021 return m_name;
43 }
44
45 3 std::string IddField_Impl::fieldId() const {
46 3 return m_fieldId;
47 }
48
49 126852103 const IddFieldProperties& IddField_Impl::properties() const {
50 126852103 return m_properties;
51 }
52
53 457 boost::optional<Unit> IddField_Impl::getUnits(bool returnIP) const {
54 457 OptionalUnit result;
55
56
3/3
✓ Branch 1 taken 457 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 453 times.
457 if (unitsBasedOnOtherField()) {
57 4 return result;
58 }
59
60
2/2
✓ Branch 0 taken 243 times.
✓ Branch 1 taken 210 times.
453 if (returnIP) {
61
4/4
✓ Branch 1 taken 243 times.
✓ Branch 4 taken 243 times.
✓ Branch 6 taken 149 times.
✓ Branch 7 taken 94 times.
486 if (OptionalString units = properties().ipUnits) {
62
2/2
✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
149 IddUnitString iddUnits(*units);
63 // let factory determine best system
64
2/2
✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
149 result = createUnit(iddUnits.toStandardUnitString());
65
6/19
✓ Branch 1 taken 149 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 149 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 149 times.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 149 times.
✓ Branch 21 taken 149 times.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 149 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
298 if (result && !iddUnits.prettyString().empty() && result->prettyString(false).empty()) {
66 ✗ result->setPrettyString(iddUnits.prettyString());
67 }
68 149 } else {
69 // figure out based on SIUnits
70
1/1
✓ Branch 1 taken 94 times.
94 OptionalUnit siUnit = getUnits(false);
71
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if (siUnit) {
72 // if default is Celsius, return Fahrenheit
73
5/5
✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
✓ Branch 7 taken 94 times.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 93 times.
94 if (siUnit->system() == UnitSystem::Celsius) {
74
7/7
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
1 return convert(Quantity(1.0, *siUnit), UnitSystem(UnitSystem::Fahrenheit)).get().units();
75 }
76 // if default is not SI, return as-is
77
5/5
✓ Branch 1 taken 93 times.
✓ Branch 4 taken 93 times.
✓ Branch 7 taken 93 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 79 times.
93 if (siUnit->system() != UnitSystem::SI) {
78 14 return siUnit;
79 }
80 // if dimensionless, return IP dimensionless
81
4/4
✓ Branch 1 taken 79 times.
✓ Branch 4 taken 79 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 71 times.
79 if (siUnit->standardString(false).empty()) {
82
3/3
✓ Branch 1 taken 8 times.
✓ Branch 5 taken 8 times.
✓ Branch 8 taken 8 times.
16 return IPUnit();
83 }
84
1/1
✓ Branch 1 taken 71 times.
71 UnitSystem sys(UnitSystem::IP);
85 // if pretty string contains W or J, use BTU system
86
2/2
✓ Branch 1 taken 71 times.
✓ Branch 4 taken 71 times.
71 std::string tempString = siUnit->prettyString(false);
87
2/2
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 40 times.
71 if (!tempString.empty()) {
88
1/1
✓ Branch 1 taken 31 times.
31 Unit tempUnit = parseUnitString(tempString);
89
16/26
✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 6 taken 19 times.
✓ Branch 7 taken 12 times.
✓ Branch 9 taken 19 times.
✓ Branch 12 taken 19 times.
✓ Branch 14 taken 11 times.
✓ Branch 15 taken 8 times.
✓ Branch 16 taken 19 times.
✓ Branch 17 taken 12 times.
✓ Branch 19 taken 19 times.
✓ Branch 20 taken 12 times.
✓ Branch 21 taken 31 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 31 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 23 times.
✓ Branch 27 taken 8 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
131 if ((tempUnit.baseUnitExponent("W") != 0) || (tempUnit.baseUnitExponent("J") != 0)) {
90
1/1
✓ Branch 1 taken 23 times.
23 sys = UnitSystem::BTU;
91 }
92 31 }
93 // otherwise, if standard string contains m and s, use CFM system
94
23/31
✓ Branch 1 taken 71 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 23 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
✓ Branch 13 taken 48 times.
✓ Branch 15 taken 25 times.
✓ Branch 16 taken 23 times.
✓ Branch 18 taken 25 times.
✓ Branch 21 taken 25 times.
✓ Branch 24 taken 25 times.
✓ Branch 26 taken 21 times.
✓ Branch 27 taken 4 times.
✓ Branch 28 taken 25 times.
✓ Branch 29 taken 46 times.
✓ Branch 31 taken 25 times.
✓ Branch 32 taken 46 times.
✓ Branch 33 taken 48 times.
✓ Branch 34 taken 23 times.
✓ Branch 36 taken 48 times.
✓ Branch 37 taken 23 times.
✓ Branch 38 taken 21 times.
✓ Branch 39 taken 50 times.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 48 not taken.
✗ Branch 49 not taken.
217 if ((sys == UnitSystem::IP) && (siUnit->baseUnitExponent("s") != 0) && (siUnit->baseUnitExponent("m") != 0)) {
95
1/1
✓ Branch 1 taken 21 times.
21 sys = UnitSystem::CFM;
96 }
97
6/6
✓ Branch 1 taken 71 times.
✓ Branch 4 taken 71 times.
✓ Branch 7 taken 71 times.
✓ Branch 10 taken 71 times.
✓ Branch 13 taken 71 times.
✓ Branch 16 taken 71 times.
71 return convert(Quantity(1.0, *siUnit), sys).get().units();
98 71 }
99 337 }
100 } else {
101
3/4
✓ Branch 1 taken 210 times.
✓ Branch 4 taken 210 times.
✓ Branch 6 taken 210 times.
✗ Branch 7 not taken.
420 if (OptionalString units = properties().units) {
102
2/2
✓ Branch 1 taken 210 times.
✓ Branch 4 taken 210 times.
210 IddUnitString iddUnits(*units);
103 // even here let factory determine best system (SI already preferred)
104
2/2
✓ Branch 1 taken 210 times.
✓ Branch 4 taken 210 times.
210 result = createUnit(iddUnits.toStandardUnitString());
105
13/19
✓ Branch 1 taken 210 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 210 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 205 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 3 times.
✓ Branch 18 taken 5 times.
✓ Branch 19 taken 205 times.
✓ Branch 21 taken 210 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 2 times.
✓ Branch 25 taken 208 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
420 if (result && !iddUnits.prettyString().empty() && result->prettyString(false).empty()) {
106
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 result->setPrettyString(iddUnits.prettyString());
107 }
108
0/4
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
210 } else if (properties().type == IddFieldType::RealType) {
109 // dimensionless by default
110 ✗ return SIUnit();
111 210 }
112 }
113
114 359 return result;
115 457 }
116
117 465 bool IddField_Impl::unitsBasedOnOtherField() const {
118
3/4
✓ Branch 1 taken 465 times.
✓ Branch 4 taken 465 times.
✓ Branch 6 taken 465 times.
✗ Branch 7 not taken.
930 if (OptionalString units = properties().units) {
119
5/5
✓ Branch 1 taken 465 times.
✓ Branch 4 taken 465 times.
✓ Branch 7 taken 465 times.
✓ Branch 10 taken 12 times.
✓ Branch 11 taken 453 times.
465 if (boost::regex_match(*units, boost::regex("BasedOnField A\\d+"))) {
120 12 return true;
121 }
122 465 }
123 453 return false;
124 }
125
126 18 OptionalIddKey IddField_Impl::getKey(const std::string& keyName) const {
127 18 OptionalIddKey result;
128
1/2
✓ Branch 5 taken 43 times.
✗ Branch 6 not taken.
43 for (const IddKey& key : m_keys) {
129
4/4
✓ Branch 2 taken 43 times.
✓ Branch 5 taken 43 times.
✓ Branch 9 taken 18 times.
✓ Branch 10 taken 25 times.
43 if (boost::iequals(key.name(), keyName)) {
130
1/1
✓ Branch 1 taken 18 times.
18 result = key;
131 18 break;
132 }
133 }
134 18 return result;
135 ✗ }
136
137 1447334 IddKeyVector IddField_Impl::keys() const {
138 1447334 return m_keys;
139 }
140
141 // SETTERS
142
143 346412 void IddField_Impl::setName(const std::string& name) {
144 346412 m_name = name;
145 346412 }
146
147 4 void IddField_Impl::incrementFieldId(const boost::regex& fieldType) {
148
1/1
✓ Branch 1 taken 4 times.
4 boost::regex fieldIdRegex("([AN])([0-9]+)");
149
1/1
✓ Branch 1 taken 4 times.
4 boost::smatch m;
150
1/1
✓ Branch 1 taken 4 times.
4 bool ok = boost::regex_match(m_fieldId, m, fieldIdRegex);
151
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
4 OS_ASSERT(ok);
152
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 std::string letterStr(m[1].first, m[1].second);
153
3/3
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3 times.
4 if (boost::regex_match(letterStr, fieldType)) {
154
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 std::string numberStr(m[2].first, m[2].second);
155
1/1
✓ Branch 1 taken 1 time.
1 int n = boost::lexical_cast<int>(numberStr);
156 1 ++n;
157
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 m_fieldId = letterStr + boost::lexical_cast<std::string>(n);
158 1 }
159 4 }
160
161 // QUERIES
162
163 5752514 bool IddField_Impl::isNameField() const {
164
3/3
✓ Branch 2 taken 322742 times.
✓ Branch 5 taken 27 times.
✓ Branch 6 taken 322715 times.
6075256 return (((!properties().references.empty()) && (properties().objectLists.empty()))
165
19/23
✓ Branch 1 taken 5752514 times.
✓ Branch 3 taken 322742 times.
✓ Branch 4 taken 5429772 times.
✓ Branch 7 taken 5429799 times.
✓ Branch 10 taken 5429799 times.
✓ Branch 12 taken 29553 times.
✓ Branch 13 taken 5400246 times.
✓ Branch 15 taken 29553 times.
✓ Branch 18 taken 29553 times.
✓ Branch 21 taken 2530 times.
✓ Branch 22 taken 27023 times.
✓ Branch 24 taken 2530 times.
✓ Branch 27 taken 2530 times.
✓ Branch 30 taken 2492 times.
✓ Branch 31 taken 38 times.
✓ Branch 32 taken 5429799 times.
✓ Branch 33 taken 322715 times.
✓ Branch 35 taken 5429799 times.
✓ Branch 36 taken 322715 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
11827770 || (boost::iequals("Name", name()) && ((properties().type == IddFieldType::AlphaType) || (properties().type == IddFieldType::NodeType))));
166 }
167
168 26002986 bool IddField_Impl::isObjectListField() const {
169
8/9
✓ Branch 1 taken 26002986 times.
✓ Branch 4 taken 26002986 times.
✓ Branch 7 taken 1934254 times.
✓ Branch 8 taken 24068732 times.
✓ Branch 10 taken 1934254 times.
✓ Branch 13 taken 1934254 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1934254 times.
✓ Branch 16 taken 24068732 times.
26002986 if ((properties().type == IddFieldType::ObjectListType) && (!properties().objectLists.empty())) {
170 1934254 return true;
171 }
172 24068732 return false;
173 }
174
175 390 bool IddField_Impl::operator==(const IddField_Impl& other) const {
176
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 389 times.
390 if (this == &other) {
177 1 return true;
178 }
179
180
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 388 times.
389 if (m_name != other.m_name) {
181 1 return false;
182 }
183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
388 if (m_fieldId != other.m_fieldId) {
184 ✗ return false;
185 }
186
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
388 if (m_objectName != other.m_objectName) {
187 ✗ return false;
188 }
189
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
388 if (m_properties != other.m_properties) {
190 ✗ return false;
191 }
192
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 388 times.
388 if (m_keys != other.m_keys) {
193 ✗ return false;
194 }
195
196 388 return true;
197 }
198
199 1 bool IddField_Impl::operator!=(const IddField_Impl& other) const {
200 1 return !(*this == other);
201 }
202
203 // SERIALIZATION
204
205 13995333 std::shared_ptr<IddField_Impl> IddField_Impl::load(const std::string& name, const std::string& text, const std::string& objectName) {
206
207 13995333 std::shared_ptr<IddField_Impl> result;
208
1/1
✓ Branch 1 taken 13995333 times.
13995333 IddField_Impl iddFieldImpl(name, objectName);
209
210 try {
211
1/1
✓ Branch 1 taken 13995333 times.
13995333 iddFieldImpl.parse(text);
212 ✗ } catch (...) {
213 ✗ return result;
214 ✗ }
215
216
3/5
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
✓ Branch 7 taken 13995333 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13995333 result = std::shared_ptr<IddField_Impl>(new IddField_Impl(iddFieldImpl));
217 13995333 return result;
218 13995333 }
219
220 737462 std::ostream& IddField_Impl::print(std::ostream& os, bool lastField) const {
221
8/12
✓ Branch 0 taken 57482 times.
✓ Branch 1 taken 679980 times.
✓ Branch 3 taken 57482 times.
✓ Branch 6 taken 679980 times.
✓ Branch 8 taken 679980 times.
✓ Branch 9 taken 57482 times.
✓ Branch 10 taken 57482 times.
✓ Branch 11 taken 679980 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
2154904 std::string separator = (lastField ? std::string(";") : std::string(","));
222
223
3/3
✓ Branch 1 taken 737462 times.
✓ Branch 4 taken 737462 times.
✓ Branch 7 taken 737462 times.
737462 os << " " << m_fieldId << separator;
224
225
2/2
✓ Branch 1 taken 737229 times.
✓ Branch 2 taken 233 times.
737462 if (m_name != m_fieldId) {
226
2/2
✓ Branch 1 taken 737229 times.
✓ Branch 4 taken 737229 times.
737229 os << " \\field " << m_name;
227 }
228
229
1/1
✓ Branch 1 taken 737462 times.
737462 os << '\n';
230
231
1/1
✓ Branch 1 taken 737462 times.
737462 m_properties.print(os);
232
233
2/2
✓ Branch 5 taken 346368 times.
✓ Branch 6 taken 737462 times.
1083830 for (const auto& key : m_keys) {
234
1/1
✓ Branch 1 taken 346368 times.
346368 key.print(os);
235 }
236
237 737462 return os;
238 737462 }
239
240 13995333 void IddField_Impl::parse(const std::string& text) {
241
1/1
✓ Branch 1 taken 13995333 times.
13995333 boost::smatch matches;
242
3/4
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
✓ Branch 6 taken 13995333 times.
✗ Branch 7 not taken.
13995333 if (boost::regex_search(text, matches, iddRegex::field())) {
243 // find and parse the field text
244
3/3
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
✓ Branch 7 taken 13995333 times.
27990666 std::string fieldTypeChar(matches[1].first, matches[1].second);
245
3/3
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
✓ Branch 7 taken 13995333 times.
27990666 std::string fieldTypeNumber(matches[2].first, matches[2].second);
246
3/3
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
✓ Branch 7 taken 13995333 times.
13995333 std::string fieldProperties(matches[3].first, matches[3].second);
247
248 // keep track of field id
249
1/1
✓ Branch 1 taken 13995333 times.
13995333 m_fieldId = fieldTypeChar + fieldTypeNumber;
250
251 // check for base content type
252
3/3
✓ Branch 2 taken 13995333 times.
✓ Branch 5 taken 7729584 times.
✓ Branch 6 taken 6265749 times.
13995333 if (boost::iequals(fieldTypeChar, "A")) {
253
1/1
✓ Branch 1 taken 7729584 times.
7729584 m_properties.type = IddFieldType(IddFieldType::AlphaType);
254
2/3
✓ Branch 2 taken 6265749 times.
✓ Branch 5 taken 6265749 times.
✗ Branch 6 not taken.
6265749 } else if (boost::iequals(fieldTypeChar, "N")) {
255 // default numerics to real, can be overwritten later
256
1/1
✓ Branch 1 taken 6265749 times.
6265749 m_properties.type = IddFieldType(IddFieldType::RealType);
257 } else {
258 ✗ LOG_AND_THROW("Unknown field type identifier found: '" << fieldTypeChar << "'");
259 }
260
261 // parse all the properties
262
4/4
✓ Branch 1 taken 86934663 times.
✓ Branch 4 taken 86934663 times.
✓ Branch 6 taken 72939330 times.
✓ Branch 7 taken 13995333 times.
86934663 while (boost::regex_search(fieldProperties, matches, iddRegex::metaDataComment())) {
263
3/3
✓ Branch 1 taken 72939330 times.
✓ Branch 4 taken 72939330 times.
✓ Branch 7 taken 72939330 times.
72939330 std::string thisProperty(matches[1].first, matches[1].second);
264
1/1
✓ Branch 1 taken 72939330 times.
72939330 openstudio::ascii_trim(thisProperty);
265
1/1
✓ Branch 1 taken 72939330 times.
72939330 parseProperty(thisProperty);
266
267
3/3
✓ Branch 1 taken 72939330 times.
✓ Branch 4 taken 72939330 times.
✓ Branch 7 taken 72939330 times.
72939330 fieldProperties = std::string(matches[2].first, matches[2].second);
268
1/1
✓ Branch 1 taken 72939330 times.
72939330 openstudio::ascii_trim(fieldProperties);
269 72939330 }
270
271
4/6
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13995333 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 13995333 times.
13995333 if (!((boost::regex_match(fieldProperties, commentRegex::whitespaceOnlyBlock()))
272 ✗ || (boost::regex_match(fieldProperties, iddRegex::commentOnlyLine())))) {
273 ✗ LOG_AND_THROW("Unable to parse remaining fields: '" << fieldProperties << "'");
274 }
275 13995333 } else {
276 ✗ LOG_AND_THROW("Field text does not match expected pattern: '" << text << "'");
277 }
278
279
3/3
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 1540199 times.
✓ Branch 5 taken 12455134 times.
13995333 if (m_properties.type == IddFieldType::ChoiceType) {
280 // if this is a choice, assert we have some keys
281
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1540199 times.
1540199 if (m_keys.empty()) {
282 ✗ LOG(Error, "Field is of type choice but keys are empty: '" << m_name << "'");
283 }
284 } else {
285 // else assert we have no keys
286
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12455134 times.
12455134 if (!m_keys.empty()) {
287 ✗ LOG(Error, "Field is not of type choice but has non-empty keys: '" << m_name << "'");
288 }
289 }
290
291
2/3
✓ Branch 1 taken 13995333 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13995333 times.
13995333 if (m_properties.type == IddFieldType::UnknownType) {
292
293 ✗ LOG_AND_THROW("Field is of unknown type after parsing: '" << m_name << "'");
294 }
295
296 // If the field has a default then it is not required. This overrides the idd text.
297
2/2
✓ Branch 1 taken 2817866 times.
✓ Branch 2 taken 11177467 times.
27990666 if (m_properties.stringDefault) {
298
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 2817786 times.
2817866 if (m_properties.required) {
299
9/9
✓ Branch 1 taken 80 times.
✓ Branch 4 taken 80 times.
✓ Branch 7 taken 80 times.
✓ Branch 10 taken 80 times.
✓ Branch 13 taken 80 times.
✓ Branch 16 taken 80 times.
✓ Branch 19 taken 80 times.
✓ Branch 22 taken 80 times.
✓ Branch 25 taken 80 times.
80 LOG(Info, "Field '" << m_name << "' of object '" << m_objectName << "' is both required and has default value, setting required = false.");
300 80 m_properties.required = false;
301 }
302 }
303 13995333 }
304
305 72939330 void IddField_Impl::parseProperty(const std::string& text) {
306 // this function is called very often and has been identified as a bottleneck
307 // that is why some of the optimizations below have been applied
308
309
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 72939330 times.
72939330 if (text.empty()) {
310 ✗ return;
311 }
312
313 72939330 bool notHandled = true;
314
1/1
✓ Branch 1 taken 72939330 times.
72939330 boost::smatch matches;
315
316
1/1
✓ Branch 2 taken 72939330 times.
72939330 std::string lowerText = openstudio::ascii_to_lower_copy(text);
317
318 72939330 const char index = lowerText[0];
319
320 //sort inside the case statements based on the probability of that value being in the string.(so we don't run 5 unlikely
321 //regex tofind the likely one) Keep the case statements in aphabitical order for ease of maintance, since it doesn't
322 //effect the speed
323
13/14
✓ Branch 0 taken 814930 times.
✓ Branch 1 taken 396007 times.
✓ Branch 2 taken 2821448 times.
✓ Branch 3 taken 2742 times.
✓ Branch 4 taken 13983683 times.
✓ Branch 5 taken 673684 times.
✓ Branch 6 taken 6643593 times.
✓ Branch 7 taken 5306657 times.
✓ Branch 8 taken 12777241 times.
✓ Branch 9 taken 3538060 times.
✓ Branch 10 taken 8753982 times.
✓ Branch 11 taken 13133938 times.
✓ Branch 12 taken 4093365 times.
✗ Branch 13 not taken.
72939330 switch (index) {
324
325 814930 case 'a': {
326
3/3
✓ Branch 1 taken 814930 times.
✓ Branch 3 taken 740568 times.
✓ Branch 4 taken 74362 times.
814930 if (boost::algorithm::starts_with(lowerText, "autosizable")) {
327 740568 m_properties.autosizable = true;
328 740568 notHandled = false;
329
2/3
✓ Branch 1 taken 74362 times.
✓ Branch 3 taken 74362 times.
✗ Branch 4 not taken.
74362 } else if (boost::algorithm::starts_with(lowerText, "autocalculatable")) {
330 74362 m_properties.autocalculatable = true;
331 74362 notHandled = false;
332 }
333 814930 break;
334 }
335 396007 case 'b': {
336
2/3
✓ Branch 1 taken 396007 times.
✓ Branch 3 taken 396007 times.
✗ Branch 4 not taken.
396007 if (boost::algorithm::starts_with(lowerText, "begin-extensible")) {
337 396007 m_properties.beginExtensible = true;
338 396007 notHandled = false;
339 }
340 396007 break;
341 }
342
343 2821448 case 'd': {
344
3/3
✓ Branch 1 taken 2821448 times.
✓ Branch 3 taken 2818132 times.
✓ Branch 4 taken 3316 times.
2821448 if (boost::algorithm::starts_with(lowerText, "default")) {
345
3/5
✓ Branch 1 taken 2818132 times.
✓ Branch 4 taken 2818132 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2818132 times.
✗ Branch 9 not taken.
2818132 OS_ASSERT(boost::regex_search(text, matches, iddRegex::defaultProperty()));
346
3/3
✓ Branch 1 taken 2818132 times.
✓ Branch 4 taken 2818132 times.
✓ Branch 7 taken 2818132 times.
2818132 std::string stringDefault(matches[1].first, matches[1].second);
347
1/1
✓ Branch 1 taken 2818132 times.
2818132 openstudio::ascii_trim(stringDefault);
348
1/1
✓ Branch 1 taken 2818132 times.
2818132 m_properties.stringDefault = stringDefault;
349 2818132 notHandled = false;
350 // if we are numeric type and not set to autosize, set the numeric property
351
8/8
✓ Branch 1 taken 2818132 times.
✓ Branch 4 taken 1009510 times.
✓ Branch 5 taken 1808622 times.
✓ Branch 7 taken 1009510 times.
✓ Branch 10 taken 124452 times.
✓ Branch 11 taken 885058 times.
✓ Branch 12 taken 1933074 times.
✓ Branch 13 taken 885058 times.
2818132 if ((m_properties.type == IddFieldType::RealType) || (m_properties.type == IddFieldType::IntegerType)) {
352
4/4
✓ Branch 1 taken 1933074 times.
✓ Branch 4 taken 1933074 times.
✓ Branch 6 taken 1771744 times.
✓ Branch 7 taken 161330 times.
1933074 if (!boost::regex_match(text, iddRegex::automaticDefault())) {
353
2/2
✓ Branch 1 taken 1771744 times.
✓ Branch 4 taken 1771744 times.
1771744 m_properties.numericDefault = boost::lexical_cast<double>(stringDefault);
354 } else {
355 // otherwise this is -9999
356
1/1
✓ Branch 1 taken 161330 times.
161330 m_properties.numericDefault = -9999;
357 }
358 }
359
2/3
✓ Branch 2 taken 3316 times.
✓ Branch 4 taken 3316 times.
✗ Branch 5 not taken.
2821448 } else if (boost::algorithm::starts_with(lowerText, "deprecated")) {
360 3316 m_properties.deprecated = true;
361 3316 notHandled = false;
362 }
363 2821448 break;
364 }
365 2742 case 'e': {
366
2/3
✓ Branch 1 taken 2742 times.
✓ Branch 3 taken 2742 times.
✗ Branch 4 not taken.
2742 if (boost::algorithm::starts_with(lowerText, "external-list")) {
367
3/5
✓ Branch 1 taken 2742 times.
✓ Branch 4 taken 2742 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2742 times.
✗ Branch 9 not taken.
2742 OS_ASSERT(boost::regex_search(text, matches, iddRegex::externalListProperty()));
368
3/3
✓ Branch 1 taken 2742 times.
✓ Branch 4 taken 2742 times.
✓ Branch 7 taken 2742 times.
2742 std::string externalList(matches[1].first, matches[1].second);
369
1/1
✓ Branch 1 taken 2742 times.
2742 openstudio::ascii_trim(externalList);
370
1/1
✓ Branch 1 taken 2742 times.
2742 m_properties.externalLists.push_back(externalList);
371 2742 notHandled = false;
372 2742 }
373
374 2742 break;
375 }
376 13983683 case 'f': {
377
2/3
✓ Branch 1 taken 13983683 times.
✓ Branch 3 taken 13983683 times.
✗ Branch 4 not taken.
13983683 if (boost::algorithm::starts_with(lowerText, "field")) {
378
3/5
✓ Branch 1 taken 13983683 times.
✓ Branch 4 taken 13983683 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13983683 times.
✗ Branch 9 not taken.
13983683 OS_ASSERT(boost::regex_search(text, matches, iddRegex::nameProperty()));
379
3/3
✓ Branch 1 taken 13983683 times.
✓ Branch 4 taken 13983683 times.
✓ Branch 7 taken 13983683 times.
13983683 std::string fieldName(matches[1].first, matches[1].second);
380
1/1
✓ Branch 1 taken 13983683 times.
13983683 openstudio::ascii_trim(fieldName);
381 13983683 notHandled = false;
382
2/3
✓ Branch 1 taken 13983683 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13983683 times.
13983683 if (!boost::equals(m_name, fieldName)) {
383 ✗ LOG_AND_THROW("Field name '" << fieldName << "' does not match expected '" << m_name << "' in object '" << m_objectName << "'");
384 }
385 13983683 }
386 13983683 break;
387 }
388 673684 case 'i': {
389
2/3
✓ Branch 1 taken 673684 times.
✓ Branch 3 taken 673684 times.
✗ Branch 4 not taken.
673684 if (boost::algorithm::starts_with(lowerText, "ip-units")) {
390
3/5
✓ Branch 1 taken 673684 times.
✓ Branch 4 taken 673684 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 673684 times.
✗ Branch 9 not taken.
673684 OS_ASSERT(boost::regex_search(text, matches, iddRegex::ipUnitsProperty()));
391
3/3
✓ Branch 1 taken 673684 times.
✓ Branch 4 taken 673684 times.
✓ Branch 7 taken 673684 times.
673684 std::string ipUnits(matches[1].first, matches[1].second);
392
1/1
✓ Branch 1 taken 673684 times.
673684 openstudio::ascii_trim(ipUnits);
393
1/1
✓ Branch 1 taken 673684 times.
673684 m_properties.ipUnits = ipUnits;
394 673684 notHandled = false;
395 673684 }
396 673684 break;
397 }
398
399 6643593 case 'k': {
400
2/3
✓ Branch 1 taken 6643593 times.
✓ Branch 3 taken 6643593 times.
✗ Branch 4 not taken.
6643593 if (boost::algorithm::starts_with(lowerText, "key")) {
401
3/5
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 6643593 times.
✗ Branch 9 not taken.
6643593 OS_ASSERT(boost::regex_search(text, matches, iddRegex::keyProperty()));
402
3/3
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 7 taken 6643593 times.
6643593 std::string keyText(matches[1].first, matches[1].second);
403 6643593 notHandled = false;
404
1/1
✓ Branch 1 taken 6643593 times.
6643593 boost::smatch keyMatches;
405
3/4
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 6 taken 6643593 times.
✗ Branch 7 not taken.
6643593 if (boost::regex_search(keyText, keyMatches, iddRegex::contentAndCommentLine())) {
406
3/3
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 7 taken 6643593 times.
6643593 std::string keyName(keyMatches[1].first, keyMatches[1].second);
407
1/1
✓ Branch 1 taken 6643593 times.
6643593 openstudio::ascii_trim(keyName);
408
409 // construct the key
410
1/1
✓ Branch 1 taken 6643593 times.
6643593 OptionalIddKey key = IddKey::load(keyName, keyText);
411
412 // add the key to the keys
413
1/2
✓ Branch 0 taken 6643593 times.
✗ Branch 1 not taken.
6643593 if (key) {
414
2/2
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
6643593 m_keys.push_back(*key);
415 } else {
416 ✗ LOG_AND_THROW("Key could not be loaded from text '" << keyText << "'.");
417 }
418
419 6643593 } else {
420 ✗ LOG_AND_THROW("Key name could not be determined from text '" << keyText << "'.");
421 }
422 6643593 }
423 6643593 break;
424 }
425 5306657 case 'm': {
426
3/3
✓ Branch 1 taken 5306657 times.
✓ Branch 3 taken 3899821 times.
✓ Branch 4 taken 1406836 times.
5306657 if (boost::algorithm::starts_with(lowerText, "minimum")) {
427
4/4
✓ Branch 1 taken 3899821 times.
✓ Branch 4 taken 3899821 times.
✓ Branch 6 taken 1436365 times.
✓ Branch 7 taken 2463456 times.
3899821 if (boost::regex_search(text, matches, iddRegex::minExclusiveProperty())) {
428 1436365 m_properties.minBoundType = IddFieldProperties::ExclusiveBound;
429
3/3
✓ Branch 1 taken 1436365 times.
✓ Branch 4 taken 1436365 times.
✓ Branch 7 taken 1436365 times.
1436365 std::string minExclusive(matches[1].first, matches[1].second);
430
1/1
✓ Branch 1 taken 1436365 times.
1436365 openstudio::ascii_trim(minExclusive);
431
2/2
✓ Branch 1 taken 1436365 times.
✓ Branch 4 taken 1436365 times.
1436365 m_properties.minBoundValue = boost::lexical_cast<double>(minExclusive);
432
1/1
✓ Branch 1 taken 1436365 times.
1436365 m_properties.minBoundText = minExclusive;
433 1436365 notHandled = false;
434
3/4
✓ Branch 2 taken 2463456 times.
✓ Branch 5 taken 2463456 times.
✓ Branch 7 taken 2463456 times.
✗ Branch 8 not taken.
3899821 } else if (boost::regex_search(text, matches, iddRegex::minInclusiveProperty())) {
435 2463456 m_properties.minBoundType = IddFieldProperties::InclusiveBound;
436
3/3
✓ Branch 1 taken 2463456 times.
✓ Branch 4 taken 2463456 times.
✓ Branch 7 taken 2463456 times.
2463456 std::string minInclusive(matches[1].first, matches[1].second);
437
1/1
✓ Branch 1 taken 2463456 times.
2463456 openstudio::ascii_trim(minInclusive);
438
2/2
✓ Branch 1 taken 2463456 times.
✓ Branch 4 taken 2463456 times.
2463456 m_properties.minBoundValue = boost::lexical_cast<double>(minInclusive);
439
1/1
✓ Branch 1 taken 2463456 times.
2463456 m_properties.minBoundText = minInclusive;
440 2463456 notHandled = false;
441 2463456 }
442
3/3
✓ Branch 1 taken 1406836 times.
✓ Branch 3 taken 1375436 times.
✓ Branch 4 taken 31400 times.
1406836 } else if (boost::algorithm::starts_with(lowerText, "maximum")) {
443
4/4
✓ Branch 1 taken 1375436 times.
✓ Branch 4 taken 1375436 times.
✓ Branch 6 taken 149158 times.
✓ Branch 7 taken 1226278 times.
1375436 if (boost::regex_search(text, matches, iddRegex::maxExclusiveProperty())) {
444 149158 m_properties.maxBoundType = IddFieldProperties::ExclusiveBound;
445
3/3
✓ Branch 1 taken 149158 times.
✓ Branch 4 taken 149158 times.
✓ Branch 7 taken 149158 times.
149158 std::string maxExclusive(matches[1].first, matches[1].second);
446
1/1
✓ Branch 1 taken 149158 times.
149158 openstudio::ascii_trim(maxExclusive);
447
2/2
✓ Branch 1 taken 149158 times.
✓ Branch 4 taken 149158 times.
149158 m_properties.maxBoundValue = boost::lexical_cast<double>(maxExclusive);
448
1/1
✓ Branch 1 taken 149158 times.
149158 m_properties.maxBoundText = maxExclusive;
449 149158 notHandled = false;
450
3/4
✓ Branch 2 taken 1226278 times.
✓ Branch 5 taken 1226278 times.
✓ Branch 7 taken 1226278 times.
✗ Branch 8 not taken.
1375436 } else if (boost::regex_search(text, matches, iddRegex::maxInclusiveProperty())) {
451 1226278 m_properties.maxBoundType = IddFieldProperties::InclusiveBound;
452
3/3
✓ Branch 1 taken 1226278 times.
✓ Branch 4 taken 1226278 times.
✓ Branch 7 taken 1226278 times.
1226278 std::string maxInclusive(matches[1].first, matches[1].second);
453
1/1
✓ Branch 1 taken 1226278 times.
1226278 openstudio::ascii_trim(maxInclusive);
454
2/2
✓ Branch 1 taken 1226278 times.
✓ Branch 4 taken 1226278 times.
1226278 m_properties.maxBoundValue = boost::lexical_cast<double>(maxInclusive);
455
1/1
✓ Branch 1 taken 1226278 times.
1226278 m_properties.maxBoundText = maxInclusive;
456 1226278 notHandled = false;
457 1226278 }
458
2/3
✓ Branch 1 taken 31400 times.
✓ Branch 3 taken 31400 times.
✗ Branch 4 not taken.
31400 } else if (boost::algorithm::starts_with(lowerText, "memo")) {
459 31400 notHandled = false;
460
3/5
✓ Branch 1 taken 31400 times.
✓ Branch 4 taken 31400 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 31400 times.
✗ Branch 9 not taken.
31400 OS_ASSERT(boost::regex_search(text, matches, iddRegex::memoProperty()));
461
3/3
✓ Branch 1 taken 31400 times.
✓ Branch 4 taken 31400 times.
✓ Branch 7 taken 31400 times.
31400 std::string memo(matches[1].first, matches[1].second);
462
1/1
✓ Branch 2 taken 31400 times.
31400 trim(memo);
463
2/2
✓ Branch 1 taken 7368 times.
✓ Branch 2 taken 24032 times.
31400 if (m_properties.note.empty()) {
464
1/1
✓ Branch 1 taken 7368 times.
7368 m_properties.note = memo;
465 } else {
466
2/2
✓ Branch 1 taken 24032 times.
✓ Branch 4 taken 24032 times.
24032 m_properties.note += "\n" + memo;
467 }
468 31400 }
469 5306657 break;
470 }
471 12777241 case 'n': {
472
2/3
✓ Branch 1 taken 12777241 times.
✓ Branch 3 taken 12777241 times.
✗ Branch 4 not taken.
12777241 if (boost::algorithm::starts_with(lowerText, "note")) {
473 12777241 notHandled = false;
474
3/5
✓ Branch 1 taken 12777241 times.
✓ Branch 4 taken 12777241 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12777241 times.
✗ Branch 9 not taken.
12777241 OS_ASSERT(boost::regex_search(text, matches, iddRegex::noteProperty()));
475
3/3
✓ Branch 1 taken 12777241 times.
✓ Branch 4 taken 12777241 times.
✓ Branch 7 taken 12777241 times.
12777241 std::string note(matches[1].first, matches[1].second);
476
1/1
✓ Branch 2 taken 12777241 times.
12777241 trim(note);
477
2/2
✓ Branch 1 taken 5344896 times.
✓ Branch 2 taken 7432345 times.
12777241 if (m_properties.note.empty()) {
478
1/1
✓ Branch 1 taken 5344896 times.
5344896 m_properties.note = note;
479 } else {
480
2/2
✓ Branch 1 taken 7432345 times.
✓ Branch 4 taken 7432345 times.
7432345 m_properties.note += "\n" + note;
481 }
482 12777241 }
483 12777241 break;
484 }
485 3538060 case 'o': {
486
2/3
✓ Branch 1 taken 3538060 times.
✓ Branch 3 taken 3538060 times.
✗ Branch 4 not taken.
3538060 if (boost::algorithm::starts_with(lowerText, "object-list")) {
487
3/5
✓ Branch 1 taken 3538060 times.
✓ Branch 4 taken 3538060 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 3538060 times.
✗ Branch 9 not taken.
3538060 OS_ASSERT(boost::regex_search(text, matches, iddRegex::objectListProperty()));
488
3/3
✓ Branch 1 taken 3538060 times.
✓ Branch 4 taken 3538060 times.
✓ Branch 7 taken 3538060 times.
3538060 std::string objectList(matches[1].first, matches[1].second);
489
1/1
✓ Branch 1 taken 3538060 times.
3538060 openstudio::ascii_trim(objectList);
490
1/1
✓ Branch 1 taken 3538060 times.
3538060 m_properties.objectLists.push_back(objectList);
491 3538060 notHandled = false;
492 3538060 }
493 3538060 break;
494 }
495 8753982 case 'r': {
496
3/3
✓ Branch 1 taken 8753982 times.
✓ Branch 3 taken 7113378 times.
✓ Branch 4 taken 1640604 times.
8753982 if (boost::algorithm::starts_with(lowerText, "required-field")) {
497 7113378 m_properties.required = true;
498 7113378 notHandled = false;
499
3/3
✓ Branch 1 taken 1640604 times.
✓ Branch 3 taken 15989 times.
✓ Branch 4 taken 1624615 times.
1640604 } else if (boost::algorithm::starts_with(lowerText, "reference-class-name")) {
500
3/5
✓ Branch 1 taken 15989 times.
✓ Branch 4 taken 15989 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 15989 times.
✗ Branch 9 not taken.
15989 OS_ASSERT(boost::regex_search(text, matches, iddRegex::referenceClassNameProperty()));
501
3/3
✓ Branch 1 taken 15989 times.
✓ Branch 4 taken 15989 times.
✓ Branch 7 taken 15989 times.
15989 std::string reference(matches[1].first, matches[1].second);
502
1/1
✓ Branch 1 taken 15989 times.
15989 openstudio::ascii_trim(reference);
503
1/1
✓ Branch 1 taken 15989 times.
15989 m_properties.referenceClassNames.push_back(reference);
504 15989 notHandled = false;
505
3/3
✓ Branch 2 taken 1624615 times.
✓ Branch 4 taken 1486378 times.
✓ Branch 5 taken 138237 times.
1640604 } else if (boost::algorithm::starts_with(lowerText, "reference")) {
506
3/5
✓ Branch 1 taken 1486378 times.
✓ Branch 4 taken 1486378 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1486378 times.
✗ Branch 9 not taken.
1486378 OS_ASSERT(boost::regex_search(text, matches, iddRegex::referenceProperty()));
507
3/3
✓ Branch 1 taken 1486378 times.
✓ Branch 4 taken 1486378 times.
✓ Branch 7 taken 1486378 times.
1486378 std::string reference(matches[1].first, matches[1].second);
508
1/1
✓ Branch 1 taken 1486378 times.
1486378 openstudio::ascii_trim(reference);
509
1/1
✓ Branch 1 taken 1486378 times.
1486378 m_properties.references.push_back(reference);
510 1486378 notHandled = false;
511
2/3
✓ Branch 2 taken 138237 times.
✓ Branch 4 taken 138237 times.
✗ Branch 5 not taken.
1624615 } else if (boost::algorithm::starts_with(lowerText, "retaincase")) {
512 138237 m_properties.retaincase = true;
513 138237 notHandled = false;
514 }
515 8753982 break;
516 }
517
518 13133938 case 't': {
519
2/3
✓ Branch 1 taken 13133938 times.
✓ Branch 3 taken 13133938 times.
✗ Branch 4 not taken.
13133938 if (boost::algorithm::starts_with(lowerText, "type")) {
520
3/5
✓ Branch 1 taken 13133938 times.
✓ Branch 4 taken 13133938 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 13133938 times.
✗ Branch 9 not taken.
13133938 OS_ASSERT(boost::regex_search(text, matches, iddRegex::typeProperty()));
521
3/3
✓ Branch 1 taken 13133938 times.
✓ Branch 4 taken 13133938 times.
✓ Branch 7 taken 13133938 times.
13133938 std::string fieldType(matches[1].first, matches[1].second);
522
1/1
✓ Branch 1 taken 13133938 times.
13133938 openstudio::ascii_trim(fieldType);
523
1/1
✓ Branch 1 taken 13133938 times.
13133938 m_properties.type = IddFieldType(fieldType);
524 13133938 notHandled = false;
525 13133938 }
526 13133938 break;
527 }
528 4093365 case 'u': {
529
2/3
✓ Branch 1 taken 4093365 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4093365 times.
4093365 if (boost::algorithm::starts_with(lowerText, "unitsBasedOnField")) {
530 // unhandled
531 //I like how we spend time comparing to this, but then don't handle it!
532 ✗ notHandled = false;
533
2/3
✓ Branch 1 taken 4093365 times.
✓ Branch 3 taken 4093365 times.
✗ Branch 4 not taken.
4093365 } else if (boost::algorithm::starts_with(lowerText, "units")) {
534
3/5
✓ Branch 1 taken 4093365 times.
✓ Branch 4 taken 4093365 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4093365 times.
✗ Branch 9 not taken.
4093365 OS_ASSERT(boost::regex_search(text, matches, iddRegex::unitsProperty()));
535
3/3
✓ Branch 1 taken 4093365 times.
✓ Branch 4 taken 4093365 times.
✓ Branch 7 taken 4093365 times.
4093365 std::string units(matches[1].first, matches[1].second);
536
1/1
✓ Branch 1 taken 4093365 times.
4093365 openstudio::ascii_trim(units);
537
1/1
✓ Branch 1 taken 4093365 times.
4093365 m_properties.units = units;
538 4093365 notHandled = false;
539 4093365 }
540 4093365 break;
541 }
542 }
543
544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72939330 times.
72939330 if (notHandled) {
545 ✗ LOG_AND_THROW("Unknown field property text '" << text << "' detected in field '" << m_name << "'");
546 }
547 72939330 }
548
549 } // namespace detail
550
551 // CONSTRUCTORS
552
553 ✗ IddField::IddField() : m_impl(std::shared_ptr<detail::IddField_Impl>(new detail::IddField_Impl())) {}
554
555 // GETTERS
556
557 12980222 std::string IddField::name() const {
558 12980222 return m_impl->name();
559 }
560
561 3 std::string IddField::fieldId() const {
562 3 return m_impl->fieldId();
563 }
564
565 /// get properties
566 92806606 const IddFieldProperties& IddField::properties() const {
567 92806606 return m_impl->properties();
568 }
569
570 363 boost::optional<Unit> IddField::getUnits(bool returnIP) const {
571 363 return m_impl->getUnits(returnIP);
572 }
573
574 8 bool IddField::unitsBasedOnOtherField() const {
575 8 return m_impl->unitsBasedOnOtherField();
576 }
577
578 /// get key by name
579 18 OptionalIddKey IddField::getKey(const std::string& keyName) const {
580 18 return m_impl->getKey(keyName);
581 }
582
583 /// get all keys
584 1447334 IddKeyVector IddField::keys() const {
585 1447334 return m_impl->keys();
586 }
587
588 // SETTERS
589
590 /// set name
591 346412 void IddField::setName(const std::string& name) {
592 346412 m_impl->setName(name);
593 346412 }
594
595 4 void IddField::incrementFieldId(const boost::regex& fieldType) {
596 4 m_impl->incrementFieldId(fieldType);
597 4 }
598
599 // QUERIES
600
601 5752514 bool IddField::isNameField() const {
602 5752514 return m_impl->isNameField();
603 }
604
605 26002986 bool IddField::isObjectListField() const {
606 26002986 return m_impl->isObjectListField();
607 }
608
609 389 bool IddField::operator==(const IddField& other) const {
610 389 return (*m_impl == *(other.m_impl));
611 }
612
613 1 bool IddField::operator!=(const IddField& other) const {
614 1 return (*m_impl != *(other.m_impl));
615 }
616
617 // SERIALIZATION
618
619 13995333 OptionalIddField IddField::load(const std::string& name, const std::string& text, const std::string& objectName) {
620
1/1
✓ Branch 1 taken 13995333 times.
13995333 std::shared_ptr<detail::IddField_Impl> p = detail::IddField_Impl::load(name, text, objectName);
621
1/2
✓ Branch 1 taken 13995333 times.
✗ Branch 2 not taken.
13995333 if (p) {
622
2/2
✓ Branch 1 taken 13995333 times.
✓ Branch 4 taken 13995333 times.
13995333 return IddField(p);
623 } else {
624 ✗ return boost::none;
625 }
626 13995333 }
627
628 // PRIVATE
629
630 13995333 IddField::IddField(const std::shared_ptr<detail::IddField_Impl>& impl) : m_impl(impl) {}
631
632 // NON-MEMBER FUNCTIONS
633
634 737462 std::ostream& IddField::print(std::ostream& os, bool lastField) const {
635 737462 return m_impl->print(os, lastField);
636 }
637
638 ✗ std::ostream& operator<<(std::ostream& os, const IddField& iddField) {
639 ✗ return iddField.print(os, false);
640 }
641
642 3 bool referencesEqual(const IddField& field1, const IddField& field2) {
643 3 bool result = false;
644
645
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 StringVector refs1 = field1.properties().references;
646
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 StringVector refs2 = field2.properties().references;
647
648 3 unsigned n = refs2.size();
649
1/1
✓ Branch 1 taken 3 times.
3 BoolVector found(n, false);
650
651 // to be equal, must be same size
652
2/2
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 2 times.
3 if (refs1.size() == refs2.size()) {
653 1 unsigned start = 0; // start index for refs2
654
655 // look for refs1 in turn
656
2/2
✓ Branch 5 taken 1 time.
✓ Branch 6 taken 1 time.
2 for (const std::string& ref1 : refs1) {
657
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 for (unsigned i = start; i < n; ++i) {
658
2/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
1 if (!found[i]) {
659 // refs2[i] not found yet--see if there is a match
660
2/3
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
1 if (istringEqual(ref1, refs2[i])) {
661
1/1
✓ Branch 1 taken 1 time.
1 found[i] = true;
662
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (i == start) {
663 // a match and at where we started, so move start marker up
664 1 ++start;
665 }
666 1 break;
667 }
668 ✗ } else if (i == start) {
669 // refs[start] already matched, so move start marker up
670 ✗ ++start;
671 }
672 }
673 }
674 // tried to match each ref1 with a refs2. see if we were successful.
675
3/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
1 if (found == BoolVector(n, true)) {
676 1 result = true;
677 }
678 }
679
680 3 return result;
681 3 }
682
683 } // namespace openstudio
684