GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 58.1% 207 / 0 / 356
Functions: 45.2% 28 / 0 / 62
Branches: 59.0% 266 / 0 / 451

src/utilities/bcl/BCL.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 "BCL.hpp"
7
8 #include "LocalBCL.hpp"
9 #include "RemoteBCL.hpp"
10
11 #include "../core/Assert.hpp"
12 #include "../core/StringHelpers.hpp"
13 #include "../time/DateTime.hpp"
14
15 #include <pugixml.hpp>
16
17 namespace openstudio {
18
19 461 BCLFacet::BCLFacet(const pugi::xml_node& facetElement) {
20
1/1
✓ Branch 1 taken 461 times.
461 auto fieldElement = facetElement.child("field");
21
1/1
✓ Branch 1 taken 461 times.
461 auto labelElement = facetElement.child("label");
22
1/1
✓ Branch 1 taken 461 times.
461 auto itemElement = facetElement.child("item");
23
24
2/4
✓ Branch 1 taken 461 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 461 times.
✗ Branch 6 not taken.
461 OS_ASSERT(fieldElement);
25
2/4
✓ Branch 1 taken 461 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 461 times.
✗ Branch 6 not taken.
461 OS_ASSERT(labelElement);
26
2/4
✓ Branch 1 taken 461 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 461 times.
✗ Branch 6 not taken.
461 OS_ASSERT(itemElement);
27
28
3/3
✓ Branch 1 taken 461 times.
✓ Branch 4 taken 461 times.
✓ Branch 7 taken 461 times.
461 m_field = fieldElement.text().as_string();
29
30
3/3
✓ Branch 1 taken 461 times.
✓ Branch 4 taken 461 times.
✓ Branch 7 taken 461 times.
461 m_label = labelElement.text().as_string();
31
32
3/3
✓ Branch 1 taken 16679 times.
✓ Branch 3 taken 16218 times.
✓ Branch 4 taken 461 times.
16679 while (itemElement) {
33
4/4
✓ Branch 1 taken 16218 times.
✓ Branch 4 taken 16218 times.
✓ Branch 7 taken 16218 times.
✓ Branch 10 taken 16218 times.
16218 std::string value = itemElement.child("value").text().as_string();
34
3/3
✓ Branch 1 taken 16218 times.
✓ Branch 4 taken 16218 times.
✓ Branch 7 taken 16218 times.
16218 unsigned count = itemElement.child("count").text().as_uint();
35
2/2
✓ Branch 1 taken 16218 times.
✓ Branch 4 taken 16218 times.
16218 m_items.push_back(std::make_pair(value, count));
36
1/1
✓ Branch 1 taken 16218 times.
16218 itemElement = itemElement.next_sibling("item");
37 16218 }
38 461 }
39
40 ✗ std::string BCLFacet::field() const {
41 ✗ return m_field;
42 }
43
44 ✗ std::string BCLFacet::label() const {
45 ✗ return m_label;
46 }
47
48 168 std::vector<std::pair<std::string, unsigned>> BCLFacet::items() const {
49 168 return m_items;
50 }
51
52 193 BCLTaxonomyTerm::BCLTaxonomyTerm(const pugi::xml_node& taxonomyElement) {
53
1/1
✓ Branch 1 taken 193 times.
193 auto nameElement = taxonomyElement.child("name");
54
1/1
✓ Branch 1 taken 193 times.
193 auto tidElement = taxonomyElement.child("tid");
55
1/1
✓ Branch 1 taken 193 times.
193 auto numResultsElement = taxonomyElement.child("count");
56
57
2/4
✓ Branch 1 taken 193 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 193 times.
✗ Branch 6 not taken.
193 OS_ASSERT(nameElement);
58
2/4
✓ Branch 1 taken 193 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 193 times.
✗ Branch 6 not taken.
193 OS_ASSERT(tidElement);
59
2/4
✓ Branch 1 taken 193 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 193 times.
✗ Branch 6 not taken.
193 OS_ASSERT(numResultsElement);
60
61
3/3
✓ Branch 1 taken 193 times.
✓ Branch 4 taken 193 times.
✓ Branch 7 taken 193 times.
193 m_name = nameElement.text().as_string();
62
63
2/2
✓ Branch 1 taken 193 times.
✓ Branch 4 taken 193 times.
193 m_tid = tidElement.text().as_uint();
64
65
2/2
✓ Branch 1 taken 193 times.
✓ Branch 4 taken 193 times.
193 m_numResults = numResultsElement.text().as_uint();
66 193 }
67
68 ✗ std::string BCLTaxonomyTerm::name() const {
69 ✗ return m_name;
70 }
71
72 ✗ unsigned BCLTaxonomyTerm::tid() const {
73 ✗ return m_tid;
74 }
75
76 ✗ unsigned BCLTaxonomyTerm::numResults() const {
77 ✗ return m_numResults;
78 }
79
80 20 BCLMetaSearchResult::BCLMetaSearchResult(const pugi::xml_node& resultElement) {
81
1/1
✓ Branch 1 taken 20 times.
20 auto numResultsElement = resultElement.child("result_count");
82
83
2/4
✓ Branch 1 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 6 not taken.
20 OS_ASSERT(numResultsElement);
84
85
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 m_numResults = numResultsElement.text().as_uint();
86
87
1/1
✓ Branch 1 taken 20 times.
20 auto facetElement = resultElement.child("facet");
88
3/3
✓ Branch 1 taken 481 times.
✓ Branch 3 taken 461 times.
✓ Branch 4 taken 20 times.
481 while (facetElement) {
89
1/1
✓ Branch 1 taken 461 times.
461 auto fieldElement = facetElement.child("field");
90
2/3
✓ Branch 1 taken 461 times.
✓ Branch 3 taken 461 times.
✗ Branch 4 not taken.
461 if (fieldElement) {
91
2/2
✓ Branch 1 taken 461 times.
✓ Branch 4 taken 461 times.
461 m_facets.push_back(BCLFacet(facetElement));
92 }
93
1/1
✓ Branch 1 taken 461 times.
461 facetElement = facetElement.next_sibling("facet");
94 }
95
96
1/1
✓ Branch 1 taken 20 times.
20 auto taxonomyTermElement = resultElement.child("taxonomy_term");
97
3/3
✓ Branch 1 taken 213 times.
✓ Branch 3 taken 193 times.
✓ Branch 4 taken 20 times.
213 while (taxonomyTermElement) {
98
1/1
✓ Branch 1 taken 193 times.
193 auto tidElement = taxonomyTermElement.child("tid");
99
2/3
✓ Branch 1 taken 193 times.
✓ Branch 3 taken 193 times.
✗ Branch 4 not taken.
193 if (tidElement) {
100
2/2
✓ Branch 1 taken 193 times.
✓ Branch 4 taken 193 times.
193 m_taxonomyTerms.push_back(BCLTaxonomyTerm(taxonomyTermElement));
101 }
102
1/1
✓ Branch 1 taken 193 times.
193 taxonomyTermElement = taxonomyTermElement.next_sibling("taxonomy_term");
103 }
104 20 }
105
106 25 unsigned BCLMetaSearchResult::numResults() const {
107 25 return m_numResults;
108 }
109
110 10 std::vector<BCLFacet> BCLMetaSearchResult::facets() const {
111 10 return m_facets;
112 }
113
114 5 std::vector<BCLTaxonomyTerm> BCLMetaSearchResult::taxonomyTerms() const {
115 5 return m_taxonomyTerms;
116 }
117
118 558 BCLFile::BCLFile(const pugi::xml_node& fileElement) {
119
1/1
✓ Branch 1 taken 558 times.
558 auto version = fileElement.child("version");
120
1/1
✓ Branch 1 taken 558 times.
558 auto softwareProgramElement = version.child("software_program");
121
1/1
✓ Branch 1 taken 558 times.
558 auto identifierElement = version.child("identifier");
122
1/1
✓ Branch 1 taken 558 times.
558 auto minCompatibleElement = version.child("min_compatible");
123
1/1
✓ Branch 1 taken 558 times.
558 auto maxCompatibleElement = version.child("max_compatible");
124
1/1
✓ Branch 1 taken 558 times.
558 auto filenameElement = fileElement.child("filename");
125
1/1
✓ Branch 1 taken 558 times.
558 auto urlElement = fileElement.child("url");
126
1/1
✓ Branch 1 taken 558 times.
558 auto filetypeElement = fileElement.child("filetype");
127
1/1
✓ Branch 1 taken 558 times.
558 auto usageTypeElement = fileElement.child("usage_type");
128
1/1
✓ Branch 1 taken 558 times.
558 auto checksumElement = fileElement.child("checksum");
129
130
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_softwareProgram = softwareProgramElement.text().as_string();
131
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_identifier = identifierElement.text().as_string();
132
133 // Avoids gettings lots of 'Could not parse '' as a version string'
134 1116 auto parseVersionIfExistsAndNotEmpty = [](const pugi::xml_node& vElement) -> boost::optional<VersionString> {
135
3/3
✓ Branch 1 taken 1116 times.
✓ Branch 3 taken 710 times.
✓ Branch 4 taken 406 times.
1116 if (!vElement) {
136 710 return boost::none;
137 }
138
3/3
✓ Branch 1 taken 406 times.
✓ Branch 4 taken 406 times.
✓ Branch 7 taken 406 times.
406 const std::string vstr = vElement.text().as_string();
139
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 406 times.
406 if (vstr.empty()) {
140 ✗ return boost::none;
141 }
142 406 boost::optional<VersionString> result;
143
144 try {
145
2/2
✓ Branch 1 taken 406 times.
✓ Branch 4 taken 406 times.
406 result = VersionString(vstr);
146 ✗ } catch (const std::exception&) {
147 ✗ }
148 406 return result;
149 406 };
150
151
3/3
✓ Branch 1 taken 558 times.
✓ Branch 3 taken 557 times.
✓ Branch 4 taken 1 time.
558 if (!minCompatibleElement) {
152
1/1
✓ Branch 1 taken 557 times.
557 m_minCompatibleVersion = parseVersionIfExistsAndNotEmpty(identifierElement);
153 } else {
154
1/1
✓ Branch 1 taken 1 time.
1 m_minCompatibleVersion = parseVersionIfExistsAndNotEmpty(minCompatibleElement);
155 }
156
157
1/1
✓ Branch 1 taken 558 times.
558 m_maxCompatibleVersion = parseVersionIfExistsAndNotEmpty(maxCompatibleElement);
158
159
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_filename = filenameElement.text().as_string();
160
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_url = urlElement.text().as_string();
161
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_filetype = filetypeElement.text().as_string();
162
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_usageType = usageTypeElement.text().as_string();
163
3/3
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 7 taken 558 times.
558 m_checksum = checksumElement.text().as_string();
164 558 }
165
166 ✗ std::string BCLFile::softwareProgram() const {
167 ✗ return m_softwareProgram;
168 }
169
170 ✗ std::string BCLFile::identifier() const {
171 ✗ return m_identifier;
172 }
173
174 ✗ boost::optional<VersionString> BCLFile::minCompatibleVersion() const {
175 ✗ return m_minCompatibleVersion;
176 }
177
178 ✗ boost::optional<VersionString> BCLFile::maxCompatibleVersion() const {
179 ✗ return m_maxCompatibleVersion;
180 }
181
182 ✗ std::string BCLFile::filename() const {
183 ✗ return m_filename;
184 }
185
186 ✗ std::string BCLFile::url() const {
187 ✗ return m_url;
188 }
189
190 ✗ std::string BCLFile::filetype() const {
191 ✗ return m_filetype;
192 }
193
194 ✗ std::string BCLFile::usageType() const {
195 ✗ return m_usageType;
196 }
197
198 ✗ std::string BCLFile::checksum() const {
199 ✗ return m_checksum;
200 }
201
202 ✗ BCLProvenance::BCLProvenance(const pugi::xml_node& provenanceElement) {
203 ✗ auto authorElement = provenanceElement.child("author");
204 ✗ auto datetimeElement = provenanceElement.child("datetime");
205 ✗ auto commentElement = provenanceElement.child("comment");
206
207 ✗ m_author = authorElement.text().as_string();
208 ✗ m_datetime = datetimeElement.text().as_string();
209 ✗ m_comment = commentElement.text().as_string();
210 ✗ }
211
212 ✗ std::string BCLProvenance::author() const {
213 ✗ return m_author;
214 }
215
216 ✗ std::string BCLProvenance::datetime() const {
217 ✗ return m_datetime;
218 }
219
220 ✗ std::string BCLProvenance::comment() const {
221 ✗ return m_comment;
222 }
223
224 ✗ BCLCost::BCLCost(const pugi::xml_node& costElement) {
225 ✗ auto instanceNameElement = costElement.child("instance_name");
226 ✗ auto costTypeElement = costElement.child("cost_type");
227 ✗ auto categoryElement = costElement.child("category");
228 ✗ auto valueElement = costElement.child("value");
229 ✗ auto unitsElement = costElement.child("units");
230 ✗ auto intervalElement = costElement.child("interval");
231 ✗ auto intervalUnitsElement = costElement.child("interval_units");
232 ✗ auto yearElement = costElement.child("year");
233 ✗ auto locationElement = costElement.child("location");
234 ✗ auto currencyElement = costElement.child("currency");
235 ✗ auto sourceElement = costElement.child("source");
236 ✗ auto referenceComponentNameElement = costElement.child("reference_component_name");
237 ✗ auto referenceComponentIdElement = costElement.child("reference_component_id");
238
239 ✗ m_instanceName = instanceNameElement.text().as_string();
240 ✗ m_costType = costTypeElement.text().as_string();
241 ✗ m_category = categoryElement.text().as_string();
242 ✗ m_value = valueElement.text().as_double();
243
244 ✗ m_units = unitsElement.text().as_string();
245 ✗ m_interval = intervalElement.text().as_string();
246 ✗ m_intervalUnits = intervalUnitsElement.text().as_string();
247
248 ✗ m_year = yearElement.text().as_uint(0);
249
250 ✗ m_location = locationElement.text().as_string();
251 ✗ m_currency = currencyElement.text().as_string();
252 ✗ m_source = sourceElement.text().as_string();
253 ✗ m_referenceComponentName = referenceComponentNameElement.text().as_string();
254 ✗ m_referenceComponentId = referenceComponentIdElement.text().as_string();
255 ✗ }
256
257 ✗ std::string BCLCost::instanceName() const {
258 ✗ return m_instanceName;
259 }
260
261 ✗ std::string BCLCost::costType() const {
262 ✗ return m_costType;
263 }
264
265 ✗ std::string BCLCost::category() const {
266 ✗ return m_category;
267 }
268
269 ✗ double BCLCost::value() const {
270 ✗ return m_value;
271 }
272
273 ✗ std::string BCLCost::units() const {
274 ✗ return m_units;
275 }
276
277 ✗ std::string BCLCost::interval() const {
278 ✗ return m_interval;
279 }
280
281 ✗ std::string BCLCost::intervalUnits() const {
282 ✗ return m_intervalUnits;
283 }
284
285 ✗ unsigned BCLCost::year() const {
286 ✗ return m_year;
287 }
288
289 ✗ std::string BCLCost::location() const {
290 ✗ return m_location;
291 }
292
293 ✗ std::string BCLCost::currency() const {
294 ✗ return m_currency;
295 }
296
297 ✗ std::string BCLCost::source() const {
298 ✗ return m_source;
299 }
300
301 ✗ std::string BCLCost::referenceComponentName() const {
302 ✗ return m_referenceComponentName;
303 }
304
305 ✗ std::string BCLCost::referenceComponentId() const {
306 ✗ return m_referenceComponentId;
307 }
308
309
2/2
✓ Branch 7 taken 134 times.
✓ Branch 10 taken 134 times.
402 BCLSearchResult::BCLSearchResult(const pugi::xml_node& componentElement) : m_componentType{componentElement.name()} {
310
311
1/1
✓ Branch 1 taken 134 times.
134 auto uidElement = componentElement.child("uuid");
312
1/1
✓ Branch 1 taken 134 times.
134 auto versionIdElement = componentElement.child("vuuid");
313
1/1
✓ Branch 1 taken 134 times.
134 auto nameElement = componentElement.child("name");
314
1/1
✓ Branch 1 taken 134 times.
134 auto descriptionElement = componentElement.child("description");
315
1/1
✓ Branch 1 taken 134 times.
134 auto modelerDescriptionElement = componentElement.child("modeler_description");
316
1/1
✓ Branch 1 taken 134 times.
134 auto fidelityLevelElement = componentElement.child("fidelity_level");
317
1/1
✓ Branch 1 taken 134 times.
134 auto provenancesElement = componentElement.child("provenances");
318
1/1
✓ Branch 1 taken 134 times.
134 auto tagsElement = componentElement.child("tags");
319
1/1
✓ Branch 1 taken 134 times.
134 auto attributesElement = componentElement.child("attributes");
320
1/1
✓ Branch 1 taken 134 times.
134 auto filesElement = componentElement.child("files");
321
1/1
✓ Branch 1 taken 134 times.
134 auto costsElement = componentElement.child("costs");
322
323
2/4
✓ Branch 1 taken 134 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 134 times.
✗ Branch 6 not taken.
134 OS_ASSERT(nameElement);
324
2/4
✓ Branch 1 taken 134 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 134 times.
✗ Branch 6 not taken.
134 OS_ASSERT(uidElement);
325
2/4
✓ Branch 1 taken 134 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 134 times.
✗ Branch 6 not taken.
134 OS_ASSERT(versionIdElement);
326
327
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 std::string name = nameElement.text().as_string();
328 134 std::replace(name.begin(), name.end(), '_', ' ');
329 134 auto index = name.find(" ", 0);
330
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 134 times.
136 while (index != std::string::npos) {
331
1/1
✓ Branch 1 taken 2 times.
2 name.replace(index, 2, " ");
332 2 ++index;
333 2 index = name.find(" ", index);
334 }
335 //QString name = nameElement.firstChild().nodeValue().replace('_', ' ');
336 //while (name.indexOf(" ") != -1) {
337 // name = name.replace(" ", " ");
338 //}
339 134 name[0] = std::toupper(name[0]); // Why is this needed? Won't this be an issue for unicode, etc.?
340
1/1
✓ Branch 1 taken 134 times.
134 m_name = name;
341
342
2/3
✓ Branch 1 taken 134 times.
✓ Branch 3 taken 134 times.
✗ Branch 4 not taken.
134 if (uidElement) {
343
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 std::string txt = uidElement.text().as_string();
344
1/2
✓ Branch 1 taken 134 times.
✗ Branch 2 not taken.
134 if (txt.length() == 36) {
345
1/1
✓ Branch 1 taken 134 times.
134 m_uid = txt;
346 }
347 134 }
348
349
2/3
✓ Branch 1 taken 134 times.
✓ Branch 3 taken 134 times.
✗ Branch 4 not taken.
134 if (versionIdElement) {
350
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 std::string txt = versionIdElement.text().as_string();
351
1/2
✓ Branch 1 taken 134 times.
✗ Branch 2 not taken.
134 if (txt.length() == 36) {
352
1/1
✓ Branch 1 taken 134 times.
134 m_versionId = txt;
353 }
354 134 }
355
356
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 m_description = descriptionElement.text().as_string();
357
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 m_modelerDescription = modelerDescriptionElement.text().as_string();
358
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 m_fidelityLevel = fidelityLevelElement.text().as_string();
359
360
1/1
✓ Branch 1 taken 134 times.
134 auto provenanceElement = provenancesElement.child("provenance");
361
2/3
✓ Branch 1 taken 134 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 134 times.
134 while (provenanceElement) {
362 ✗ if (provenanceElement.first_child() != nullptr) {
363 ✗ m_provenances.emplace_back(provenanceElement);
364 } else {
365 ✗ break;
366 }
367 ✗ provenanceElement = provenanceElement.next_sibling("provenance");
368 }
369
1/1
✓ Branch 1 taken 134 times.
134 auto provenanceRequiredElement = provenancesElement.child("provenance_required");
370
2/3
✓ Branch 1 taken 134 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 134 times.
134 if (provenanceRequiredElement) {
371 ✗ std::string required = provenanceRequiredElement.text().as_string();
372 ✗ m_provenanceRequired = (required == "true");
373 ✗ }
374
375
1/1
✓ Branch 1 taken 134 times.
134 auto tagElement = tagsElement.child("tag");
376
3/3
✓ Branch 1 taken 268 times.
✓ Branch 3 taken 134 times.
✓ Branch 4 taken 134 times.
268 while (tagElement) {
377
4/4
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
✓ Branch 10 taken 134 times.
268 m_tags.push_back(tagElement.text().as_string());
378
1/1
✓ Branch 1 taken 134 times.
134 tagElement = tagElement.next_sibling("tag");
379 }
380
381
1/1
✓ Branch 1 taken 134 times.
134 auto attributeElement = attributesElement.child("attribute");
382
3/3
✓ Branch 1 taken 1303 times.
✓ Branch 3 taken 1169 times.
✓ Branch 4 taken 134 times.
1303 while (attributeElement) {
383
3/4
✓ Branch 1 taken 1169 times.
✓ Branch 4 taken 1169 times.
✓ Branch 6 taken 1169 times.
✗ Branch 7 not taken.
1169 if (attributeElement.first_child() != nullptr) {
384
4/4
✓ Branch 1 taken 1169 times.
✓ Branch 4 taken 1169 times.
✓ Branch 7 taken 1169 times.
✓ Branch 10 taken 1169 times.
1169 std::string att_name = attributeElement.child("name").text().as_string();
385
4/4
✓ Branch 1 taken 1169 times.
✓ Branch 4 taken 1169 times.
✓ Branch 7 taken 1169 times.
✓ Branch 10 taken 1169 times.
1169 std::string value = attributeElement.child("value").text().as_string();
386
4/4
✓ Branch 1 taken 1169 times.
✓ Branch 4 taken 1169 times.
✓ Branch 7 taken 1169 times.
✓ Branch 10 taken 1169 times.
1169 std::string datatype = attributeElement.child("datatype").text().as_string();
387
388 // Units are optional
389
4/4
✓ Branch 1 taken 1169 times.
✓ Branch 4 taken 1169 times.
✓ Branch 7 taken 1169 times.
✓ Branch 10 taken 1169 times.
1169 std::string units = attributeElement.child("units").text().as_string();
390
391
1/1
✓ Branch 1 taken 1169 times.
1169 const auto doubleValue = openstudio::string_conversions::to_no_throw<double>(value);
392
1/1
✓ Branch 1 taken 1169 times.
1169 const auto intValue = openstudio::string_conversions::to_no_throw<int>(value);
393
394
6/7
✓ Branch 1 taken 1169 times.
✓ Branch 3 taken 323 times.
✓ Branch 4 taken 846 times.
✓ Branch 5 taken 323 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 323 times.
✓ Branch 8 taken 846 times.
1492 if (datatype == "float" && doubleValue) {
395
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 if (units.empty()) {
396
2/2
✓ Branch 1 taken 323 times.
✓ Branch 4 taken 323 times.
323 Attribute attr(att_name, *doubleValue);
397
1/1
✓ Branch 1 taken 323 times.
323 m_attributes.push_back(attr);
398 323 } else {
399 ✗ Attribute attr(att_name, *doubleValue, units);
400 ✗ m_attributes.push_back(attr);
401 ✗ }
402
3/7
✓ Branch 1 taken 846 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 846 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 846 times.
846 } else if (datatype == "int" && intValue) {
403 ✗ if (units.empty()) {
404 ✗ Attribute attr(att_name, *intValue);
405 ✗ m_attributes.push_back(attr);
406 ✗ } else {
407 ✗ Attribute attr(att_name, *intValue, units);
408 ✗ m_attributes.push_back(attr);
409 ✗ }
410 }
411 // Assume string
412 else {
413
1/2
✓ Branch 1 taken 846 times.
✗ Branch 2 not taken.
846 if (units.empty()) {
414
1/1
✓ Branch 1 taken 846 times.
846 Attribute attr(att_name, value);
415
1/1
✓ Branch 1 taken 846 times.
846 m_attributes.push_back(attr);
416 846 } else {
417 ✗ Attribute attr(att_name, value, units);
418 ✗ m_attributes.push_back(attr);
419 ✗ }
420 //LOG(Error, "Error: Unrecognized attribute datatype \"" << datatype << "\"");
421 }
422 1169 } else {
423 ✗ break;
424 }
425
1/1
✓ Branch 1 taken 1169 times.
1169 attributeElement = attributeElement.next_sibling("attribute");
426 }
427
428
1/1
✓ Branch 1 taken 134 times.
134 auto fileElement = filesElement.child("file");
429
3/3
✓ Branch 1 taken 692 times.
✓ Branch 3 taken 558 times.
✓ Branch 4 taken 134 times.
692 while (fileElement) {
430
3/4
✓ Branch 1 taken 558 times.
✓ Branch 4 taken 558 times.
✓ Branch 6 taken 558 times.
✗ Branch 7 not taken.
558 if (fileElement.first_child() != nullptr) {
431
1/1
✓ Branch 1 taken 558 times.
558 m_files.emplace_back(fileElement); // BCLFile
432 } else {
433 ✗ break;
434 }
435
1/1
✓ Branch 1 taken 558 times.
558 fileElement = fileElement.next_sibling("file");
436 }
437
438
3/3
✓ Branch 1 taken 134 times.
✓ Branch 3 taken 133 times.
✓ Branch 4 taken 1 time.
134 if (m_componentType == "component") {
439
1/1
✓ Branch 1 taken 133 times.
133 auto costElement = costsElement.child("cost");
440
2/3
✓ Branch 1 taken 133 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 133 times.
133 while (costElement) {
441 ✗ if (costElement.first_child() != nullptr) {
442 ✗ m_costs.emplace_back(costElement); // BCLCost
443 } else {
444 ✗ break;
445 }
446 ✗ costElement = costElement.next_sibling("cost");
447 }
448 }
449
450
3/4
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 6 taken 134 times.
✗ Branch 7 not taken.
134 if (auto orgElement = componentElement.child("org")) {
451
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 m_org = orgElement.text().as_string();
452 }
453
3/4
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 6 taken 134 times.
✗ Branch 7 not taken.
134 if (auto repoElement = componentElement.child("repo")) {
454
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 m_repo = repoElement.text().as_string();
455 }
456
3/4
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 6 taken 134 times.
✗ Branch 7 not taken.
134 if (auto release_tagElement = componentElement.child("release_tag")) {
457
3/3
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 7 taken 134 times.
134 m_releaseTag = release_tagElement.text().as_string();
458 }
459
4/4
✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 133 times.
134 if (auto versionModifiedElement = componentElement.child("version_modified")) {
460
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
1 const std::string versionModified = versionModifiedElement.text().as_string();
461
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 if (!versionModified.empty()) {
462 // fromXsdDateTime forwards to fromISO8601 and handles both formats
463
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
2 if (auto dt_ = openstudio::DateTime::fromXsdDateTime(versionModified)) {
464
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 m_versionModified = *dt_;
465 1 }
466 }
467 1 }
468 134 }
469
470 9 std::string BCLSearchResult::uid() const {
471 9 return m_uid;
472 }
473
474 4 std::string BCLSearchResult::versionId() const {
475 4 return m_versionId;
476 }
477
478 2 std::string BCLSearchResult::name() const {
479 2 return m_name;
480 }
481
482 1 std::string BCLSearchResult::description() const {
483 1 return m_description;
484 }
485
486 1 std::string BCLSearchResult::modelerDescription() const {
487 1 return m_modelerDescription;
488 }
489
490 1 std::string BCLSearchResult::fidelityLevel() const {
491 1 return m_fidelityLevel;
492 }
493
494 1 std::string BCLSearchResult::componentType() const {
495 1 return m_componentType;
496 }
497
498 1 bool BCLSearchResult::provenanceRequired() const {
499 1 return m_provenanceRequired;
500 }
501
502 1 std::vector<BCLProvenance> BCLSearchResult::provenances() const {
503 1 return m_provenances;
504 }
505
506 1 std::vector<std::string> BCLSearchResult::tags() const {
507 1 return m_tags;
508 }
509
510 1 std::vector<Attribute> BCLSearchResult::attributes() const {
511 1 return m_attributes;
512 }
513
514 1 std::vector<BCLFile> BCLSearchResult::files() const {
515 1 return m_files;
516 }
517
518 1 std::vector<BCLCost> BCLSearchResult::costs() const {
519 1 return m_costs;
520 }
521
522 2 std::string BCLSearchResult::org() const {
523 2 return m_org;
524 }
525 2 std::string BCLSearchResult::repo() const {
526 2 return m_repo;
527 }
528 1 std::string BCLSearchResult::releaseTag() const {
529 1 return m_releaseTag;
530 }
531 1 boost::optional<openstudio::DateTime> BCLSearchResult::versionModified() const {
532 1 return m_versionModified;
533 }
534
535 32 BCL::BCL() = default;
536
537 ✗ boost::optional<BCLComponent> getComponent(const std::string& uid, const std::string& versionId) {
538 ✗ OptionalBCLComponent localComponent = LocalBCL::instance().getComponent(uid, versionId);
539
540 // if versionId specified, done if localComponent exists
541 ✗ if (!versionId.empty() && localComponent) {
542 ✗ return localComponent;
543 }
544
545 // versionId.empty() or !localComponent
546 ✗ RemoteBCL remoteBCL;
547 ✗ OptionalBCLComponent remoteComponent = remoteBCL.getComponent(uid, versionId);
548 ✗ if (remoteComponent) {
549 // RemoteBCL class handles updating the LocalBCL
550 ✗ localComponent = LocalBCL::instance().getComponent(uid, versionId);
551 ✗ OS_ASSERT(localComponent);
552 ✗ OS_ASSERT(localComponent.get() == remoteComponent.get());
553 }
554
555 ✗ return localComponent;
556 ✗ }
557
558 ✗ boost::optional<BCLMeasure> getMeasure(const std::string& uid, const std::string& versionId) {
559 ✗ OptionalBCLMeasure localMeasure = LocalBCL::instance().getMeasure(uid, versionId);
560
561 // if versionId specified, done if localMeasure exists
562 ✗ if (!versionId.empty() && localMeasure) {
563 ✗ return localMeasure;
564 }
565
566 // versionId.empty() or !localMeasure
567 ✗ RemoteBCL remoteBCL;
568 ✗ OptionalBCLMeasure remoteMeasure = remoteBCL.getMeasure(uid, versionId);
569 ✗ if (remoteMeasure) {
570 // RemoteBCL class handles updating the LocalBCL
571 ✗ localMeasure = LocalBCL::instance().getMeasure(uid, versionId);
572 ✗ OS_ASSERT(localMeasure);
573 ✗ OS_ASSERT(localMeasure.get() == remoteMeasure.get());
574 }
575
576 ✗ return localMeasure;
577 ✗ }
578
579 } // namespace openstudio
580