GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 89.6% 420 / 0 / 469
Functions: 98.7% 75 / 0 / 76
Branches: 57.8% 416 / 0 / 720

src/utilities/idd/IddObject.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 "IddObject.hpp"
7 #include "IddObject_Impl.hpp"
8
9 #include "ExtensibleIndex.hpp"
10 #include "IddRegex.hpp"
11 #include <utilities/idd/IddFactory.hxx>
12 #include <utilities/idd/IddEnums.hxx>
13 #include "IddKey.hpp"
14 #include "CommentRegex.hpp"
15
16 #include "../core/Assert.hpp"
17 #include "../core/ASCIIStrings.hpp"
18
19 #include <boost/lexical_cast.hpp>
20
21 using std::string;
22 using std::vector;
23 using boost::regex;
24 using boost::smatch;
25 using boost::regex_replace;
26 using boost::replace_all;
27
28 namespace openstudio {
29
30 namespace detail {
31
32 // CONSTRUCTORS
33
34 /// default constructor for serialization
35
3/3
✓ Branch 1 taken 226425 times.
✓ Branch 5 taken 226425 times.
✓ Branch 8 taken 226425 times.
679275 IddObject_Impl::IddObject_Impl() : m_name("Catchall"), m_type(IddObjectType::Catchall) {
36 226425 m_properties.extensible = true;
37 226425 m_properties.numExtensible = 1;
38 226425 m_properties.hasURL = false;
39
3/3
✓ Branch 1 taken 226425 times.
✓ Branch 4 taken 226425 times.
✓ Branch 7 taken 226425 times.
905700 OptionalIddField oField = IddField::load("Object Type", "A1, \\field Object Type \n \\type alpha", m_name);
40
2/2
✓ Branch 1 taken 226425 times.
✓ Branch 4 taken 226425 times.
226425 m_fields.push_back(*oField);
41
3/3
✓ Branch 1 taken 226425 times.
✓ Branch 4 taken 226425 times.
✓ Branch 7 taken 226425 times.
905700 oField = IddField::load("Generic Data Field", "A2; \\field Generic Data Field \n \\type alpha \n \\begin-extensible", m_name);
42
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 226425 times.
✗ Branch 4 not taken.
226425 OS_ASSERT(oField);
43
2/2
✓ Branch 1 taken 226425 times.
✓ Branch 4 taken 226425 times.
226425 m_extensibleFields.push_back(*oField);
44 226425 }
45
46 // GETTERS
47
48 136708528 std::string IddObject_Impl::name() const {
49 136708528 return m_name;
50 }
51
52 51865595 IddObjectType IddObject_Impl::type() const {
53 51865595 return m_type;
54 }
55
56 61131 std::string IddObject_Impl::group() const {
57 61131 return m_group;
58 }
59
60 39492495 const IddObjectProperties& IddObject_Impl::properties() const {
61 39492495 return m_properties;
62 }
63
64 202224 const IddFieldVector& IddObject_Impl::nonextensibleFields() const {
65 202224 return m_fields;
66 }
67
68 135420 const IddFieldVector& IddObject_Impl::extensibleGroup() const {
69 135420 return m_extensibleFields;
70 }
71
72 99475498 boost::optional<IddField> IddObject_Impl::getField(unsigned index) const {
73 99475498 OptionalIddField field;
74
75 // is index in the regular fields
76
2/2
✓ Branch 1 taken 60701932 times.
✓ Branch 2 taken 38773566 times.
99475498 if (index < m_fields.size()) {
77
1/1
✓ Branch 2 taken 60701932 times.
60701932 field = m_fields[index];
78
2/2
✓ Branch 1 taken 38773552 times.
✓ Branch 2 taken 14 times.
38773566 } else if (!m_extensibleFields.empty()) {
79 // if not subtract out fields size and mod by number of extensible fields
80 38773552 index = index - m_fields.size();
81 38773552 index = index % m_extensibleFields.size();
82
1/1
✓ Branch 2 taken 38773552 times.
38773552 field = m_extensibleFields[index];
83 }
84
85 99475498 return field;
86 ✗ }
87
88 14 boost::optional<IddField> IddObject_Impl::getField(const std::string& fieldName) const {
89 14 OptionalIddField result;
90
91 // look in fields
92
2/2
✓ Branch 5 taken 102 times.
✓ Branch 6 taken 8 times.
110 for (const IddField& field : m_fields) {
93
4/4
✓ Branch 2 taken 102 times.
✓ Branch 5 taken 102 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 96 times.
102 if (boost::iequals(field.name(), fieldName)) {
94
1/1
✓ Branch 1 taken 6 times.
6 result = field;
95 6 break;
96 }
97 }
98 // look in extensible fields
99
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 6 times.
14 if (!result) {
100
2/2
✓ Branch 5 taken 20 times.
✓ Branch 6 taken 4 times.
24 for (const IddField& field : m_extensibleFields) {
101
4/4
✓ Branch 2 taken 20 times.
✓ Branch 5 taken 20 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 16 times.
20 if (boost::iequals(field.name(), fieldName)) {
102
1/1
✓ Branch 1 taken 4 times.
4 result = field;
103 4 break;
104 }
105 }
106 }
107
108 14 return result;
109 ✗ }
110
111 9530 boost::optional<int> IddObject_Impl::getFieldIndex(const std::string& fieldName) const {
112 9530 OptionalInt result;
113 9530 int index = 0;
114
115 // look in fields
116
1/2
✓ Branch 4 taken 17035 times.
✗ Branch 5 not taken.
17035 for (const IddField& field : m_fields) {
117
4/4
✓ Branch 2 taken 17035 times.
✓ Branch 5 taken 17035 times.
✓ Branch 9 taken 9530 times.
✓ Branch 10 taken 7505 times.
17035 if (boost::iequals(field.name(), fieldName)) {
118
1/1
✓ Branch 1 taken 9530 times.
9530 result = index;
119 9530 break;
120 }
121 7505 ++index;
122 }
123
124 // look in extensible fields
125
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9530 times.
9530 if (!result) {
126 ✗ for (const IddField& field : m_extensibleFields) {
127 ✗ if (boost::iequals(field.name(), fieldName)) {
128 ✗ result = index;
129 ✗ break;
130 }
131 ✗ ++index;
132 }
133 }
134
135 9530 return result;
136 }
137
138 // SETTERS
139
140 1 void IddObject_Impl::insertHandleField() {
141
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 if (!hasHandleField()) {
142
1/1
✓ Branch 1 taken 1 time.
1 std::stringstream fieldText;
143
5/5
✓ 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.
1 fieldText << " A1, \\field Handle" << '\n' << " \\type handle" << '\n' << " \\required-field";
144
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
3 IddField handleField = IddField::load("Handle", fieldText.str(), m_name).get();
145
1/1
✓ Branch 3 taken 1 time.
1 auto it = m_fields.insert(m_fields.begin(), handleField);
146 1 ++it;
147
2/2
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 time.
5 for (auto itEnd = m_fields.end(); it != itEnd; ++it) {
148
2/2
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
4 it->incrementFieldId(); // by default, applies only to 'A'-type fields
149 }
150 1 it = m_extensibleFields.begin();
151
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
1 for (auto itEnd = m_extensibleFields.end(); it != itEnd; ++it) {
152 ✗ it->incrementFieldId(); // by default, applies only to 'A'-type fields
153 }
154 1 ++m_properties.minFields;
155
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
2 if (m_properties.maxFields) {
156 ✗ unsigned newMaxFields = m_properties.maxFields.get() + 1;
157 ✗ m_properties.maxFields = newMaxFields;
158 }
159 1 }
160 1 }
161
162 // QUERIES
163
164 9336004 unsigned IddObject_Impl::numFields() const {
165 9336004 return m_fields.size();
166 }
167
168 1679001 unsigned IddObject_Impl::numFieldsInDefaultObject() const {
169 1679001 unsigned result = m_properties.minFields;
170
171 // check for non-extensible required fields
172 1679001 unsigned index = result;
173 1679001 unsigned n = numFields();
174
2/2
✓ Branch 0 taken 6090738 times.
✓ Branch 1 taken 1679001 times.
7769739 while (index < n) {
175
2/2
✓ Branch 2 taken 1971642 times.
✓ Branch 3 taken 4119096 times.
6090738 if (m_fields[index].properties().required) {
176 1971642 result = index + 1;
177 }
178 6090738 ++index;
179 }
180
181 // do not pre-create extensible groups, so user can directly call
182 // .pushExtensibleGroup, without preceding it with a .clearExtensibleGroups.
183
2/2
✓ Branch 0 taken 622391 times.
✓ Branch 1 taken 1056610 times.
1679001 if (result > n) {
184 622391 result = n;
185 }
186
187 1679001 return result;
188 }
189
190 1272923 bool IddObject_Impl::isVersionObject() const {
191
15/17
✓ Branch 1 taken 1272923 times.
✓ Branch 4 taken 1272923 times.
✓ Branch 7 taken 1269486 times.
✓ Branch 8 taken 3437 times.
✓ Branch 10 taken 1269486 times.
✓ Branch 13 taken 1269486 times.
✓ Branch 16 taken 1263340 times.
✓ Branch 17 taken 6146 times.
✓ Branch 19 taken 1263340 times.
✓ Branch 22 taken 1263340 times.
✓ Branch 25 taken 1263340 times.
✓ Branch 27 taken 11449 times.
✓ Branch 28 taken 1251891 times.
✓ Branch 29 taken 1263340 times.
✓ Branch 30 taken 9583 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
1272923 return (type() == IddObjectType::Version) || (type() == IddObjectType::OS_Version) || (boost::regex_match(name(), iddRegex::versionObjectName()));
192 }
193
194 6760332 bool IddObject_Impl::isNonextensibleField(unsigned index) const {
195
2/2
✓ Branch 1 taken 4993538 times.
✓ Branch 2 taken 1766794 times.
6760332 if (index < m_fields.size()) {
196 4993538 return true;
197 }
198 1766794 return false;
199 }
200
201 32511456 bool IddObject_Impl::isExtensibleField(unsigned index) const {
202
6/6
✓ Branch 1 taken 20368557 times.
✓ Branch 2 taken 12142899 times.
✓ Branch 3 taken 20368543 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 20368543 times.
✓ Branch 6 taken 12142913 times.
32511456 if ((index >= m_fields.size()) && (m_properties.extensible)) {
203 20368543 return true;
204 }
205 12142913 return false;
206 }
207
208 3140804 bool IddObject_Impl::hasHandleField() const {
209
6/6
✓ Branch 1 taken 3072146 times.
✓ Branch 2 taken 68658 times.
✓ Branch 4 taken 3072146 times.
✓ Branch 8 taken 3072146 times.
✓ Branch 11 taken 2266150 times.
✓ Branch 12 taken 805996 times.
3140804 return ((!m_fields.empty()) && (m_fields[0].properties().type == IddFieldType::HandleType));
210 }
211
212 50174225 bool IddObject_Impl::hasNameField() const {
213
2/2
✓ Branch 1 taken 50095983 times.
✓ Branch 2 taken 78242 times.
100348450 if (m_nameFieldCache) {
214
1/1
✓ Branch 1 taken 50095983 times.
50095983 return m_nameFieldCache->first;
215 }
216
217 78242 unsigned index = 0;
218
3/3
✓ Branch 1 taken 78242 times.
✓ Branch 3 taken 51922 times.
✓ Branch 4 taken 26320 times.
78242 if (hasHandleField()) {
219 51922 index = 1;
220 }
221
5/5
✓ Branch 1 taken 76423 times.
✓ Branch 2 taken 1819 times.
✓ Branch 5 taken 76423 times.
✓ Branch 7 taken 52626 times.
✓ Branch 8 taken 23797 times.
78242 bool result = ((m_fields.size() > index) && (m_fields[index].isNameField()));
222
1/1
✓ Branch 2 taken 78242 times.
78242 m_nameFieldCache = std::pair<bool, unsigned>(result, index);
223 78242 return result;
224 }
225
226 42565592 boost::optional<unsigned> IddObject_Impl::nameFieldIndex() const {
227
2/2
✓ Branch 1 taken 41326862 times.
✓ Branch 2 taken 1238730 times.
42565592 if (hasNameField()) {
228
2/2
✓ Branch 1 taken 41326862 times.
✓ Branch 4 taken 41326862 times.
41326862 return m_nameFieldCache->second;
229 }
230 1238730 return boost::none;
231 }
232
233 200835 bool IddObject_Impl::isRequiredField(unsigned index) const {
234
1/1
✓ Branch 1 taken 200835 times.
200835 OptionalIddField iddField = getField(index);
235
1/2
✓ Branch 0 taken 200835 times.
✗ Branch 1 not taken.
200835 if (iddField) {
236
2/2
✓ Branch 1 taken 200835 times.
✓ Branch 4 taken 200835 times.
200835 return iddField->properties().required;
237 }
238 ✗ return false;
239 200835 }
240
241 384 bool IddObject_Impl::hasURL() const {
242 384 return m_properties.hasURL;
243 }
244
245 12592170 ExtensibleIndex IddObject_Impl::extensibleIndex(unsigned index) const {
246
2/3
✓ Branch 1 taken 12592170 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12592170 times.
12592170 if (!isExtensibleField(index)) {
247 ✗ LOG_AND_THROW("Field " << index << " is not an extensible field in IddObject " << name() << ".");
248 }
249
1/1
✓ Branch 1 taken 12592170 times.
12592170 ExtensibleIndex result(0, 0);
250 12592170 result.field = (index - m_fields.size()) % m_properties.numExtensible;
251 12592170 result.group = (index - result.field - m_fields.size()) / m_properties.numExtensible;
252 12592170 return result;
253 }
254
255 12254649 unsigned IddObject_Impl::index(ExtensibleIndex extensibleIndex) const {
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12254649 times.
12254649 if (!m_properties.extensible) {
257 ✗ LOG_AND_THROW("IddObject " << name() << " does not have extensible fields.");
258 }
259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12254649 times.
12254649 if (extensibleIndex.field >= m_properties.numExtensible) {
260 ✗ LOG_AND_THROW("IddObject " << name() << " only has " << m_properties.numExtensible
261 << " fields in its extensible group. Therefore, a ExtensibleIndex.field of " << extensibleIndex.field
262 << " is invalid.");
263 }
264 12254649 return m_fields.size() + extensibleIndex.group * m_properties.numExtensible + extensibleIndex.field;
265 }
266
267 785668 std::vector<std::string> IddObject_Impl::references() const {
268 785668 std::vector<std::string> result;
269
3/3
✓ Branch 1 taken 785668 times.
✓ Branch 3 taken 645563 times.
✓ Branch 4 taken 140105 times.
1571336 if (OptionalUnsigned index = nameFieldIndex()) {
270
3/3
✓ Branch 1 taken 645563 times.
✓ Branch 5 taken 645563 times.
✓ Branch 8 taken 645563 times.
645563 result = m_fields[*index].properties().references;
271 // To ensure uniqueness of name within a given class, we add a fake reference by class
272 // https://github.com/NREL/OpenStudio/issues/3079
273 //if (result.empty()) {
274
1/1
✓ Branch 1 taken 645563 times.
645563 std::string ref = name();
275
2/2
✓ Branch 1 taken 645563 times.
✓ Branch 4 taken 645563 times.
645563 result.push_back(ref + "UniqueNames");
276 //}
277 645563 } else {
278
1/1
✓ Branch 1 taken 140105 times.
140105 std::string n = name();
279
3/3
✓ Branch 1 taken 140105 times.
✓ Branch 3 taken 21286 times.
✓ Branch 4 taken 118819 times.
140105 if (n == "OS:PortList") {
280
2/2
✓ Branch 1 taken 21286 times.
✓ Branch 4 taken 21286 times.
42572 result.push_back("ConnectionObject");
281
2/2
✓ Branch 1 taken 21286 times.
✓ Branch 4 taken 21286 times.
42572 result.push_back("PortLists");
282
3/3
✓ Branch 1 taken 118819 times.
✓ Branch 3 taken 45653 times.
✓ Branch 4 taken 73166 times.
118819 } else if (n == "OS:Connection") {
283
2/2
✓ Branch 1 taken 45653 times.
✓ Branch 4 taken 45653 times.
91306 result.push_back("ConnectionNames");
284 }
285 140105 }
286
287 785668 return result;
288 ✗ }
289
290 392163 std::set<std::string> IddObject_Impl::objectLists() const {
291 392163 std::set<std::string> result;
292
2/2
✓ Branch 5 taken 3401878 times.
✓ Branch 6 taken 392163 times.
3794041 for (const IddField& field : m_fields) {
293
1/1
✓ Branch 1 taken 3401878 times.
3401878 const IddFieldProperties& properties = field.properties();
294
1/1
✓ Branch 3 taken 3401878 times.
3401878 result.insert(properties.objectLists.begin(), properties.objectLists.end());
295 }
296
2/2
✓ Branch 5 taken 452598 times.
✓ Branch 6 taken 392163 times.
844761 for (const IddField& field : m_extensibleFields) {
297
1/1
✓ Branch 1 taken 452598 times.
452598 const IddFieldProperties& properties = field.properties();
298
1/1
✓ Branch 3 taken 452598 times.
452598 result.insert(properties.objectLists.begin(), properties.objectLists.end());
299 }
300 392163 return result;
301 ✗ }
302
303 1557398 std::set<std::string> IddObject_Impl::objectLists(unsigned index) const {
304 1557398 std::set<std::string> result;
305
306
3/3
✓ Branch 1 taken 1557398 times.
✓ Branch 3 taken 1468320 times.
✓ Branch 4 taken 89078 times.
1557398 if (isNonextensibleField(index)) {
307
1/1
✓ Branch 2 taken 1468320 times.
1468320 const IddFieldProperties& properties = m_fields[index].properties();
308
1/1
✓ Branch 3 taken 1468320 times.
1468320 result.insert(properties.objectLists.begin(), properties.objectLists.end());
309
2/3
✓ Branch 1 taken 89078 times.
✓ Branch 3 taken 89078 times.
✗ Branch 4 not taken.
89078 } else if (isExtensibleField(index)) {
310
1/1
✓ Branch 1 taken 89078 times.
89078 ExtensibleIndex eIndex = extensibleIndex(index);
311
1/1
✓ Branch 2 taken 89078 times.
89078 const IddFieldProperties& properties = m_extensibleFields[eIndex.field].properties();
312
1/1
✓ Branch 3 taken 89078 times.
89078 result.insert(properties.objectLists.begin(), properties.objectLists.end());
313 }
314
315 1557398 return result;
316 ✗ }
317
318 406488 UnsignedVector IddObject_Impl::objectListFields() const {
319
320 406488 UnsignedVector result;
321
322
2/2
✓ Branch 1 taken 3503175 times.
✓ Branch 2 taken 406488 times.
3909663 for (unsigned index = 0; index < m_fields.size(); ++index) {
323
3/3
✓ Branch 2 taken 3503175 times.
✓ Branch 4 taken 884306 times.
✓ Branch 5 taken 2618869 times.
3503175 if (m_fields[index].isObjectListField()) {
324
1/1
✓ Branch 1 taken 884306 times.
884306 result.push_back(index);
325 }
326 }
327
2/2
✓ Branch 1 taken 459896 times.
✓ Branch 2 taken 406488 times.
866384 for (unsigned index = 0; index < m_extensibleFields.size(); ++index) {
328
3/3
✓ Branch 2 taken 459896 times.
✓ Branch 4 taken 56138 times.
✓ Branch 5 taken 403758 times.
459896 if (m_extensibleFields[index].isObjectListField()) {
329
1/1
✓ Branch 2 taken 56138 times.
56138 result.push_back(m_fields.size() + index);
330 }
331 }
332
333 406488 return result;
334 ✗ }
335
336 1 std::vector<unsigned> IddObject_Impl::urlFields() const {
337 1 UnsignedVector result;
338
339
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1 time.
11 for (unsigned index = 0; index < m_fields.size(); ++index) {
340
4/4
✓ Branch 1 taken 10 times.
✓ Branch 5 taken 10 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 9 times.
10 if (m_fields[index].properties().type == IddFieldType::URLType) {
341
1/1
✓ Branch 1 taken 1 time.
1 result.push_back(index);
342 }
343 }
344
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 for (unsigned index = 0; index < m_extensibleFields.size(); ++index) {
345 ✗ if (m_extensibleFields[index].properties().type == IddFieldType::URLType) {
346 ✗ result.push_back(m_fields.size() + index);
347 }
348 }
349
350 1 return result;
351 ✗ }
352
353 3331756 bool IddObject_Impl::operator==(const IddObject_Impl& other) const {
354
2/2
✓ Branch 0 taken 84193 times.
✓ Branch 1 taken 3247563 times.
3331756 if (this == &other) {
355 84193 return true;
356 }
357
358
2/2
✓ Branch 1 taken 2898165 times.
✓ Branch 2 taken 349398 times.
3247563 if (m_type != other.m_type) {
359 2898165 return false;
360 }
361
2/2
✓ Branch 1 taken 349218 times.
✓ Branch 2 taken 180 times.
349398 if (m_name != other.m_name) {
362 349218 return false;
363 }
364
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
180 if (m_group != other.m_group) {
365 ✗ return false;
366 }
367
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
180 if (m_properties != other.m_properties) {
368 ✗ return false;
369 }
370
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
180 if (m_fields != other.m_fields) {
371 ✗ return false;
372 }
373
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 180 times.
180 if (m_extensibleFields != other.m_extensibleFields) {
374 ✗ return false;
375 }
376
377 180 return true;
378 }
379
380 // SERIALIZATION
381
382 1099616 std::shared_ptr<IddObject_Impl> IddObject_Impl::load(const std::string& name, const std::string& group, const std::string& text,
383 IddObjectType type) {
384 1099616 std::shared_ptr<IddObject_Impl> result;
385
3/5
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
✓ Branch 7 taken 1099616 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1099616 result = std::shared_ptr<IddObject_Impl>(new IddObject_Impl(name, group, type));
386
387 try {
388
1/1
✓ Branch 2 taken 1099616 times.
1099616 result->parse(text);
389 ✗ } catch (...) {
390 ✗ return {};
391 ✗ }
392
393 1099616 return result;
394 1099616 }
395
396 /// print
397 57587 std::ostream& IddObject_Impl::print(std::ostream& os) const {
398
6/6
✓ Branch 1 taken 109 times.
✓ Branch 2 taken 57478 times.
✓ Branch 4 taken 105 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 105 times.
✓ Branch 7 taken 57482 times.
57587 if (m_fields.empty() && m_extensibleFields.empty()) {
399
400 105 os << m_name << ";" << '\n';
401 105 m_properties.print(os);
402 105 os << '\n';
403
404 } else {
405
406 57482 os << m_name << "," << '\n';
407 57482 m_properties.print(os);
408
409 57482 bool extensibleFields = !m_extensibleFields.empty();
410
2/2
✓ Branch 4 taken 719703 times.
✓ Branch 5 taken 57482 times.
777185 for (auto it = m_fields.begin(), itend = m_fields.end(); it != itend; ++it) {
411
2/2
✓ Branch 0 taken 57836 times.
✓ Branch 1 taken 661867 times.
719703 if (extensibleFields) {
412
1/1
✓ Branch 2 taken 57836 times.
57836 it->print(os, false); // don't print ; just yet
413 } else {
414
1/1
✓ Branch 4 taken 661867 times.
661867 it->print(os, (it == itend - 1));
415 }
416 }
417
2/2
✓ Branch 3 taken 17758 times.
✓ Branch 4 taken 57482 times.
75240 for (auto it = m_extensibleFields.begin(), itend = m_extensibleFields.end(); it != itend; ++it) {
418
1/1
✓ Branch 4 taken 17758 times.
17758 it->print(os, (it == itend - 1));
419 }
420
421 57482 os << '\n';
422 }
423
424 57587 return os;
425 }
426
427 // PRIVATE
428
429
2/2
✓ Branch 2 taken 1099616 times.
✓ Branch 5 taken 1099616 times.
1099616 IddObject_Impl::IddObject_Impl(const string& name, const string& group, IddObjectType type) : m_name(name), m_group(group), m_type(type) {}
430
431 1099616 void IddObject_Impl::parse(const std::string& text) {
432
1/1
✓ Branch 1 taken 1099616 times.
1099616 smatch matches;
433
4/4
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
✓ Branch 6 taken 1097119 times.
✓ Branch 7 taken 2497 times.
1099616 if (boost::regex_search(text, matches, iddRegex::objectAndFields())) {
434 // find and parse the object text
435
3/3
✓ Branch 1 taken 1097119 times.
✓ Branch 4 taken 1097119 times.
✓ Branch 7 taken 1097119 times.
1097119 string objectText(matches[1].first, matches[1].second);
436
1/1
✓ Branch 1 taken 1097119 times.
1097119 parseObject(objectText);
437
438 // find and parse the fields text
439
3/3
✓ Branch 1 taken 1097119 times.
✓ Branch 4 taken 1097119 times.
✓ Branch 7 taken 1097119 times.
1097119 string fieldsText(matches[2].first, matches[2].second);
440
1/1
✓ Branch 1 taken 1097119 times.
1097119 parseFields(fieldsText);
441
442
3/4
✓ Branch 3 taken 2497 times.
✓ Branch 6 taken 2497 times.
✓ Branch 8 taken 2497 times.
✗ Branch 9 not taken.
1099616 } else if (boost::regex_match(text, iddRegex::objectNoFields())) {
443 // there are no fields in this object, it is all object text
444
1/1
✓ Branch 1 taken 2497 times.
2497 parseObject(text);
445
446 } else {
447 // error
448 ✗ LOG_AND_THROW("Unexpected pattern '" << text << "' found in object '" << m_name << "'");
449 }
450
451 // remove existing extensible fields and add them the the extensible list
452
2/2
✓ Branch 0 taken 169582 times.
✓ Branch 1 taken 930034 times.
1099616 if (m_properties.extensible) {
453
1/1
✓ Branch 1 taken 169582 times.
169582 makeExtensible();
454 }
455 1099616 }
456
457 169582 void IddObject_Impl::makeExtensible() {
458 // number of fields in extensible group
459 169582 unsigned numExtensible = m_properties.numExtensible;
460
461 // check that numExtensible > 0
462
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 169582 times.
169582 if (numExtensible == 0) {
463 ✗ LOG(Error, "Extensible length 0 in object '" << m_name << "'");
464 ✗ return;
465 }
466
467 // find the begin extensible field, there should be only one
468 169582 auto extensibleBegin = m_fields.end();
469
1/2
✓ Branch 4 taken 1240663 times.
✗ Branch 5 not taken.
1240663 for (auto it = m_fields.begin(), itend = m_fields.end(); it != itend; ++it) {
470
3/3
✓ Branch 2 taken 1240663 times.
✓ Branch 4 taken 169582 times.
✓ Branch 5 taken 1071081 times.
1240663 if (it->properties().beginExtensible) {
471 169582 extensibleBegin = it;
472 169582 break;
473 }
474 }
475
476 // no extensible begin found
477
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 169582 times.
169582 if (extensibleBegin == m_fields.end()) {
478 ✗ LOG(Error, "No begin-extensible field detected in object '" << m_name << "'");
479 ✗ return;
480 }
481
482 // extensible begin is too close to the end of the field list
483
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 169582 times.
169582 if ((extensibleBegin + numExtensible) > m_fields.end()) {
484 ✗ LOG(Error, "Extensible fields begin too close to end of fields in object '" << m_name << "'");
485 ✗ return;
486 }
487
488 // copy extensible fields
489
1/1
✓ Branch 2 taken 169582 times.
169582 m_extensibleFields = IddFieldVector(extensibleBegin, extensibleBegin + numExtensible);
490
491 // remove all the extensible fields from the field list
492
1/1
✓ Branch 3 taken 169582 times.
169582 m_fields.resize(extensibleBegin - m_fields.begin());
493
494 // regexs that match extensible fields
495 169582 std::string replace;
496
497 // replace names of extensible fields so they do not contain numbers
498 // e.g. "Vertex 1 X-coordinate" -> "Vertex X-coordinate"
499
2/2
✓ Branch 5 taken 346412 times.
✓ Branch 6 taken 169582 times.
515994 for (IddField& extensibleField : m_extensibleFields) {
500
1/1
✓ Branch 1 taken 346412 times.
346412 std::string extensibleFieldName = extensibleField.name();
501
3/3
✓ Branch 1 taken 346412 times.
✓ Branch 4 taken 346412 times.
✓ Branch 7 taken 346412 times.
346412 extensibleFieldName = regex_replace(extensibleFieldName, iddRegex::numberAndPrecedingSpace(), replace, boost::format_first_only);
502
1/1
✓ Branch 1 taken 346412 times.
346412 openstudio::ascii_trim(extensibleFieldName);
503
1/1
✓ Branch 1 taken 346412 times.
346412 extensibleField.setName(extensibleFieldName);
504 346412 }
505
506 // figure out numExtensibleGroupsRequired
507
2/2
✓ Branch 0 taken 121733 times.
✓ Branch 1 taken 47849 times.
169582 if (m_properties.minFields > 0) {
508 121733 unsigned minFields = m_properties.minFields;
509
2/2
✓ Branch 1 taken 56545 times.
✓ Branch 2 taken 65188 times.
121733 if (minFields > m_fields.size()) {
510 56545 double numerator(minFields - (unsigned)m_fields.size());
511 56545 double denominator(numExtensible);
512 56545 m_properties.numExtensibleGroupsRequired = unsigned(std::ceil(numerator / denominator));
513 }
514 }
515 169582 }
516
517 1099616 void IddObject_Impl::parseObject(const std::string& text) {
518 // find the object name and the property text
519
1/1
✓ Branch 1 taken 1099616 times.
1099616 smatch matches;
520 1099616 string propertiesText;
521
3/4
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
✓ Branch 6 taken 1099616 times.
✗ Branch 7 not taken.
1099616 if (boost::regex_search(text, matches, iddRegex::line())) {
522
3/3
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
✓ Branch 7 taken 1099616 times.
1099616 std::string objectName = string(matches[1].first, matches[1].second);
523
1/1
✓ Branch 1 taken 1099616 times.
1099616 openstudio::ascii_trim(objectName);
524
2/3
✓ Branch 1 taken 1099616 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1099616 times.
1099616 if (!boost::equals(m_name, objectName)) {
525 ✗ LOG_AND_THROW("Object name '" << objectName << "' does not match expected '" << m_name << "'");
526 }
527
528
3/3
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
✓ Branch 7 taken 1099616 times.
1099616 propertiesText = string(matches[2].first, matches[2].second);
529
1/1
✓ Branch 1 taken 1099616 times.
1099616 openstudio::ascii_trim(propertiesText);
530 1099616 } else {
531 ✗ LOG_AND_THROW("Could not determine object name from text '" << text << "'");
532 }
533
534
4/4
✓ Branch 1 taken 4121472 times.
✓ Branch 4 taken 4121472 times.
✓ Branch 6 taken 3021856 times.
✓ Branch 7 taken 1099616 times.
4121472 while (boost::regex_search(propertiesText, matches, iddRegex::metaDataComment())) {
535
3/3
✓ Branch 1 taken 3021856 times.
✓ Branch 4 taken 3021856 times.
✓ Branch 7 taken 3021856 times.
3021856 string thisProperty(matches[1].first, matches[1].second);
536
1/1
✓ Branch 1 taken 3021856 times.
3021856 openstudio::ascii_trim(thisProperty);
537
1/1
✓ Branch 1 taken 3021856 times.
3021856 parseProperty(thisProperty);
538
539
3/3
✓ Branch 1 taken 3021856 times.
✓ Branch 4 taken 3021856 times.
✓ Branch 7 taken 3021856 times.
3021856 propertiesText = string(matches[2].first, matches[2].second);
540
1/1
✓ Branch 1 taken 3021856 times.
3021856 openstudio::ascii_trim(propertiesText);
541 3021856 }
542
5/6
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
✓ Branch 6 taken 2103 times.
✓ Branch 7 taken 1097513 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1099616 times.
1101719 if (!((boost::regex_match(propertiesText, commentRegex::whitespaceOnlyBlock()))
543
3/4
✓ Branch 1 taken 2103 times.
✓ Branch 4 taken 2103 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2103 times.
2103 || (boost::regex_match(propertiesText, iddRegex::commentOnlyLine())))) {
544 ✗ LOG_AND_THROW("Could not process properties text '" << propertiesText << "' in object '" << m_name << "'");
545 }
546 1099616 }
547
548 3021856 void IddObject_Impl::parseProperty(const std::string& text) {
549
1/1
✓ Branch 1 taken 3021856 times.
3021856 smatch matches;
550
4/4
✓ Branch 1 taken 3021856 times.
✓ Branch 4 taken 3021856 times.
✓ Branch 6 taken 1811221 times.
✓ Branch 7 taken 1210635 times.
3021856 if (boost::regex_search(text, matches, iddRegex::memoProperty())) {
551
3/3
✓ Branch 1 taken 1811221 times.
✓ Branch 4 taken 1811221 times.
✓ Branch 7 taken 1811221 times.
1811221 string memo(matches[1].first, matches[1].second);
552
1/1
✓ Branch 1 taken 1811221 times.
1811221 openstudio::ascii_trim(memo);
553
2/2
✓ Branch 1 taken 667308 times.
✓ Branch 2 taken 1143913 times.
1811221 if (m_properties.memo.empty()) {
554
1/1
✓ Branch 1 taken 667308 times.
667308 m_properties.memo = memo;
555 } else {
556
2/2
✓ Branch 1 taken 1143913 times.
✓ Branch 4 taken 1143913 times.
1143913 m_properties.memo += "\n" + memo;
557 }
558
559
4/4
✓ Branch 2 taken 1210635 times.
✓ Branch 5 taken 1210635 times.
✓ Branch 7 taken 110173 times.
✓ Branch 8 taken 1100462 times.
3021856 } else if (boost::regex_match(text, iddRegex::uniqueProperty())) {
560 110173 m_properties.unique = true;
561
562
4/4
✓ Branch 1 taken 1100462 times.
✓ Branch 4 taken 1100462 times.
✓ Branch 6 taken 12057 times.
✓ Branch 7 taken 1088405 times.
1100462 } else if (boost::regex_match(text, iddRegex::requiredObjectProperty())) {
563 12057 m_properties.required = true;
564
565
4/4
✓ Branch 1 taken 1088405 times.
✓ Branch 4 taken 1088405 times.
✓ Branch 6 taken 2296 times.
✓ Branch 7 taken 1086109 times.
1088405 } else if (boost::regex_match(text, iddRegex::obsoleteProperty())) {
566 2296 m_properties.obsolete = true;
567
568
4/4
✓ Branch 1 taken 1086109 times.
✓ Branch 4 taken 1086109 times.
✓ Branch 6 taken 7532 times.
✓ Branch 7 taken 1078577 times.
1086109 } else if (boost::regex_match(text, iddRegex::hasurlProperty())) {
569 7532 m_properties.hasURL = true;
570
571
4/4
✓ Branch 1 taken 1078577 times.
✓ Branch 4 taken 1078577 times.
✓ Branch 6 taken 170902 times.
✓ Branch 7 taken 907675 times.
1078577 } else if (boost::regex_search(text, matches, iddRegex::extensibleProperty())) {
572 170902 m_properties.extensible = true;
573
574
3/3
✓ Branch 1 taken 170902 times.
✓ Branch 4 taken 170902 times.
✓ Branch 7 taken 170902 times.
170902 string numExtensible(matches[1].first, matches[1].second);
575
1/1
✓ Branch 1 taken 170902 times.
170902 m_properties.numExtensible = boost::lexical_cast<unsigned>(numExtensible);
576
577
4/4
✓ Branch 2 taken 907675 times.
✓ Branch 5 taken 907675 times.
✓ Branch 7 taken 63187 times.
✓ Branch 8 taken 844488 times.
1078577 } else if (boost::regex_search(text, matches, iddRegex::formatProperty())) {
578
3/3
✓ Branch 1 taken 63187 times.
✓ Branch 4 taken 63187 times.
✓ Branch 7 taken 63187 times.
63187 string format(matches[1].first, matches[1].second);
579
1/1
✓ Branch 1 taken 63187 times.
63187 openstudio::ascii_trim(format);
580
1/1
✓ Branch 1 taken 63187 times.
63187 m_properties.format = format;
581
582
4/4
✓ Branch 2 taken 844488 times.
✓ Branch 5 taken 844488 times.
✓ Branch 7 taken 814447 times.
✓ Branch 8 taken 30041 times.
907675 } else if (boost::regex_search(text, matches, iddRegex::minFieldsProperty())) {
583
3/3
✓ Branch 1 taken 814447 times.
✓ Branch 4 taken 814447 times.
✓ Branch 7 taken 814447 times.
814447 string minFields(matches[1].first, matches[1].second);
584
1/1
✓ Branch 1 taken 814447 times.
814447 m_properties.minFields = boost::lexical_cast<unsigned>(minFields);
585
586
3/4
✓ Branch 2 taken 30041 times.
✓ Branch 5 taken 30041 times.
✓ Branch 7 taken 30041 times.
✗ Branch 8 not taken.
844488 } else if (boost::regex_search(text, matches, iddRegex::maxFieldsProperty())) {
587
3/3
✓ Branch 1 taken 30041 times.
✓ Branch 4 taken 30041 times.
✓ Branch 7 taken 30041 times.
30041 string maxFields(matches[1].first, matches[1].second);
588
2/2
✓ Branch 1 taken 30041 times.
✓ Branch 4 taken 30041 times.
30041 m_properties.maxFields = boost::lexical_cast<unsigned>(maxFields);
589 30041 } else {
590 // error, unknown property
591 ✗ LOG_AND_THROW("Unknown property text '" << text << "' in object '" << m_name << "'");
592 }
593 3021856 }
594
595 1097119 void IddObject_Impl::parseFields(const std::string& text) {
596
4/7
✓ Branch 0 taken 4052 times.
✓ Branch 1 taken 1093067 times.
✓ Branch 3 taken 4052 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4052 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
1097119 static const boost::regex field_start("[AN][0-9]+[\\s]*[,;]");
597
598 1097119 auto begin = text.begin();
599 1097119 const auto end = text.end();
600
601
1/1
✓ Branch 1 taken 1097119 times.
1097119 boost::match_results<std::string::const_iterator> matches;
602
2/3
✓ Branch 1 taken 1097119 times.
✓ Branch 3 taken 1097119 times.
✗ Branch 4 not taken.
1097119 if (boost::regex_search(begin, end, matches, field_start)) {
603
1/1
✓ Branch 1 taken 1097119 times.
1097119 begin = matches[0].first;
604
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1097119 times.
1097119 if (begin != text.begin()) {
605 ✗ LOG_AND_THROW("Could not process field text '" << text << "' in object ', start is not where expected" << m_name << "'");
606 }
607 } else {
608 ✗ return;
609 }
610
611 1097119 std::string::const_iterator field_end;
612
613
2/2
✓ Branch 1 taken 13542481 times.
✓ Branch 2 taken 1097119 times.
14639600 while (begin != end) {
614
3/3
✓ Branch 2 taken 13542481 times.
✓ Branch 4 taken 12445362 times.
✓ Branch 5 taken 1097119 times.
13542481 if (boost::regex_search(begin + 1, end, matches, field_start)) {
615
1/1
✓ Branch 1 taken 12445362 times.
12445362 field_end = matches[0].first;
616 } else {
617 1097119 field_end = end;
618 }
619
620 // take the text of the last field
621
1/1
✓ Branch 1 taken 13542481 times.
13542481 string fieldText(begin, field_end);
622 13542481 begin = field_end;
623
624 13542481 string fieldName;
625
626 // peak ahead to find the field name for indexing in map
627
1/1
✓ Branch 1 taken 13542481 times.
13542481 smatch nameMatches;
628
4/4
✓ Branch 1 taken 13542481 times.
✓ Branch 4 taken 13542481 times.
✓ Branch 6 taken 13530831 times.
✓ Branch 7 taken 11650 times.
13542481 if (boost::regex_search(fieldText, nameMatches, iddRegex::name())) {
629
3/3
✓ Branch 1 taken 13530831 times.
✓ Branch 4 taken 13530831 times.
✓ Branch 7 taken 13530831 times.
13530831 fieldName = string(nameMatches[1].first, nameMatches[1].second);
630
1/1
✓ Branch 1 taken 13530831 times.
13530831 openstudio::ascii_trim(fieldName);
631
3/4
✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 11650 times.
✓ Branch 6 taken 11650 times.
✗ Branch 7 not taken.
11650 } else if (boost::regex_search(fieldText, nameMatches, iddRegex::field())) {
632 // if no explicit field name, use the type and number
633
3/3
✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 11650 times.
✓ Branch 7 taken 11650 times.
11650 string fieldTypeChar(nameMatches[1].first, nameMatches[1].second);
634
1/1
✓ Branch 1 taken 11650 times.
11650 openstudio::ascii_trim(fieldTypeChar);
635
3/3
✓ Branch 1 taken 11650 times.
✓ Branch 4 taken 11650 times.
✓ Branch 7 taken 11650 times.
11650 string fieldTypeNumber(nameMatches[2].first, nameMatches[2].second);
636
1/1
✓ Branch 1 taken 11650 times.
11650 openstudio::ascii_trim(fieldTypeNumber);
637
1/1
✓ Branch 1 taken 11650 times.
11650 fieldName = fieldTypeChar + fieldTypeNumber;
638 11650 } else {
639 // cannot find the field name
640 ✗ LOG_AND_THROW("Cannot determine field name from text '" << fieldText << "'");
641 }
642
643 // construct the field
644
1/1
✓ Branch 1 taken 13542481 times.
13542481 OptionalIddField oField = IddField::load(fieldName, fieldText, m_name);
645
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13542481 times.
13542481 if (!oField) {
646 ✗ LOG_AND_THROW("Cannot parse IddField text '" << fieldText << "'.");
647 }
648
649 // construct a new object and put it in the object list and object map
650
2/2
✓ Branch 1 taken 13542481 times.
✓ Branch 4 taken 13542481 times.
13542481 m_fields.push_back(*oField);
651 13542481 }
652 1097119 }
653
654 } // namespace detail
655
656 // CONSTRUCTORS
657
658
2/4
✓ Branch 2 taken 226425 times.
✓ Branch 5 taken 226425 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
226425 IddObject::IddObject() : m_impl(std::shared_ptr<detail::IddObject_Impl>(new detail::IddObject_Impl())) {}
659
660 135591996 IddObject::IddObject(const IddObject& other) = default;
661
662 // GETTERS
663
664 134659520 std::string IddObject::name() const {
665 134659520 return m_impl->name();
666 }
667
668 49323186 IddObjectType IddObject::type() const {
669 49323186 return m_impl->type();
670 }
671
672 61131 std::string IddObject::group() const {
673 61131 return m_impl->group();
674 }
675
676 39492495 const IddObjectProperties& IddObject::properties() const {
677 39492495 return m_impl->properties();
678 }
679
680 202224 const IddFieldVector& IddObject::nonextensibleFields() const {
681 202224 return m_impl->nonextensibleFields();
682 }
683
684 135420 const IddFieldVector& IddObject::extensibleGroup() const {
685 135420 return m_impl->extensibleGroup();
686 }
687
688 99274663 boost::optional<IddField> IddObject::getField(unsigned index) const {
689 99274663 return m_impl->getField(index);
690 }
691
692 14 boost::optional<IddField> IddObject::getField(const std::string& fieldName) const {
693 14 return m_impl->getField(fieldName);
694 }
695
696 9530 boost::optional<int> IddObject::getFieldIndex(const std::string& fieldName) const {
697 9530 return m_impl->getFieldIndex(fieldName);
698 }
699
700 // SETTERS
701
702 1 void IddObject::insertHandleField() {
703 1 return m_impl->insertHandleField();
704 }
705
706 // QUERIES
707
708 7657003 unsigned IddObject::numFields() const {
709 7657003 return m_impl->numFields();
710 }
711
712 1679001 unsigned IddObject::numFieldsInDefaultObject() const {
713 1679001 return m_impl->numFieldsInDefaultObject();
714 }
715
716 1272923 bool IddObject::isVersionObject() const {
717 1272923 return m_impl->isVersionObject();
718 }
719
720 5202934 bool IddObject::isNonextensibleField(unsigned index) const {
721 5202934 return m_impl->isNonextensibleField(index);
722 }
723
724 19830208 bool IddObject::isExtensibleField(unsigned index) const {
725 19830208 return m_impl->isExtensibleField(index);
726 }
727
728 3062561 bool IddObject::hasHandleField() const {
729 3062561 return m_impl->hasHandleField();
730 }
731
732 7608633 bool IddObject::hasNameField() const {
733 7608633 return m_impl->hasNameField();
734 }
735
736 41779924 boost::optional<unsigned> IddObject::nameFieldIndex() const {
737 41779924 return m_impl->nameFieldIndex();
738 }
739
740 200835 bool IddObject::isRequiredField(unsigned index) const {
741 200835 return m_impl->isRequiredField(index);
742 }
743
744 384 bool IddObject::hasURL() const {
745 384 return m_impl->hasURL();
746 }
747
748 12503092 ExtensibleIndex IddObject::extensibleIndex(unsigned index) const {
749 12503092 return m_impl->extensibleIndex(index);
750 }
751
752 12254649 unsigned IddObject::index(ExtensibleIndex extensibleIndex) const {
753 12254649 return m_impl->index(extensibleIndex);
754 }
755
756 785668 std::vector<std::string> IddObject::references() const {
757 785668 return m_impl->references();
758 }
759
760 392163 std::set<std::string> IddObject::objectLists() const {
761 392163 return m_impl->objectLists();
762 }
763
764 1557398 std::set<std::string> IddObject::objectLists(unsigned index) const {
765 1557398 return m_impl->objectLists(index);
766 }
767
768 406488 std::vector<unsigned> IddObject::objectListFields() const {
769 406488 return m_impl->objectListFields();
770 }
771
772 1 std::vector<unsigned> IddObject::urlFields() const {
773 1 return m_impl->urlFields();
774 }
775
776 3331756 bool IddObject::operator==(const IddObject& other) const {
777 3331756 return (*m_impl == *(other.m_impl));
778 }
779
780 2970206 bool IddObject::operator!=(const IddObject& other) const {
781 2970206 return !(*this == other);
782 }
783
784 // SERIALIZATION
785
786 1099616 boost::optional<IddObject> IddObject::load(const std::string& name, const std::string& group, const std::string& text, IddObjectType type) {
787
1/1
✓ Branch 1 taken 1099616 times.
1099616 std::shared_ptr<detail::IddObject_Impl> p = detail::IddObject_Impl::load(name, group, text, type);
788
1/2
✓ Branch 1 taken 1099616 times.
✗ Branch 2 not taken.
1099616 if (p) {
789
2/2
✓ Branch 1 taken 1099616 times.
✓ Branch 4 taken 1099616 times.
1099616 return IddObject(p);
790 } else {
791 ✗ return boost::none;
792 }
793 1099616 }
794
795 881104 boost::optional<IddObject> IddObject::load(const std::string& name, const std::string& group, const std::string& text) {
796
2/2
✓ Branch 1 taken 881104 times.
✓ Branch 4 taken 881104 times.
881104 return load(name, group, text, IddObjectType(IddObjectType::UserCustom));
797 }
798
799 57587 std::ostream& IddObject::print(std::ostream& os) const {
800 57587 return m_impl->print(os);
801 }
802
803 // PRIVATE
804
805 1099616 IddObject::IddObject(const std::shared_ptr<detail::IddObject_Impl>& impl) : m_impl(impl) {}
806
807 // NON-MEMBER FUNCTIONS
808
809 ✗ std::ostream& operator<<(std::ostream& os, const IddObject& iddObject) {
810 ✗ return iddObject.print(os);
811 }
812
813 2 IddObjectTypeVector getIddObjectTypeVector(const IddObjectVector& objects) {
814 2 IddObjectTypeVector result;
815
2/2
✓ Branch 4 taken 4356 times.
✓ Branch 5 taken 2 times.
4358 for (const IddObject& object : objects) {
816
2/2
✓ Branch 1 taken 4356 times.
✓ Branch 4 taken 4356 times.
4356 result.push_back(object.type());
817 }
818 2 return result;
819 ✗ }
820
821 1 IddObjectTypeSet getIddObjectTypeSet(const IddObjectVector& objects) {
822 1 IddObjectTypeSet result;
823
2/2
✓ Branch 4 taken 2904 times.
✓ Branch 5 taken 1 time.
2905 for (const IddObject& object : objects) {
824
2/2
✓ Branch 1 taken 2904 times.
✓ Branch 4 taken 2904 times.
2904 result.insert(object.type());
825 }
826 1 return result;
827 ✗ }
828
829 6112 std::vector<std::string> getIddKeyNames(const IddObject& object, unsigned index) {
830 6112 StringVector result;
831
1/1
✓ Branch 1 taken 6112 times.
6112 OptionalIddField oIddField = object.getField(index);
832
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6112 times.
6112 if (!oIddField) {
833 ✗ return result;
834 }
835
1/1
✓ Branch 1 taken 6112 times.
6112 IddField iddField = *oIddField;
836
1/1
✓ Branch 1 taken 6112 times.
6112 IddKeyVector keys = iddField.keys();
837
2/2
✓ Branch 4 taken 79793 times.
✓ Branch 5 taken 6112 times.
85905 for (const IddKey& key : keys) {
838
2/2
✓ Branch 1 taken 79793 times.
✓ Branch 4 taken 79793 times.
79793 result.push_back(key.name());
839 }
840 6112 return result;
841 6112 }
842
843 } // namespace openstudio
844