GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 83.3% 1161 / 0 / 1394
Functions: 89.2% 149 / 0 / 167
Branches: 68.7% 1515 / 0 / 2205

src/utilities/idf/IdfObject.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 "IdfObject.hpp"
7 #include "IdfObject_Impl.hpp"
8
9 #include "IdfExtensibleGroup.hpp"
10 #include "IdfRegex.hpp"
11 #include "ValidityReport.hpp"
12
13 #include "../idd/IddKey.hpp"
14 #include <utilities/idd/IddFactory.hxx>
15 #include <utilities/idd/IddEnums.hxx>
16 #include "../idd/IddRegex.hpp"
17 #include "../idd/CommentRegex.hpp"
18 #include "../idd/Comments.hpp"
19
20 #include "../math/FloatCompare.hpp"
21 #include "../core/Finder.hpp"
22 #include "../core/Assert.hpp"
23
24 #include "../units/Quantity.hpp"
25 #include "../units/OSOptionalQuantity.hpp"
26 #include "../units/QuantityConverter.hpp"
27
28 #include <boost/lexical_cast.hpp>
29
30 #include <iomanip>
31
32 namespace openstudio {
33
34 namespace detail {
35
36 // CONSTRUCTORS
37
38 1820167 IdfObject_Impl::IdfObject_Impl(const IdfObject_Impl& other, bool keepHandle)
39
5/5
✓ Branch 6 taken 1820167 times.
✓ Branch 9 taken 1820167 times.
✓ Branch 12 taken 1820167 times.
✓ Branch 15 taken 1820167 times.
✓ Branch 18 taken 1820167 times.
1820167 : m_comment(other.comment()), m_iddObject(other.iddObject()), m_fields(other.fields()), m_fieldComments(other.fieldComments()) {
40
2/2
✓ Branch 0 taken 1229354 times.
✓ Branch 1 taken 590813 times.
1820167 if (keepHandle) {
41
2/4
✓ Branch 1 taken 1229354 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1229354 times.
✗ Branch 7 not taken.
1229354 OS_ASSERT(!other.handle().isNull());
42
1/1
✓ Branch 1 taken 1229354 times.
1229354 m_handle = other.handle();
43 } else {
44
1/1
✓ Branch 1 taken 590813 times.
590813 m_handle = openstudio::createUUID();
45
3/3
✓ Branch 1 taken 590813 times.
✓ Branch 3 taken 210578 times.
✓ Branch 4 taken 380235 times.
590813 if (m_iddObject.hasHandleField()) {
46
2/2
✓ Branch 1 taken 210578 times.
✓ Branch 4 taken 210578 times.
210578 bool ok = setString(0, toString(m_handle));
47
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 210578 times.
✗ Branch 3 not taken.
210578 OS_ASSERT(ok);
48 }
49 }
50 1820167 }
51
52
2/2
✓ Branch 6 taken 223420 times.
✓ Branch 10 taken 223420 times.
223420 IdfObject_Impl::IdfObject_Impl(IddObjectType type, bool fastName) : m_handle(openstudio::createUUID()) {
53
2/2
✓ Branch 1 taken 223420 times.
✓ Branch 4 taken 223420 times.
223420 OptionalIddObject candidate = IddFactory::instance().getObject(type);
54
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 223420 times.
✗ Branch 4 not taken.
223420 OS_ASSERT(candidate);
55
1/1
✓ Branch 1 taken 223420 times.
223420 m_iddObject = *candidate;
56
3/3
✓ Branch 1 taken 223420 times.
✓ Branch 3 taken 175344 times.
✓ Branch 4 taken 48076 times.
223420 if (m_iddObject.hasHandleField()) {
57
2/2
✓ Branch 1 taken 175344 times.
✓ Branch 4 taken 175344 times.
175344 bool ok = setString(0, toString(m_handle));
58
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 175344 times.
✗ Branch 3 not taken.
175344 OS_ASSERT(ok);
59 }
60
2/2
✓ Branch 0 taken 1021 times.
✓ Branch 1 taken 222399 times.
223420 if (fastName) {
61
1/1
✓ Branch 1 taken 1021 times.
1021 boost::optional<unsigned> nameFieldIndex = this->m_iddObject.nameFieldIndex();
62
1/2
✓ Branch 0 taken 1021 times.
✗ Branch 1 not taken.
1021 if (nameFieldIndex) {
63
4/4
✓ Branch 1 taken 1021 times.
✓ Branch 4 taken 1021 times.
✓ Branch 7 taken 1021 times.
✓ Branch 10 taken 1021 times.
1021 bool ok = setString(*nameFieldIndex, toString(createUUID()));
64
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1021 times.
✗ Branch 3 not taken.
1021 OS_ASSERT(ok);
65 } else {
66 ✗ LOG(Error, "Requested setting name field to UUID but object of type '" << this->m_iddObject.name() << "' has no name field");
67 }
68 }
69
1/1
✓ Branch 1 taken 223420 times.
223420 resizeToMinFields();
70 223420 }
71
72
2/2
✓ Branch 6 taken 21835 times.
✓ Branch 10 taken 21835 times.
21835 IdfObject_Impl::IdfObject_Impl(const IddObject& iddObject, bool fastName) : m_handle(openstudio::createUUID()), m_iddObject(iddObject) {
73
3/3
✓ Branch 1 taken 21835 times.
✓ Branch 3 taken 19835 times.
✓ Branch 4 taken 2000 times.
21835 if (this->m_iddObject.hasHandleField()) {
74
2/2
✓ Branch 1 taken 19835 times.
✓ Branch 4 taken 19835 times.
19835 bool ok = setString(0, toString(m_handle));
75
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 19835 times.
✗ Branch 3 not taken.
19835 OS_ASSERT(ok);
76 }
77
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 21825 times.
21835 if (fastName) {
78
1/1
✓ Branch 1 taken 10 times.
10 boost::optional<unsigned> nameFieldIndex = this->m_iddObject.nameFieldIndex();
79
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if (nameFieldIndex) {
80
4/4
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
10 bool ok = setString(*nameFieldIndex, toString(createUUID()));
81
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
10 OS_ASSERT(ok);
82 } else {
83 ✗ LOG(Error, "Requested setting name field to UUID but object of type '" << this->m_iddObject.name() << "' has no name field");
84 }
85 }
86
1/1
✓ Branch 1 taken 21835 times.
21835 resizeToMinFields();
87 21835 }
88
89
2/2
✓ Branch 6 taken 1249552 times.
✓ Branch 10 taken 1249552 times.
1249552 IdfObject_Impl::IdfObject_Impl(const IddObject& iddObject, bool fastName, bool minimal) : m_iddObject(iddObject) {
90
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1249552 times.
✗ Branch 3 not taken.
1249552 OS_ASSERT(!fastName);
91
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1249552 times.
✗ Branch 3 not taken.
1249552 OS_ASSERT(minimal);
92 1249552 }
93
94 180814 IdfObject_Impl::IdfObject_Impl(const Handle& handle, const std::string& comment, const IddObject& iddObject, const StringVector& fields,
95 180814 const StringVector& fieldComments)
96
4/4
✓ Branch 6 taken 180814 times.
✓ Branch 9 taken 180814 times.
✓ Branch 12 taken 180814 times.
✓ Branch 15 taken 180814 times.
180814 : m_handle(handle), m_comment(comment), m_iddObject(iddObject), m_fields(fields), m_fieldComments(fieldComments) {
97
1/1
✓ Branch 1 taken 180814 times.
180814 resizeToMinFields();
98 180814 }
99
100 // GETTERS
101
102 21083671 Handle IdfObject_Impl::handle() const {
103 21083671 return m_handle;
104 }
105
106 124166137 IddObject IdfObject_Impl::iddObject() const {
107 124166137 return m_iddObject;
108 }
109
110 1820332 std::string IdfObject_Impl::comment() const {
111 1820332 return m_comment;
112 }
113
114 9521005 boost::optional<std::string> IdfObject_Impl::fieldComment(unsigned index, bool returnDefault) const {
115
3/3
✓ Branch 1 taken 9521005 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 9521004 times.
9521005 if (index >= numFields()) {
116 1 return boost::none;
117 }
118
119 9521004 std::string result;
120
2/2
✓ Branch 1 taken 590320 times.
✓ Branch 2 taken 8930684 times.
9521004 if (index < m_fieldComments.size()) {
121
1/1
✓ Branch 2 taken 590320 times.
590320 result = m_fieldComments[index];
122 }
123
124
6/6
✓ Branch 0 taken 9210147 times.
✓ Branch 1 taken 310857 times.
✓ Branch 3 taken 8621639 times.
✓ Branch 4 taken 588508 times.
✓ Branch 5 taken 8621639 times.
✓ Branch 6 taken 899365 times.
9521004 if (returnDefault && result.empty()) {
125
2/3
✓ Branch 1 taken 8621639 times.
✓ Branch 3 taken 8621639 times.
✗ Branch 4 not taken.
17243278 if (OptionalIddField iddField = m_iddObject.getField(index)) {
126
1/1
✓ Branch 1 taken 8621639 times.
8621639 std::stringstream ss;
127
4/4
✓ Branch 1 taken 8621639 times.
✓ Branch 4 taken 8621639 times.
✓ Branch 7 taken 8621639 times.
✓ Branch 10 taken 8621639 times.
8621639 ss << makeIdfEditorComment(iddField->name());
128
3/3
✓ Branch 1 taken 8621639 times.
✓ Branch 3 taken 679254 times.
✓ Branch 4 taken 7942385 times.
8621639 if (m_iddObject.isExtensibleField(index)) {
129
1/1
✓ Branch 1 taken 679254 times.
679254 ExtensibleIndex ei = m_iddObject.extensibleIndex(index);
130
2/2
✓ Branch 1 taken 679254 times.
✓ Branch 4 taken 679254 times.
679254 ss << " " << ei.group + 1;
131 }
132
5/5
✓ Branch 1 taken 8621639 times.
✓ Branch 4 taken 8621639 times.
✓ Branch 7 taken 8621639 times.
✓ Branch 9 taken 878591 times.
✓ Branch 10 taken 7743048 times.
17243278 if (OptionalString units = iddField->properties().units) {
133
1/2
✓ Branch 0 taken 878591 times.
✗ Branch 1 not taken.
878591 if (units) {
134
4/4
✓ Branch 1 taken 878591 times.
✓ Branch 4 taken 878591 times.
✓ Branch 7 taken 878591 times.
✓ Branch 10 taken 878591 times.
878591 ss << " {" << *units << "}";
135 }
136 8621639 }
137
1/1
✓ Branch 1 taken 8621639 times.
8621639 result = ss.str();
138 17243278 }
139 }
140
1/1
✓ Branch 1 taken 9521004 times.
9521004 return result;
141 9521004 }
142
143 34875385 boost::optional<std::string> IdfObject_Impl::name(bool returnDefault) const {
144
3/3
✓ Branch 1 taken 34875385 times.
✓ Branch 3 taken 33777515 times.
✓ Branch 4 taken 1097870 times.
69750770 if (OptionalUnsigned oi = m_iddObject.nameFieldIndex()) {
145
1/1
✓ Branch 1 taken 33777515 times.
33777515 unsigned index = *oi;
146 33777515 bool validIndex = m_fields.size() > index;
147
7/8
✓ Branch 0 taken 401295 times.
✓ Branch 1 taken 33376220 times.
✓ Branch 2 taken 401295 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 116580 times.
✓ Branch 7 taken 284715 times.
✓ Branch 8 taken 116580 times.
✓ Branch 9 taken 33660935 times.
33777515 if (returnDefault && validIndex && m_fields[index].empty()) {
148
5/5
✓ Branch 1 taken 116580 times.
✓ Branch 5 taken 116580 times.
✓ Branch 8 taken 116580 times.
✓ Branch 10 taken 48 times.
✓ Branch 11 taken 116532 times.
233160 if (OptionalString stringDefault = m_iddObject.nonextensibleFields()[index].properties().stringDefault) {
149
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if (stringDefault) {
150
3/3
✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
48 return decodeString(*stringDefault);
151 } else {
152 ✗ return boost::none;
153 }
154 116580 }
155
2/2
✓ Branch 2 taken 116532 times.
✓ Branch 5 taken 116532 times.
116532 return decodeString(m_fields[index]);
156
2/2
✓ Branch 0 taken 33651449 times.
✓ Branch 1 taken 9486 times.
33660935 } else if (validIndex) {
157
2/2
✓ Branch 2 taken 33651449 times.
✓ Branch 5 taken 33651449 times.
33651449 return decodeString(m_fields[index]);
158 }
159 }
160 1107356 return boost::none;
161 }
162
163 434574 std::string IdfObject_Impl::nameString(bool returnDefault) const {
164
1/1
✓ Branch 1 taken 434574 times.
434574 boost::optional<std::string> temp = name(returnDefault);
165
2/2
✓ Branch 0 taken 428350 times.
✓ Branch 1 taken 6224 times.
434574 if (temp) {
166
2/2
✓ Branch 1 taken 428350 times.
✓ Branch 4 taken 428350 times.
428350 return temp.get();
167 }
168
1/1
✓ Branch 1 taken 6224 times.
12448 return "";
169 434574 }
170
171 70351 std::string IdfObject_Impl::briefDescription() const {
172
1/1
✓ Branch 1 taken 70351 times.
70351 std::stringstream ss;
173
5/5
✓ Branch 1 taken 70351 times.
✓ Branch 4 taken 70351 times.
✓ Branch 7 taken 70351 times.
✓ Branch 10 taken 70351 times.
✓ Branch 13 taken 70351 times.
70351 ss << "Object of type '" << m_iddObject.type().valueDescription() << "'";
174
1/1
✓ Branch 1 taken 70351 times.
70351 OptionalString oName = name(true);
175
6/7
✓ Branch 0 taken 54510 times.
✓ Branch 1 taken 15841 times.
✓ Branch 3 taken 54510 times.
✓ Branch 6 taken 54510 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 54510 times.
✓ Branch 9 taken 15841 times.
70351 if (oName && (!oName->empty())) {
176
4/4
✓ Branch 1 taken 54510 times.
✓ Branch 4 taken 54510 times.
✓ Branch 7 taken 54510 times.
✓ Branch 10 taken 54510 times.
54510 ss << " and named '" << *oName << "'";
177 }
178
1/1
✓ Branch 1 taken 70351 times.
140702 return ss.str();
179 70351 }
180
181 154987 bool IdfObject_Impl::isEmpty(unsigned index) const {
182 154987 bool result = true;
183
2/2
✓ Branch 1 taken 122466 times.
✓ Branch 2 taken 32521 times.
154987 if (index < m_fields.size()) {
184
1/1
✓ Branch 1 taken 122466 times.
122466 OptionalString string = getString(index, false, true);
185
2/2
✓ Branch 0 taken 55203 times.
✓ Branch 1 taken 67263 times.
122466 if (string) {
186 55203 result = false;
187 }
188 122466 }
189 154987 return result;
190 }
191
192 19908112 boost::optional<std::string> IdfObject_Impl::getString(unsigned index, bool returnDefault, bool returnUninitializedEmpty) const {
193 19908112 OptionalString result;
194
2/2
✓ Branch 1 taken 19834680 times.
✓ Branch 2 taken 73432 times.
19908112 if (index < m_fields.size()) {
195
1/1
✓ Branch 2 taken 19834680 times.
19834680 result = m_fields[index];
196 }
197
11/11
✓ Branch 0 taken 1639729 times.
✓ Branch 1 taken 18268383 times.
✓ Branch 2 taken 1571216 times.
✓ Branch 3 taken 68513 times.
✓ Branch 5 taken 1571216 times.
✓ Branch 8 taken 1496829 times.
✓ Branch 9 taken 74387 times.
✓ Branch 11 taken 68513 times.
✓ Branch 12 taken 1496829 times.
✓ Branch 13 taken 142900 times.
✓ Branch 14 taken 19765212 times.
21547841 if (returnDefault && ((result && result->empty()) || (!result))) {
198
1/1
✓ Branch 1 taken 142900 times.
142900 OptionalIddField iddField = m_iddObject.getField(index);
199
8/8
✓ Branch 0 taken 142899 times.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 142899 times.
✓ Branch 6 taken 142899 times.
✓ Branch 9 taken 97706 times.
✓ Branch 10 taken 45193 times.
✓ Branch 11 taken 97706 times.
✓ Branch 12 taken 45194 times.
285799 if (iddField && iddField->properties().stringDefault) {
200
4/4
✓ Branch 1 taken 97706 times.
✓ Branch 4 taken 97706 times.
✓ Branch 7 taken 97706 times.
✓ Branch 10 taken 97706 times.
97706 result = *(iddField->properties().stringDefault);
201 }
202 142900 }
203
9/9
✓ Branch 0 taken 512048 times.
✓ Branch 1 taken 19396064 times.
✓ Branch 2 taken 509811 times.
✓ Branch 3 taken 2237 times.
✓ Branch 5 taken 509811 times.
✓ Branch 8 taken 42111 times.
✓ Branch 9 taken 467700 times.
✓ Branch 10 taken 42111 times.
✓ Branch 11 taken 19866001 times.
20420160 if (returnUninitializedEmpty && (result && result->empty())) {
204 42111 result.reset();
205 }
206
2/2
✓ Branch 0 taken 19840768 times.
✓ Branch 1 taken 67344 times.
19908112 if (result) {
207
3/3
✓ Branch 1 taken 19840768 times.
✓ Branch 4 taken 19840768 times.
✓ Branch 7 taken 19840768 times.
19840768 return decodeString(*result);
208 }
209 67344 return boost::none;
210 19908112 }
211
212 809 boost::optional<std::string> IdfObject_Impl::getField(unsigned index, bool returnDefault) const {
213 809 return IdfObject_Impl::getString(index, returnDefault, false);
214 }
215
216 11312254 boost::optional<double> IdfObject_Impl::getDouble(unsigned index, bool returnDefault) const {
217 11312254 OptionalDouble result;
218
1/1
✓ Branch 1 taken 11312254 times.
11312254 OptionalString value = getString(index, returnDefault, false);
219
2/2
✓ Branch 0 taken 11303586 times.
✓ Branch 1 taken 8668 times.
11312254 if (value) {
220
27/41
✓ Branch 1 taken 11303586 times.
✓ Branch 4 taken 11303586 times.
✓ Branch 7 taken 11303586 times.
✓ Branch 9 taken 10015396 times.
✓ Branch 10 taken 1288190 times.
✓ Branch 12 taken 10015396 times.
✓ Branch 15 taken 10015396 times.
✓ Branch 18 taken 10015396 times.
✓ Branch 20 taken 9864478 times.
✓ Branch 21 taken 150918 times.
✓ Branch 23 taken 9864478 times.
✓ Branch 26 taken 9864478 times.
✓ Branch 29 taken 9864478 times.
✓ Branch 31 taken 9821285 times.
✓ Branch 32 taken 43193 times.
✓ Branch 33 taken 9864478 times.
✓ Branch 34 taken 1439108 times.
✓ Branch 36 taken 9864478 times.
✓ Branch 37 taken 1439108 times.
✓ Branch 38 taken 10015396 times.
✓ Branch 39 taken 1288190 times.
✓ Branch 41 taken 10015396 times.
✓ Branch 42 taken 1288190 times.
✓ Branch 43 taken 11303586 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 11303586 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 9821285 times.
✓ Branch 49 taken 1482301 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
73670506 if (!(istringEqual(*value, "") || istringEqual(*value, "autosize") || istringEqual(*value, "autocalculate"))) {
221 try {
222
3/3
✓ Branch 1 taken 9821285 times.
✓ Branch 4 taken 9797344 times.
✓ Branch 7 taken 9797344 times.
9821285 result = boost::lexical_cast<double>(*value);
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23941 times.
23941 } catch (const std::exception&) {
224
8/8
✓ Branch 1 taken 23941 times.
✓ Branch 4 taken 23941 times.
✓ Branch 7 taken 23941 times.
✓ Branch 10 taken 23941 times.
✓ Branch 13 taken 23941 times.
✓ Branch 16 taken 23941 times.
✓ Branch 19 taken 23941 times.
✓ Branch 22 taken 23941 times.
23941 LOG(Error, "Could not convert '" << *value << "' to double");
225 23941 }
226 }
227 }
228 11312254 return result;
229 11312254 }
230
231 2 OSOptionalQuantity IdfObject_Impl::getQuantity(unsigned index, bool returnDefault, bool returnIP) const {
232
1/1
✓ Branch 1 taken 2 times.
2 OptionalDouble value = getDouble(index, returnDefault);
233
1/1
✓ Branch 1 taken 2 times.
4 return getQuantityFromDouble(index, value, returnIP);
234 }
235
236 12972 boost::optional<unsigned> IdfObject_Impl::getUnsigned(unsigned index, bool returnDefault) const {
237 12972 OptionalUnsigned result;
238
1/1
✓ Branch 1 taken 12972 times.
12972 OptionalString value = getString(index, returnDefault, false);
239
2/2
✓ Branch 0 taken 12971 times.
✓ Branch 1 taken 1 time.
12972 if (value) {
240
19/41
✓ Branch 1 taken 12971 times.
✓ Branch 4 taken 12971 times.
✓ Branch 7 taken 12971 times.
✓ Branch 9 taken 12971 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 12971 times.
✓ Branch 15 taken 12971 times.
✓ Branch 18 taken 12971 times.
✓ Branch 20 taken 12971 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 12971 times.
✓ Branch 26 taken 12971 times.
✓ Branch 29 taken 12971 times.
✓ Branch 31 taken 12971 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 12971 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 12971 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 12971 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 12971 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 12971 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 12971 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 12971 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
90797 if (!(istringEqual(*value, "") || istringEqual(*value, "autosize") || istringEqual(*value, "autocalculate"))) {
241 try {
242
2/2
✓ Branch 1 taken 12971 times.
✓ Branch 4 taken 12971 times.
12971 auto temp = boost::lexical_cast<double>(*value);
243
2/2
✓ Branch 1 taken 12971 times.
✓ Branch 4 taken 12971 times.
12971 result = boost::numeric_cast<unsigned>(temp);
244 ✗ } catch (const std::exception&) {
245 ✗ LOG(Error, "Could not convert '" << *value << "' to unsigned");
246 ✗ }
247 }
248 }
249 12972 return result;
250 12972 }
251
252 2957706 boost::optional<int> IdfObject_Impl::getInt(unsigned index, bool returnDefault) const {
253 2957706 OptionalInt result;
254
1/1
✓ Branch 1 taken 2957706 times.
2957706 OptionalString value = getString(index, returnDefault, false);
255
2/2
✓ Branch 0 taken 2943921 times.
✓ Branch 1 taken 13785 times.
2957706 if (value) {
256
25/41
✓ Branch 1 taken 2943921 times.
✓ Branch 4 taken 2943921 times.
✓ Branch 7 taken 2943921 times.
✓ Branch 9 taken 2773700 times.
✓ Branch 10 taken 170221 times.
✓ Branch 12 taken 2773700 times.
✓ Branch 15 taken 2773700 times.
✓ Branch 18 taken 2773700 times.
✓ Branch 20 taken 2773700 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 2773700 times.
✓ Branch 26 taken 2773700 times.
✓ Branch 29 taken 2773700 times.
✓ Branch 31 taken 2773700 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 2773700 times.
✓ Branch 34 taken 170221 times.
✓ Branch 36 taken 2773700 times.
✓ Branch 37 taken 170221 times.
✓ Branch 38 taken 2773700 times.
✓ Branch 39 taken 170221 times.
✓ Branch 41 taken 2773700 times.
✓ Branch 42 taken 170221 times.
✓ Branch 43 taken 2943921 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 2943921 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 2773700 times.
✓ Branch 49 taken 170221 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✗ Branch 63 not taken.
✗ Branch 64 not taken.
19926563 if (!(istringEqual(*value, "") || istringEqual(*value, "autosize") || istringEqual(*value, "autocalculate"))) {
257 try {
258
2/2
✓ Branch 1 taken 2773700 times.
✓ Branch 4 taken 2773700 times.
2773700 auto temp = boost::lexical_cast<double>(*value);
259
2/2
✓ Branch 1 taken 2773625 times.
✓ Branch 4 taken 2773625 times.
2773700 result = boost::numeric_cast<int>(temp);
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 75 times.
75 } catch (const std::exception&) {
261
8/8
✓ Branch 1 taken 75 times.
✓ Branch 4 taken 75 times.
✓ Branch 7 taken 75 times.
✓ Branch 10 taken 75 times.
✓ Branch 13 taken 75 times.
✓ Branch 16 taken 75 times.
✓ Branch 19 taken 75 times.
✓ Branch 22 taken 75 times.
75 LOG(Error, "Could not convert '" << *value << "' to int");
262 75 }
263 }
264 }
265 2957706 return result;
266 2957706 }
267
268 2842439 IdfExtensibleGroup IdfObject_Impl::getExtensibleGroup(unsigned groupIndex) const {
269
1/1
✓ Branch 1 taken 2842439 times.
2842439 unsigned n = numFields();
270 2842439 unsigned i = n;
271 2842439 std::shared_ptr<detail::IdfObject_Impl> p;
272
1/1
✓ Branch 2 taken 2842439 times.
2842439 IdfExtensibleGroup eg(p, i);
273
2/3
✓ Branch 1 taken 2842439 times.
✓ Branch 3 taken 2842439 times.
✗ Branch 4 not taken.
2842439 if (m_iddObject.properties().extensible) {
274
5/5
✓ Branch 1 taken 2842439 times.
✓ Branch 4 taken 2842439 times.
✓ Branch 7 taken 2842439 times.
✓ Branch 9 taken 2842393 times.
✓ Branch 10 taken 46 times.
2842439 if (m_iddObject.index(ExtensibleIndex(groupIndex, m_iddObject.properties().numExtensible - 1)) < n) {
275
2/2
✓ Branch 1 taken 2842393 times.
✓ Branch 4 taken 2842393 times.
2842393 i = m_iddObject.index(ExtensibleIndex(groupIndex, 0));
276
2/2
✓ Branch 1 taken 2842393 times.
✓ Branch 5 taken 2842393 times.
2842393 eg = IdfExtensibleGroup(std::const_pointer_cast<IdfObject_Impl>(shared_from_this()), i);
277 }
278 }
279 5684878 return eg;
280 2842439 }
281
282 323011 std::vector<IdfExtensibleGroup> IdfObject_Impl::extensibleGroups() const {
283 323011 IdfExtensibleGroupVector result;
284
3/3
✓ Branch 1 taken 323011 times.
✓ Branch 3 taken 2084623 times.
✓ Branch 4 taken 323011 times.
2407634 for (unsigned i = 0, n = numExtensibleGroups(); i < n; ++i) {
285
2/2
✓ Branch 1 taken 2084623 times.
✓ Branch 4 taken 2084623 times.
2084623 result.push_back(getExtensibleGroup(i));
286 }
287 323011 return result;
288 ✗ }
289
290 // SETTERS
291
292 73 void IdfObject_Impl::setComment(const std::string& comment) {
293 73 setComment(comment, true);
294 73 this->emitChangeSignals();
295 73 }
296
297 73 void IdfObject_Impl::setComment(const std::string& comment, bool /*checkValidity*/) {
298
1/1
✓ Branch 1 taken 73 times.
73 m_comment = makeComment(comment);
299
2/2
✓ Branch 4 taken 73 times.
✓ Branch 7 taken 73 times.
73 m_diffs.push_back(IdfObjectDiff(boost::none, boost::none, boost::none));
300 73 }
301
302 255 bool IdfObject_Impl::setFieldComment(unsigned index, const std::string& cmnt) {
303 255 bool result = setFieldComment(index, cmnt, true);
304
2/2
✓ Branch 0 taken 251 times.
✓ Branch 1 taken 4 times.
255 if (result) {
305 251 this->emitChangeSignals();
306 }
307 255 return result;
308 }
309
310 255 bool IdfObject_Impl::setFieldComment(unsigned index, const std::string& cmnt, bool /*checkValidity*/) {
311
2/2
✓ Branch 1 taken 251 times.
✓ Branch 2 taken 4 times.
255 if (index < m_fields.size()) {
312
1/2
✓ Branch 1 taken 251 times.
✗ Branch 2 not taken.
251 if (index >= m_fieldComments.size()) {
313 251 m_fieldComments.resize(index + 1);
314 }
315
316
1/1
✓ Branch 1 taken 251 times.
251 m_fieldComments[index] = makeComment(cmnt);
317
318
5/5
✓ Branch 2 taken 251 times.
✓ Branch 6 taken 251 times.
✓ Branch 9 taken 251 times.
✓ Branch 12 taken 251 times.
✓ Branch 15 taken 251 times.
251 m_diffs.push_back(IdfObjectDiff(index, m_fields[index], m_fields[index]));
319
320 251 return true;
321 }
322 4 return false;
323 }
324
325 32795 boost::optional<std::string> IdfObject_Impl::setName(const std::string& newName) {
326 32795 OptionalString result = IdfObject_Impl::setName(newName, true);
327
2/2
✓ Branch 0 taken 32792 times.
✓ Branch 1 taken 3 times.
32795 if (result) {
328
1/1
✓ Branch 1 taken 32792 times.
32792 this->emitChangeSignals();
329 }
330 32795 return result;
331 ✗ }
332
333 246676 boost::optional<std::string> IdfObject_Impl::setName(const std::string& _newName, bool /*checkValidity*/) {
334
1/1
✓ Branch 1 taken 246676 times.
246676 std::string newName = encodeString(_newName);
335
336
4/4
✓ Branch 1 taken 246676 times.
✓ Branch 4 taken 246676 times.
✓ Branch 6 taken 1156 times.
✓ Branch 7 taken 245520 times.
246676 switch (m_iddObject.type().value()) {
337 // get all EMS idd object types in both E+ and OS IDD
338 1156 case openstudio::IddObjectType::EnergyManagementSystem_Actuator:; // deliberate fall through
339 case openstudio::IddObjectType::OS_EnergyManagementSystem_Actuator:; // deliberate fall through
340 case openstudio::IddObjectType::EnergyManagementSystem_ConstructionIndexVariable:; // TODO uncomment when wrapped
341 case openstudio::IddObjectType::OS_EnergyManagementSystem_ConstructionIndexVariable:; // deliberate fall through
342 case openstudio::IddObjectType::EnergyManagementSystem_CurveOrTableIndexVariable:; // TODO uncomment when wrapped
343 case openstudio::IddObjectType::OS_EnergyManagementSystem_CurveOrTableIndexVariable:; // deliberate fall through
344 case openstudio::IddObjectType::EnergyManagementSystem_GlobalVariable:; // deliberate fall through
345 case openstudio::IddObjectType::OS_EnergyManagementSystem_GlobalVariable:; // deliberate fall through
346 case openstudio::IddObjectType::EnergyManagementSystem_InternalVariable:; // deliberate fall through
347 case openstudio::IddObjectType::OS_EnergyManagementSystem_InternalVariable:; // deliberate fall through
348 case openstudio::IddObjectType::EnergyManagementSystem_Program:; // deliberate fall through
349 case openstudio::IddObjectType::OS_EnergyManagementSystem_Program:; // deliberate fall through
350 case openstudio::IddObjectType::EnergyManagementSystem_Sensor:; // deliberate fall through
351 case openstudio::IddObjectType::OS_EnergyManagementSystem_Sensor:; // deliberate fall through
352 case openstudio::IddObjectType::EnergyManagementSystem_Subroutine:; // deliberate fall through
353 case openstudio::IddObjectType::OS_EnergyManagementSystem_Subroutine:; // deliberate fall through
354 case openstudio::IddObjectType::EnergyManagementSystem_TrendVariable:; // deliberate fall through
355 case openstudio::IddObjectType::OS_EnergyManagementSystem_TrendVariable:; // deliberate fall through
356 // replace � � with �_�
357 1156 std::replace(newName.begin(), newName.end(), ' ', '_');
358 1156 break;
359 //case openstudio::IddObjectType::EnergyManagementSystem_OutputVariable:; // deliberate fall through
360 //case openstudio::IddObjectType::OS_EnergyManagementSystem_OutputVariable:; // deliberate fall through
361 //TODO Enforce Title-Case
362 245520 default:
363 // no-op
364 245520 break;
365 }
366
367 // check Idd to see if this object has a name
368
3/3
✓ Branch 1 taken 246676 times.
✓ Branch 3 taken 246673 times.
✓ Branch 4 taken 3 times.
493352 if (OptionalUnsigned index = m_iddObject.nameFieldIndex()) {
369 // if so, change the name, or create it
370
1/1
✓ Branch 1 taken 246673 times.
246673 unsigned n = numFields();
371
1/1
✓ Branch 1 taken 246673 times.
246673 unsigned i = *index;
372
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 246673 times.
✗ Branch 3 not taken.
246673 OS_ASSERT(i < 2u);
373
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 246671 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
246673 if (n == 0 && i == 1) {
374 ✗ OS_ASSERT(!m_handle.isNull());
375 ✗ m_fields.push_back(toString(m_handle));
376 ✗ m_diffs.push_back(IdfObjectDiff(0u, boost::none, m_fields.back()));
377 }
378
1/1
✓ Branch 1 taken 246673 times.
246673 n = numFields();
379
2/2
✓ Branch 0 taken 242472 times.
✓ Branch 1 taken 4201 times.
246673 if (i < n) {
380
1/1
✓ Branch 2 taken 242472 times.
242472 std::string oldName = m_fields[i];
381
1/1
✓ Branch 2 taken 242472 times.
242472 m_fields[i] = newName;
382
5/5
✓ Branch 1 taken 242472 times.
✓ Branch 4 taken 242472 times.
✓ Branch 7 taken 242472 times.
✓ Branch 10 taken 242472 times.
✓ Branch 13 taken 242472 times.
242472 m_diffs.push_back(IdfObjectDiff(i, oldName, newName));
383 242472 } else {
384
1/1
✓ Branch 1 taken 4201 times.
4201 m_fields.push_back(newName);
385
4/4
✓ Branch 1 taken 4201 times.
✓ Branch 5 taken 4201 times.
✓ Branch 8 taken 4201 times.
✓ Branch 11 taken 4201 times.
4201 m_diffs.push_back(IdfObjectDiff(i, boost::none, newName));
386 }
387 //return decoded string since we might have made changes to it if its an EMS object.
388
1/1
✓ Branch 1 taken 246673 times.
246673 newName = decodeString(newName);
389
1/1
✓ Branch 1 taken 246673 times.
246673 return newName; // success!
390 }
391 3 return boost::none; // no name
392 246676 }
393
394 ✗ boost::optional<std::string> IdfObject_Impl::createName() {
395 ✗ return IdfObject_Impl::createName(true);
396 }
397
398 2 boost::optional<std::string> IdfObject_Impl::createName(bool overwrite) {
399
2/3
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
4 if (OptionalUnsigned index = m_iddObject.nameFieldIndex()) {
400
1/1
✓ Branch 1 taken 2 times.
2 OptionalString oName = name();
401
7/9
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 1 time.
✓ Branch 12 taken 1 time.
2 if (!oName || oName->empty() || overwrite) {
402
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 std::string newName = createUniqueName(m_iddObject.name());
403
1/1
✓ Branch 1 taken 1 time.
1 return setName(newName);
404 1 }
405 2 }
406 1 return boost::none;
407 }
408
409 1079431 bool IdfObject_Impl::setString(unsigned index, const std::string& value) {
410 1079431 bool result = IdfObject_Impl::setString(index, value, true);
411
2/2
✓ Branch 0 taken 1079429 times.
✓ Branch 1 taken 2 times.
1079431 if (result) {
412 1079429 this->emitChangeSignals();
413 }
414 1079431 return result;
415 }
416
417 4626981 bool IdfObject_Impl::setString(unsigned index, const std::string& _value, bool checkValidity) {
418
1/1
✓ Branch 1 taken 4626981 times.
4626981 std::string value = encodeString(_value);
419
420
9/9
✓ Branch 1 taken 4626981 times.
✓ Branch 3 taken 3889808 times.
✓ Branch 4 taken 737173 times.
✓ Branch 6 taken 3889808 times.
✓ Branch 9 taken 3889808 times.
✓ Branch 11 taken 14195 times.
✓ Branch 12 taken 3875613 times.
✓ Branch 13 taken 14195 times.
✓ Branch 14 taken 4612786 times.
4626981 if (m_iddObject.hasNameField() && (index == m_iddObject.nameFieldIndex().get())) {
421
1/1
✓ Branch 1 taken 14195 times.
14195 return IdfObject_Impl::setName(value, checkValidity).has_value();
422 }
423
424 // push fields and groups if necessary and possible
425
8/8
✓ Branch 1 taken 4612786 times.
✓ Branch 3 taken 1672862 times.
✓ Branch 4 taken 2939924 times.
✓ Branch 6 taken 1672862 times.
✓ Branch 8 taken 1672859 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 4612783 times.
✓ Branch 11 taken 3 times.
4612786 if (m_iddObject.isNonextensibleField(index) || m_iddObject.isExtensibleField(index)) {
426 4612783 bool result = true;
427 4612783 boost::optional<std::string> oldValue;
428 4612783 unsigned n = m_fields.size();
429 4612783 unsigned nn = n;
430 4612783 unsigned diffSize = m_diffs.size();
431
1/1
✓ Branch 1 taken 4612783 times.
4612783 unsigned iddn = m_iddObject.numFields();
432
433
2/2
✓ Branch 1 taken 376355 times.
✓ Branch 2 taken 4236428 times.
4612783 if (index >= m_fields.size()) {
434
5/6
✓ Branch 0 taken 683259 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 387459 times.
✓ Branch 3 taken 295800 times.
✓ Branch 4 taken 306904 times.
✓ Branch 5 taken 80555 times.
683259 while (result && (index >= nn) && (nn < iddn)) {
435 // push regular fields
436
3/5
✓ Branch 0 taken 306904 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 306904 times.
✓ Branch 5 taken 306904 times.
✗ Branch 6 not taken.
306904 result = result && this->pushString(checkValidity);
437 306904 nn = m_fields.size();
438 }
439
3/4
✓ Branch 0 taken 456910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80555 times.
✓ Branch 3 taken 376355 times.
456910 while (result && (index >= nn)) {
440 // push extensible fields
441
6/14
✓ Branch 0 taken 80555 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 80555 times.
✓ Branch 7 taken 80555 times.
✓ Branch 9 taken 80555 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 80555 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 80555 times.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
80555 result = result && !this->pushExtensibleGroup(StringVector(), checkValidity).empty();
442 80555 nn = m_fields.size();
443 }
444 } else {
445
1/1
✓ Branch 2 taken 4236428 times.
4236428 oldValue = m_fields[index];
446 }
447
448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4612783 times.
4612783 if (!result) {
449 // remove diffs
450 ✗ m_diffs.resize(diffSize);
451
452 // resize fields
453 ✗ m_fields.resize(n);
454 ✗ if (m_fieldComments.size() > n) {
455 ✗ m_fieldComments.resize(n);
456 }
457
458 ✗ return false;
459 }
460
461
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 4612783 times.
✗ Branch 4 not taken.
4612783 OS_ASSERT(index < m_fields.size());
462
463
1/1
✓ Branch 2 taken 4612783 times.
4612783 m_fields[index] = value;
464
1/1
✓ Branch 1 taken 4612783 times.
4612783 m_diffs.emplace_back(index, oldValue, value);
465 4612783 return result;
466 4612783 }
467 3 return false;
468 4626981 }
469
470 439626 bool IdfObject_Impl::setDouble(unsigned index, double value) {
471 439626 bool result = setDouble(index, value, true);
472
2/2
✓ Branch 0 taken 439181 times.
✓ Branch 1 taken 445 times.
439626 if (result) {
473 439181 this->emitChangeSignals();
474 }
475 439626 return result;
476 }
477
478 444050 bool IdfObject_Impl::setDouble(unsigned index, double value, bool checkValidity) {
479 try {
480
2/2
✓ Branch 1 taken 444050 times.
✓ Branch 4 taken 444050 times.
444050 return setString(index, toString(value), checkValidity);
481 ✗ } catch (...) {
482 ✗ return false;
483 ✗ }
484 }
485
486 1 bool IdfObject_Impl::setQuantity(unsigned index, const Quantity& q) {
487 1 bool result = setQuantity(index, q, true);
488
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (result) {
489 1 this->emitChangeSignals();
490 }
491 1 return result;
492 }
493
494 1 bool IdfObject_Impl::setQuantity(unsigned index, const Quantity& q, bool checkValidity) {
495
1/1
✓ Branch 1 taken 1 time.
1 OptionalDouble value = getDoubleFromQuantity(index, q);
496
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!value) {
497 ✗ return false;
498 }
499
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 return setDouble(index, *value, checkValidity);
500 }
501
502 51151 bool IdfObject_Impl::setUnsigned(unsigned index, unsigned value) {
503 51151 bool result = setUnsigned(index, value, true);
504
2/2
✓ Branch 0 taken 51150 times.
✓ Branch 1 taken 1 time.
51151 if (result) {
505 51150 this->emitChangeSignals();
506 }
507 51151 return result;
508 }
509
510 51151 bool IdfObject_Impl::setUnsigned(unsigned index, unsigned value, bool checkValidity) {
511 try {
512
1/1
✓ Branch 1 taken 51151 times.
51151 auto str = boost::lexical_cast<std::string>(value);
513
1/1
✓ Branch 1 taken 51151 times.
51151 return setString(index, str, checkValidity);
514 51151 } catch (...) {
515 ✗ return false;
516 ✗ }
517 }
518
519 36648 bool IdfObject_Impl::setInt(unsigned index, int value) {
520 36648 bool result = setInt(index, value, true);
521
2/2
✓ Branch 0 taken 36596 times.
✓ Branch 1 taken 52 times.
36648 if (result) {
522 36596 this->emitChangeSignals();
523 }
524 36648 return result;
525 }
526
527 43462 bool IdfObject_Impl::setInt(unsigned index, int value, bool checkValidity) {
528 try {
529
1/1
✓ Branch 1 taken 43462 times.
43462 auto str = boost::lexical_cast<std::string>(value);
530
1/1
✓ Branch 1 taken 43462 times.
43462 return setString(index, str, checkValidity);
531 43462 } catch (...) {
532 ✗ return false;
533 ✗ }
534 }
535
536 ✗ bool IdfObject_Impl::pushString() {
537 ✗ bool result = IdfObject_Impl::pushString(std::string(), true);
538 ✗ if (result) {
539 ✗ this->emitChangeSignals();
540 }
541 ✗ return result;
542 }
543
544 338495 bool IdfObject_Impl::pushString(bool checkValidity) {
545
1/1
✓ Branch 2 taken 338495 times.
338495 return IdfObject_Impl::pushString(std::string(), checkValidity);
546 }
547
548 ✗ bool IdfObject_Impl::pushString(const std::string& value) {
549 ✗ bool result = IdfObject_Impl::pushString(value, true);
550 ✗ if (result) {
551 ✗ this->emitChangeSignals();
552 }
553 ✗ return result;
554 }
555
556 472935 bool IdfObject_Impl::pushString(const std::string& value, bool checkValidity) {
557 // get new index
558 472935 unsigned index = m_fields.size();
559
7/9
✓ Branch 1 taken 472935 times.
✓ Branch 3 taken 338424 times.
✓ Branch 4 taken 134511 times.
✓ Branch 6 taken 338424 times.
✓ Branch 9 taken 338424 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 338424 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 472935 times.
472935 if (m_iddObject.hasNameField() && (index == m_iddObject.nameFieldIndex().get())) {
560 ✗ return IdfObject_Impl::setName(value, checkValidity).has_value();
561 }
562
563 // ok if nonextensible, or extensible w/ group size 1
564
10/11
✓ Branch 1 taken 472935 times.
✓ Branch 3 taken 738 times.
✓ Branch 4 taken 472197 times.
✓ Branch 6 taken 738 times.
✓ Branch 8 taken 738 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 738 times.
✓ Branch 13 taken 735 times.
✓ Branch 14 taken 3 times.
✓ Branch 15 taken 472932 times.
✓ Branch 16 taken 3 times.
472935 if (m_iddObject.isNonextensibleField(index) || (m_iddObject.isExtensibleField(index) && (m_iddObject.properties().numExtensible == 1))) {
565
1/1
✓ Branch 1 taken 472932 times.
472932 m_fields.push_back(value);
566
4/4
✓ Branch 1 taken 472932 times.
✓ Branch 5 taken 472932 times.
✓ Branch 8 taken 472932 times.
✓ Branch 11 taken 472932 times.
472932 m_diffs.push_back(IdfObjectDiff(index, boost::none, value));
567 472932 return true;
568 }
569 3 return false;
570 }
571
572 67181 IdfExtensibleGroup IdfObject_Impl::pushExtensibleGroup(const std::vector<std::string>& values) {
573 67181 IdfExtensibleGroup result = IdfObject_Impl::pushExtensibleGroup(values, true);
574
3/3
✓ Branch 1 taken 67181 times.
✓ Branch 3 taken 67154 times.
✓ Branch 4 taken 27 times.
67181 if (!result.empty()) {
575
1/1
✓ Branch 1 taken 67154 times.
67154 this->emitChangeSignals();
576 }
577 67181 return result;
578 ✗ }
579
580 511163 IdfExtensibleGroup IdfObject_Impl::pushExtensibleGroup(const std::vector<std::string>& values, bool checkValidity) {
581
1/1
✓ Branch 1 taken 511163 times.
511163 unsigned groupSize = m_iddObject.properties().numExtensible;
582
1/1
✓ Branch 1 taken 511163 times.
511163 unsigned n = numFields();
583 511163 IdfObject_ImplPtr p = nullptr;
584
1/1
✓ Branch 2 taken 511163 times.
511163 IdfExtensibleGroup result(p, n);
585
586
6/6
✓ Branch 1 taken 382405 times.
✓ Branch 2 taken 128758 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 382403 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 511161 times.
511163 if (!values.empty() && (values.size() != groupSize)) {
587 2 return result;
588 }
589
590
1/1
✓ Branch 1 taken 511161 times.
511161 StringVector wValues = values; // copy so can resize empty vector
591
1/1
✓ Branch 1 taken 511161 times.
511161 OptionalUnsigned mf = maxFields();
592 511161 unsigned diffSize = m_diffs.size();
593
594 // push fields as needed
595
1/1
✓ Branch 1 taken 511161 times.
511161 unsigned iddn = m_iddObject.numFields();
596
2/2
✓ Branch 0 taken 9069 times.
✓ Branch 1 taken 502092 times.
511161 if (n < iddn) {
597
2/2
✓ Branch 1 taken 9069 times.
✓ Branch 4 taken 9069 times.
18138 bool ok = this->setString(iddn - 1, "", checkValidity);
598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9069 times.
9069 if (!ok) {
599 // remove the diffs
600 ✗ m_diffs.resize(diffSize);
601
602 // resize the fields
603 ✗ m_fields.resize(n);
604 ✗ if (m_fieldComments.size() > n) {
605 ✗ m_fieldComments.resize(n);
606 }
607 ✗ return result;
608 }
609 }
610
611
1/1
✓ Branch 1 taken 511161 times.
511161 n = numFields();
612
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 511161 times.
✗ Branch 3 not taken.
511161 OS_ASSERT(n >= iddn);
613
614 // needs to be extensible, have all non-extensible fields defined, and not violate maxFields.
615
9/9
✓ Branch 0 taken 511159 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 11230 times.
✓ Branch 4 taken 499929 times.
✓ Branch 6 taken 11230 times.
✓ Branch 8 taken 11210 times.
✓ Branch 9 taken 20 times.
✓ Branch 10 taken 511139 times.
✓ Branch 11 taken 22 times.
511161 if ((groupSize > 0) && (!mf || (n + groupSize <= *mf))) {
616
617
2/4
✓ Branch 1 taken 511139 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 511139 times.
✗ Branch 6 not taken.
511139 OS_ASSERT(m_iddObject.properties().extensible);
618
619
2/2
✓ Branch 1 taken 128736 times.
✓ Branch 2 taken 382403 times.
511139 if (wValues.empty()) {
620
1/1
✓ Branch 1 taken 128736 times.
128736 wValues.resize(groupSize);
621 }
622
623
1/1
✓ Branch 1 taken 511139 times.
511139 m_fields.resize(n + groupSize);
624
625
2/2
✓ Branch 0 taken 1349322 times.
✓ Branch 1 taken 511135 times.
1860457 for (unsigned i = 0; i < groupSize; ++i) {
626
627
1/1
✓ Branch 2 taken 1349322 times.
1349322 bool ok = setString(n + i, wValues[i], checkValidity);
628
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1349318 times.
1349322 if (!ok) {
629 // remove the diffs
630
1/1
✓ Branch 1 taken 4 times.
4 m_diffs.resize(diffSize);
631
632 // resize the fields
633
1/1
✓ Branch 1 taken 4 times.
4 m_fields.resize(n);
634
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (m_fieldComments.size() > n) {
635 ✗ m_fieldComments.resize(n);
636 }
637 4 return result;
638 }
639 }
640
641
2/2
✓ Branch 1 taken 511135 times.
✓ Branch 4 taken 511135 times.
511135 result = getExtensibleGroup(numExtensibleGroups() - 1);
642
2/4
✓ Branch 1 taken 511135 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 511135 times.
✗ Branch 6 not taken.
511135 OS_ASSERT(!result.empty());
643
3/5
✓ Branch 1 taken 511135 times.
✓ Branch 4 taken 511135 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 511135 times.
✗ Branch 9 not taken.
511135 OS_ASSERT(result.groupIndex() == m_iddObject.extensibleIndex(n).group);
644 }
645
646 511157 return result;
647 511163 }
648
649 35204 IdfExtensibleGroup IdfObject_Impl::insertExtensibleGroup(unsigned groupIndex, const std::vector<std::string>& values) {
650 35204 IdfExtensibleGroup result = insertExtensibleGroup(groupIndex, values, true);
651
3/3
✓ Branch 1 taken 35204 times.
✓ Branch 3 taken 35200 times.
✓ Branch 4 taken 4 times.
35204 if (!result.empty()) {
652
1/1
✓ Branch 1 taken 35200 times.
35200 this->emitChangeSignals();
653 }
654 35204 return result;
655 ✗ }
656
657 35204 IdfExtensibleGroup IdfObject_Impl::insertExtensibleGroup(unsigned groupIndex, const std::vector<std::string>& values, bool checkValidity) {
658 // if really a push request, send it there
659
3/3
✓ Branch 1 taken 35204 times.
✓ Branch 3 taken 12323 times.
✓ Branch 4 taken 22881 times.
35204 if (groupIndex == numExtensibleGroups()) {
660
1/1
✓ Branch 1 taken 12323 times.
12323 return pushExtensibleGroup(values, checkValidity);
661 }
662
663 // now have groupIndex != numExtensibleGroups()
664
1/1
✓ Branch 1 taken 22881 times.
22881 unsigned groupSize = m_iddObject.properties().numExtensible;
665
1/1
✓ Branch 1 taken 22881 times.
22881 unsigned n = numFields();
666 22881 IdfObject_ImplPtr p;
667
1/1
✓ Branch 2 taken 22881 times.
22881 IdfExtensibleGroup result(p, n);
668 // nothing to do if not extensible, groupIndex invalid, or values invalid
669
6/7
✓ Branch 0 taken 22881 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 22881 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 22879 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 22879 times.
22881 if ((groupSize == 0) || (groupIndex > numExtensibleGroups())) {
670 2 return result;
671 }
672
4/6
✓ Branch 1 taken 22858 times.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 22858 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 22879 times.
22879 if (!values.empty() && (values.size() != groupSize)) {
673 ✗ return result;
674 }
675
676 // record diffs at start
677 22879 unsigned diffSize = m_diffs.size();
678
679 // from now on, groupIndex < numExtensibleGroups(), and numExtensibleGroups() > 0
680
1/1
✓ Branch 1 taken 22879 times.
22879 OptionalUnsigned mf = maxFields();
681 // needs to have all non-extensible fields defined, and not violate maxFields.
682
7/10
✓ Branch 1 taken 22879 times.
✓ Branch 3 taken 22879 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 26 times.
✓ Branch 7 taken 22853 times.
✓ Branch 9 taken 26 times.
✓ Branch 11 taken 26 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 22879 times.
✗ Branch 14 not taken.
22879 if ((n >= m_iddObject.numFields()) && (!mf || (n + groupSize <= *mf))) {
683
2/4
✓ Branch 1 taken 22879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22879 times.
✗ Branch 6 not taken.
22879 OS_ASSERT(m_iddObject.properties().extensible);
684
685
1/1
✓ Branch 1 taken 22879 times.
22879 StringVector wValues = values;
686
2/2
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 22858 times.
22879 if (wValues.empty()) {
687
1/1
✓ Branch 1 taken 21 times.
21 wValues.resize(groupSize);
688 }
689
690 // push a new group on the end
691
1/1
✓ Branch 1 taken 22879 times.
22879 unsigned i = numExtensibleGroups() - 1;
692
1/1
✓ Branch 1 taken 22879 times.
22879 IdfExtensibleGroup eg = getExtensibleGroup(i);
693
2/4
✓ Branch 1 taken 22879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22879 times.
✗ Branch 6 not taken.
22879 OS_ASSERT(!eg.empty());
694
2/2
✓ Branch 1 taken 22879 times.
✓ Branch 4 taken 22879 times.
22879 IdfExtensibleGroup temp = pushExtensibleGroup(eg.fieldsWithHandles(), checkValidity);
695
2/3
✓ Branch 1 taken 22879 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22879 times.
22879 if (temp.empty()) {
696 ✗ OS_ASSERT(numFields() == n);
697 ✗ OS_ASSERT(m_diffs.size() == diffSize);
698
699 ✗ return result;
700 }
701
702 // copy values from group i to i+1 down to and including groupIndex
703 22879 bool ok = true;
704
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 22879 times.
22896 while (i > groupIndex) {
705 17 --i;
706
1/1
✓ Branch 1 taken 17 times.
17 IdfExtensibleGroup peg = getExtensibleGroup(i);
707
2/4
✓ Branch 1 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 17 times.
✗ Branch 6 not taken.
17 OS_ASSERT(!peg.empty());
708
2/2
✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
17 ok = eg.setFields(peg.fieldsWithHandles(), false);
709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (!ok) {
710 // roll back
711 ✗ i += 2;
712 ✗ while (i < numExtensibleGroups() - 1) {
713 ✗ peg = getExtensibleGroup(i);
714 ✗ OS_ASSERT(!peg.empty());
715 ✗ eg = getExtensibleGroup(i + 1);
716 ✗ OS_ASSERT(!eg.empty());
717 ✗ peg.setFields(eg.fieldsWithHandles(), false);
718 ✗ ++i;
719 }
720 ✗ popExtensibleGroup(false);
721
722 // remove the diffs
723 ✗ m_diffs.resize(diffSize);
724
725 ✗ return result;
726 }
727 17 eg = peg;
728 17 }
729
730 // now set the values at this group index
731
1/1
✓ Branch 1 taken 22879 times.
22879 ok = eg.setFields(wValues, checkValidity);
732
733
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 22878 times.
22879 if (!ok) {
734 1 i = groupIndex + 1;
735
1/1
✓ Branch 1 taken 1 time.
1 IdfExtensibleGroup peg = getExtensibleGroup(i);
736
2/4
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
1 OS_ASSERT(!peg.empty());
737
3/3
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
2 while (i < numExtensibleGroups() - 1) {
738 1 ++i;
739
1/1
✓ Branch 1 taken 1 time.
1 eg = getExtensibleGroup(i);
740
2/4
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
1 OS_ASSERT(!eg.empty());
741
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 peg.setFields(eg.fieldsWithHandles(), false);
742 1 peg = eg;
743 }
744
1/1
✓ Branch 1 taken 1 time.
1 popExtensibleGroup(false);
745
746 // remove the diffs
747
1/1
✓ Branch 1 taken 1 time.
1 m_diffs.resize(diffSize);
748
749 1 return result;
750 1 }
751
752 22878 result = eg;
753
2/4
✓ Branch 1 taken 22878 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22878 times.
✗ Branch 6 not taken.
22878 OS_ASSERT(!result.empty());
754
2/4
✓ Branch 1 taken 22878 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22878 times.
✗ Branch 6 not taken.
22878 OS_ASSERT(numFields() == n + groupSize);
755 22881 }
756
757 22878 return result;
758 22881 }
759
760 4 std::vector<std::string> IdfObject_Impl::popExtensibleGroup() {
761 4 StringVector result = IdfObject_Impl::popExtensibleGroup(true);
762
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 time.
4 if (!result.empty()) {
763
1/1
✓ Branch 1 taken 3 times.
3 this->emitChangeSignals();
764 }
765 4 return result;
766 ✗ }
767
768 /** Pops the final extensible group from the object, if possible. Returns the popped data if
769 * successful. Otherwise, the returned vector will be empty. */
770 107621 std::vector<std::string> IdfObject_Impl::popExtensibleGroup(bool /*checkValidity*/) {
771
772 107621 unsigned groupSize = m_iddObject.properties().numExtensible;
773 107621 unsigned numBeforePop = numFields();
774 107621 unsigned numAfterPop = numBeforePop - groupSize;
775 107621 StringVector result;
776 // must be extensible object, with some extensible fields
777
7/7
✓ Branch 0 taken 107607 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 107607 times.
✓ Branch 5 taken 106911 times.
✓ Branch 6 taken 696 times.
✓ Branch 7 taken 106911 times.
✓ Branch 8 taken 710 times.
107621 if ((groupSize > 0) && (numAfterPop >= m_iddObject.numFields())) {
778
2/2
✓ Branch 1 taken 106911 times.
✓ Branch 4 taken 106911 times.
106911 IdfExtensibleGroup egToPop = getExtensibleGroup(numExtensibleGroups() - 1);
779
2/4
✓ Branch 1 taken 106911 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 106911 times.
✗ Branch 6 not taken.
106911 OS_ASSERT(!egToPop.empty());
780
1/1
✓ Branch 1 taken 106911 times.
106911 UnsignedVector indices = egToPop.mf_indices();
781
1/1
✓ Branch 1 taken 106911 times.
106911 result = egToPop.fieldsWithHandles();
782
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 106911 times.
✗ Branch 4 not taken.
106911 OS_ASSERT(result.size() == groupSize);
783
784 // record diffs for each field going backwards
785
2/2
✓ Branch 0 taken 318562 times.
✓ Branch 1 taken 106911 times.
425473 for (unsigned i = 0; i < groupSize; ++i) {
786
4/4
✓ Branch 3 taken 318562 times.
✓ Branch 6 taken 318562 times.
✓ Branch 9 taken 318562 times.
✓ Branch 12 taken 318562 times.
318562 m_diffs.push_back(IdfObjectDiff(numBeforePop - 1 - i, result[i], boost::none));
787 }
788
789
1/1
✓ Branch 1 taken 106911 times.
106911 m_fields.resize(numAfterPop);
790
2/2
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 106901 times.
106911 if (m_fieldComments.size() > m_fields.size()) {
791
1/1
✓ Branch 1 taken 10 times.
10 m_fieldComments.resize(numAfterPop);
792 }
793
2/4
✓ Branch 1 taken 106911 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 106911 times.
✗ Branch 6 not taken.
106911 OS_ASSERT(egToPop.empty());
794 106911 }
795
796 107621 return result;
797 ✗ }
798
799 /** Erases the extensible group at groupIndex, if possible. Returns the erased data, and
800 * preserves the relative order of the remaining data if successful. Otherwise, the returned
801 * vector will be empty. */
802 415 std::vector<std::string> IdfObject_Impl::eraseExtensibleGroup(unsigned groupIndex) {
803 415 StringVector result = eraseExtensibleGroup(groupIndex, true);
804
2/2
✓ Branch 1 taken 414 times.
✓ Branch 2 taken 1 time.
415 if (!result.empty()) {
805
1/1
✓ Branch 1 taken 414 times.
414 this->emitChangeSignals();
806 }
807 415 return result;
808 ✗ }
809
810 415 std::vector<std::string> IdfObject_Impl::eraseExtensibleGroup(unsigned groupIndex, bool checkValidity) {
811 415 StringVector result;
812
3/3
✓ Branch 1 taken 415 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 414 times.
415 if (groupIndex >= numExtensibleGroups()) {
813 1 return result;
814 }
815
2/2
✓ Branch 1 taken 414 times.
✓ Branch 4 taken 414 times.
414 UnsignedVector indices = getExtensibleGroup(groupIndex).mf_indices();
816
817 // start at bottom
818
1/1
✓ Branch 1 taken 414 times.
414 result = popExtensibleGroup(false);
819
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
414 if (result.empty()) {
820 ✗ return result;
821 }
822
823 // record diffs at start
824 414 unsigned diffSize = m_diffs.size();
825
826 414 bool ok = true;
827 // pop was successful. roll up until overwrite groupIndex
828
3/3
✓ Branch 1 taken 414 times.
✓ Branch 3 taken 183 times.
✓ Branch 4 taken 414 times.
597 for (int i = numExtensibleGroups() - 1; i >= static_cast<int>(groupIndex); --i) {
829
1/1
✓ Branch 1 taken 183 times.
183 StringVector temp = result;
830
1/1
✓ Branch 1 taken 183 times.
183 IdfExtensibleGroup eg = getExtensibleGroup(i);
831
2/4
✓ Branch 1 taken 183 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 183 times.
✗ Branch 6 not taken.
183 OS_ASSERT(!eg.empty());
832
1/1
✓ Branch 1 taken 183 times.
183 result = eg.fieldsWithHandles();
833
1/1
✓ Branch 1 taken 183 times.
183 ok = eg.setFields(temp, checkValidity);
834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 183 times.
183 if (!ok) {
835 // roll back changes and return
836 ✗ for (unsigned j = i + 1, n = numExtensibleGroups(); j < n; ++j) {
837 ✗ eg = getExtensibleGroup(j);
838 ✗ OS_ASSERT(!eg.empty());
839 ✗ result = eg.fieldsWithHandles();
840 ✗ OS_ASSERT(result.size() == temp.size());
841 ✗ eg.setFields(temp, false);
842 ✗ temp = result;
843 }
844 ✗ eg = pushExtensibleGroup(temp, false);
845 ✗ OS_ASSERT(!eg.empty());
846
847 // remove the diffs
848 ✗ m_diffs.resize(diffSize);
849
850 ✗ return {};
851 }
852 183 }
853
854
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
✗ Branch 3 not taken.
414 OS_ASSERT(ok);
855 414 return result;
856 415 }
857
858 /** Pops all \link IdfExtensibleGroup IdfExtensibleGroups\endlink from the object, if possible.
859 * Returns popped data if successful. Otherwise, the returned vector will be empty. */
860 17937 std::vector<std::vector<std::string>> IdfObject_Impl::clearExtensibleGroups() {
861 17937 std::vector<StringVector> result = clearExtensibleGroups(true);
862
2/2
✓ Branch 1 taken 5244 times.
✓ Branch 2 taken 12693 times.
17937 if (!result.empty()) {
863
1/1
✓ Branch 1 taken 5244 times.
5244 this->emitChangeSignals();
864 }
865 17937 return result;
866 ✗ }
867
868 71190 std::vector<std::vector<std::string>> IdfObject_Impl::clearExtensibleGroups(bool checkValidity) {
869
870 // data to restore if cannot delete all groups
871 71190 std::vector<StringVector> rollbackValues;
872 71190 std::vector<StringVector> rollbackComments;
873
874
1/1
✓ Branch 1 taken 71190 times.
71190 unsigned gn = numExtensibleGroups();
875
2/2
✓ Branch 0 taken 44889 times.
✓ Branch 1 taken 26301 times.
71190 if (gn == 0) {
876 44889 return rollbackValues;
877 }
878
879 // record diffs at start
880 26301 unsigned diffSize = m_diffs.size();
881
882 // loop through groups
883 26301 UnsignedVector indices;
884
2/2
✓ Branch 0 taken 104083 times.
✓ Branch 1 taken 26300 times.
130383 while (gn > 0) {
885 // get this group's data
886
1/1
✓ Branch 1 taken 104083 times.
104083 IdfExtensibleGroup eg = getExtensibleGroup(gn - 1);
887
2/4
✓ Branch 1 taken 104083 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 104083 times.
✗ Branch 6 not taken.
104083 OS_ASSERT(!eg.empty());
888
2/2
✓ Branch 1 taken 26301 times.
✓ Branch 2 taken 77782 times.
104083 if (indices.empty()) {
889
1/1
✓ Branch 1 taken 26301 times.
26301 indices = eg.mf_indices();
890 }
891
2/2
✓ Branch 1 taken 104083 times.
✓ Branch 4 taken 104083 times.
104083 rollbackValues.push_back(eg.fieldsWithHandles());
892
2/2
✓ Branch 1 taken 104083 times.
✓ Branch 4 taken 104083 times.
104083 rollbackComments.push_back(eg.fieldComments());
893 // try to pop
894
1/1
✓ Branch 1 taken 104083 times.
104083 StringVector result = popExtensibleGroup(checkValidity);
895
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 104082 times.
104083 if (result.empty()) {
896 // unsuccessful--restore cleared data
897 1 rollbackValues.pop_back();
898 1 rollbackComments.pop_back();
899
2/4
✓ Branch 1 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 6 not taken.
1 OS_ASSERT(gn == numExtensibleGroups());
900 // add back groups already popped
901
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
2 while (!rollbackValues.empty()) {
902
1/1
✓ Branch 2 taken 1 time.
1 IdfExtensibleGroup pushed = pushExtensibleGroup(rollbackValues.back(), false);
903 1 unsigned fieldIndex = 0;
904
2/2
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 time.
4 for (const std::string& cmnt : rollbackComments.back()) {
905
1/1
✓ Branch 1 taken 3 times.
3 pushed.setFieldComment(fieldIndex, cmnt);
906 3 ++fieldIndex;
907 }
908 1 rollbackValues.pop_back();
909 1 rollbackComments.pop_back();
910 1 }
911
912 // remove the diffs
913
1/1
✓ Branch 1 taken 1 time.
1 m_diffs.resize(diffSize);
914
915 1 return rollbackValues;
916 }
917 104082 --gn;
918
2/4
✓ Branch 1 taken 104082 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 104082 times.
✗ Branch 6 not taken.
104082 OS_ASSERT(gn == numExtensibleGroups());
919 104084 }
920
921
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26300 times.
✗ Branch 4 not taken.
26300 OS_ASSERT(!rollbackValues.empty());
922
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 26300 times.
✗ Branch 4 not taken.
26300 OS_ASSERT(!indices.empty());
923
924 26300 return rollbackValues;
925 71190 }
926
927 5 void IdfObject_Impl::initializeFields(bool fill_default) {
928
1/1
✓ Branch 1 taken 5 times.
5 const unsigned n = numFields();
929
1/1
✓ Branch 1 taken 5 times.
5 const unsigned iddN = m_iddObject.numFields();
930 5 bool resized = false;
931
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (n < iddN) {
932 2 resized = true;
933
1/1
✓ Branch 1 taken 2 times.
2 m_fields.resize(iddN);
934 }
935
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4 times.
5 if (!fill_default) {
936
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (resized) {
937
1/1
✓ Branch 1 taken 1 time.
1 this->onChange.nano_emit();
938 }
939 1 return;
940 }
941
942 // Instead of allocating m_diffs, then calling emitChangeSignals which will try to see if there's a name change,
943 // I know there isn't going to be **any** name changes here, so let's be quicker
944 4 bool dataChange = false;
945
946
2/2
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 4 times.
36 for (unsigned int index = 0; index < std::max(n, iddN); ++index) {
947
2/2
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 2 times.
32 if (m_fields[index].empty()) {
948
1/1
✓ Branch 1 taken 30 times.
30 OptionalIddField iddField = m_iddObject.getField(index);
949
7/8
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 30 times.
✓ Branch 6 taken 30 times.
✓ Branch 9 taken 20 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 20 times.
✓ Branch 12 taken 10 times.
60 if (iddField && iddField->properties().stringDefault) {
950
4/4
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 11 taken 20 times.
20 m_fields[index] = *(iddField->properties().stringDefault);
951 20 dataChange = true;
952 // m_diffs.push_back(IdfObjectDiff(index, boost::none, m_fields[index] ));
953 }
954 30 }
955 }
956
957
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
4 if (dataChange) {
958
1/1
✓ Branch 1 taken 3 times.
3 this->onDataChange.nano_emit();
959
1/1
✓ Branch 1 taken 3 times.
3 this->onChange.nano_emit();
960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 } else if (resized) {
961 ✗ this->onChange.nano_emit();
962 }
963 }
964
965 // QUERIES
966
967 64163284 unsigned IdfObject_Impl::numFields() const {
968 64163284 return m_fields.size();
969 }
970
971 1415353 unsigned IdfObject_Impl::numNonextensibleFields() const {
972 1415353 unsigned n = numFields();
973 1415353 unsigned iddN = m_iddObject.numFields();
974
2/2
✓ Branch 0 taken 1233900 times.
✓ Branch 1 taken 181453 times.
1415353 if (iddN < n) {
975 1233900 return iddN;
976 }
977 181453 return n;
978 }
979
980 3488 unsigned IdfObject_Impl::minFields() const {
981 3488 return m_iddObject.properties().minFields;
982 }
983
984 539848 OptionalUnsigned IdfObject_Impl::maxFields() const {
985 539848 OptionalUnsigned result;
986
3/3
✓ Branch 1 taken 539848 times.
✓ Branch 3 taken 4188 times.
✓ Branch 4 taken 535660 times.
539848 if (!m_iddObject.properties().extensible) {
987
2/2
✓ Branch 1 taken 4188 times.
✓ Branch 5 taken 4188 times.
4188 result = m_iddObject.nonextensibleFields().size();
988 } else {
989
1/1
✓ Branch 1 taken 535660 times.
535660 result = m_iddObject.properties().maxFields;
990 }
991 539848 return result;
992 }
993
994 1251448 unsigned IdfObject_Impl::numExtensibleGroups() const {
995 1251448 unsigned nExtFields = numFields() - numNonextensibleFields();
996
2/2
✓ Branch 0 taken 150221 times.
✓ Branch 1 taken 1101227 times.
1251448 if (nExtFields == 0) {
997 150221 return 0;
998 }
999
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1101227 times.
1101227 OS_ASSERT(m_iddObject.properties().extensible);
1000 1101227 unsigned groupSize = m_iddObject.properties().numExtensible;
1001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1101227 times.
1101227 OS_ASSERT(nExtFields % groupSize == 0);
1002 1101227 return nExtFields / groupSize;
1003 }
1004
1005 ✗ unsigned IdfObject_Impl::minExtensibleGroups() const {
1006 ✗ return m_iddObject.properties().numExtensibleGroupsRequired;
1007 }
1008
1009 ✗ boost::optional<unsigned> IdfObject_Impl::maxExtensibleGroups() const {
1010 ✗ OptionalUnsigned result = static_cast<unsigned>(0);
1011 ✗ if (!m_iddObject.properties().extensible) {
1012 ✗ return result;
1013 }
1014 ✗ OptionalUnsigned mf = maxFields();
1015 ✗ if (!mf) {
1016 ✗ return boost::none;
1017 }
1018 ✗ unsigned groupSize = m_iddObject.properties().numExtensible;
1019 ✗ unsigned maxExtFields = *mf - m_iddObject.numFields();
1020 ✗ OS_ASSERT(maxExtFields % groupSize == 0);
1021 ✗ OS_ASSERT(groupSize > 0);
1022 ✗ result = maxExtFields / groupSize;
1023 ✗ return result;
1024 }
1025
1026 35769 bool IdfObject_Impl::isObjectListField(unsigned index) const {
1027
2/3
✓ Branch 1 taken 35769 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35769 times.
35769 if (index >= numFields()) {
1028 ✗ return false;
1029 }
1030
1/1
✓ Branch 1 taken 35769 times.
35769 OptionalIddField oIddField = m_iddObject.getField(index);
1031
1/2
✓ Branch 0 taken 35769 times.
✗ Branch 1 not taken.
35769 if (oIddField) {
1032
2/2
✓ Branch 1 taken 35769 times.
✓ Branch 4 taken 35769 times.
35769 return oIddField->isObjectListField();
1033 }
1034 ✗ return false;
1035 35769 }
1036
1037 404413 std::vector<unsigned> IdfObject_Impl::objectListFields() const {
1038 404413 UnsignedVector result = m_iddObject.objectListFields();
1039
1/1
✓ Branch 1 taken 404413 times.
404413 result = trimFieldIndices(result);
1040
1/1
✓ Branch 1 taken 404413 times.
404413 result = repeatExtensibleIndices(result);
1041 404413 return result;
1042 ✗ }
1043
1044 35769 bool IdfObject_Impl::isDataField(unsigned index) const {
1045
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35769 times.
35769 if (index >= numFields()) {
1046 ✗ return false;
1047 }
1048
6/6
✓ Branch 1 taken 33120 times.
✓ Branch 2 taken 2649 times.
✓ Branch 3 taken 4536 times.
✓ Branch 4 taken 28584 times.
✓ Branch 6 taken 376 times.
✓ Branch 7 taken 4160 times.
35769 return (!isObjectListField(index) && (index > 0 || !m_iddObject.hasHandleField()));
1049 }
1050
1051 4536 std::vector<unsigned> IdfObject_Impl::dataFields() const {
1052 4536 UnsignedVector result;
1053
3/3
✓ Branch 1 taken 4536 times.
✓ Branch 3 taken 35769 times.
✓ Branch 4 taken 4536 times.
40305 for (unsigned i = 0, n = numFields(); i < n; ++i) {
1054
3/3
✓ Branch 1 taken 35769 times.
✓ Branch 3 taken 28960 times.
✓ Branch 4 taken 6809 times.
35769 if (isDataField(i)) {
1055
1/1
✓ Branch 1 taken 28960 times.
28960 result.push_back(i);
1056 }
1057 }
1058 4536 return result;
1059 ✗ }
1060
1061 ✗ UnsignedVector IdfObject_Impl::requiredFields() const {
1062 ✗ UnsignedVector result;
1063 ✗ for (unsigned index = 0; index < m_fields.size(); ++index) {
1064 ✗ OptionalIddField field = m_iddObject.getField(index);
1065 ✗ if (field && field->properties().required) {
1066 ✗ result.push_back(index);
1067 }
1068 ✗ }
1069 ✗ return result;
1070 ✗ }
1071
1072 92218 bool IdfObject_Impl::isValid(StrictnessLevel level) const {
1073 92218 return isValid(level, false);
1074 }
1075
1076 595496 bool IdfObject_Impl::isValid(StrictnessLevel level, bool checkNames) const {
1077
2/2
✓ Branch 1 taken 595496 times.
✓ Branch 4 taken 595496 times.
595496 return (validityReport(level, checkNames).numErrors() == 0);
1078 }
1079
1080 992287 ValidityReport IdfObject_Impl::validityReport(StrictnessLevel level, bool checkNames) const {
1081
2/2
✓ Branch 1 taken 992287 times.
✓ Branch 4 taken 992287 times.
992287 ValidityReport report(level, getObject<IdfObject>());
1082
1/1
✓ Branch 1 taken 992287 times.
992287 this->populateValidityReport(report, checkNames);
1083 992287 return report;
1084 ✗ }
1085
1086 2268 bool IdfObject_Impl::dataFieldsEqual(const IdfObject& other) const {
1087
3/4
✓ Branch 1 taken 2268 times.
✓ Branch 4 taken 2268 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2268 times.
2268 if (m_iddObject != other.iddObject()) {
1088 ✗ return false;
1089 }
1090
1/1
✓ Branch 1 taken 2268 times.
2268 UnsignedVector myFields = dataFields();
1091
1/1
✓ Branch 1 taken 2268 times.
2268 UnsignedVector otherFields = other.dataFields();
1092
3/3
✓ Branch 1 taken 2268 times.
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 2164 times.
2268 if (myFields != otherFields) {
1093 104 return false;
1094 }
1095
1096
1/1
✓ Branch 1 taken 2164 times.
2164 OptionalUnsigned iName = m_iddObject.nameFieldIndex();
1097
1098 // iddObject() same, field indices same--compare data
1099
2/2
✓ Branch 5 taken 11528 times.
✓ Branch 6 taken 2102 times.
13630 for (unsigned i : myFields) {
1100 11528 bool compareStrings = true;
1101
1/1
✓ Branch 1 taken 11528 times.
11528 OptionalIddField oIddField = m_iddObject.getField(i);
1102
1103 // integers
1104
8/9
✓ Branch 0 taken 11528 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 11528 times.
✓ Branch 6 taken 11528 times.
✓ Branch 9 taken 11528 times.
✓ Branch 12 taken 1045 times.
✓ Branch 13 taken 10483 times.
✓ Branch 14 taken 1045 times.
✓ Branch 15 taken 10483 times.
11528 if (oIddField && (oIddField->properties().type == IddFieldType::IntegerType)) {
1105
1/1
✓ Branch 1 taken 1045 times.
1045 OptionalInt oMyIntValue = getInt(i);
1106
1/1
✓ Branch 1 taken 1045 times.
1045 OptionalInt oOtherIntValue = other.getInt(i);
1107
5/6
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 1018 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 1018 times.
✓ Branch 5 taken 27 times.
1072 if (oMyIntValue || oOtherIntValue) {
1108
3/6
✓ Branch 0 taken 1018 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1018 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1018 times.
2036 if (!(oMyIntValue && oOtherIntValue)) {
1109 ✗ return false;
1110 }
1111
3/4
✓ Branch 1 taken 1018 times.
✓ Branch 4 taken 1018 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1018 times.
1018 if (oMyIntValue.get() != oOtherIntValue.get()) {
1112 ✗ return false;
1113 }
1114 1018 compareStrings = false;
1115 }
1116 }
1117
1118 // doubles
1119
8/9
✓ Branch 0 taken 11528 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 11528 times.
✓ Branch 6 taken 11528 times.
✓ Branch 9 taken 11528 times.
✓ Branch 12 taken 6102 times.
✓ Branch 13 taken 5426 times.
✓ Branch 14 taken 6102 times.
✓ Branch 15 taken 5426 times.
11528 if (oIddField && (oIddField->properties().type == IddFieldType::RealType)) {
1120
1/1
✓ Branch 1 taken 6102 times.
6102 OptionalDouble oMyDoubleValue = getDouble(i);
1121
1/1
✓ Branch 1 taken 6102 times.
6102 OptionalDouble oOtherDoubleValue = other.getDouble(i);
1122
5/6
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 5562 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 540 times.
✓ Branch 4 taken 5562 times.
✓ Branch 5 taken 540 times.
6642 if (oMyDoubleValue || oOtherDoubleValue) {
1123
3/6
✓ Branch 0 taken 5562 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5562 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5562 times.
11124 if (!(oMyDoubleValue && oOtherDoubleValue)) {
1124 ✗ return false;
1125 }
1126
3/4
✓ Branch 2 taken 5562 times.
✓ Branch 5 taken 5562 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5562 times.
5562 if (!equal(oMyDoubleValue.get(), oOtherDoubleValue.get())) {
1127 ✗ return false;
1128 }
1129 5562 compareStrings = false;
1130 }
1131 }
1132
1133 // urls
1134 // DLM: just treat these as strings
1135 // if (oIddField && (oIddField->properties().type == IddFieldType::URLType)) {
1136 // OptionalUrl oMyUrlValue = getURL(i);
1137 // OptionalUrl oOtherUrlValue = other.getURL(i);
1138 // if (oMyUrlValue || oOtherUrlValue) {
1139 // if (!(oMyUrlValue && oOtherUrlValue)) { return false; }
1140 // if (oMyUrlValue.get() != oOtherUrlValue.get()) { return false; }
1141 // compareStrings = false;
1142 // }
1143 // }
1144
1145 // strings (case-insensitive)
1146
2/2
✓ Branch 0 taken 4948 times.
✓ Branch 1 taken 6580 times.
11528 if (compareStrings) {
1147
1/1
✓ Branch 1 taken 4948 times.
4948 OptionalString oMyStringValue = getString(i);
1148
1/1
✓ Branch 1 taken 4948 times.
4948 OptionalString oOtherStringValue = other.getString(i);
1149
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 4948 times.
✗ Branch 4 not taken.
4948 OS_ASSERT(oMyStringValue);
1150
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 4948 times.
✗ Branch 4 not taken.
4948 OS_ASSERT(oOtherStringValue);
1151
5/5
✓ Branch 1 taken 4948 times.
✓ Branch 4 taken 4948 times.
✓ Branch 7 taken 4948 times.
✓ Branch 9 taken 62 times.
✓ Branch 10 taken 4886 times.
4948 if (!istringEqual(*oMyStringValue, *oOtherStringValue)) {
1152
9/12
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45 times.
✓ Branch 3 taken 17 times.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 17 times.
✓ Branch 11 taken 17 times.
✓ Branch 14 taken 17 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 17 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 62 times.
62 if (iName && (i == iName.get()) && (handle() == other.handle())) {
1153 ✗ continue;
1154 }
1155 62 return false;
1156 }
1157 5010 }
1158 11528 }
1159
1160 2102 return true;
1161 2268 }
1162
1163 ✗ bool IdfObject_Impl::objectListFieldsEqual(const IdfObject& other) const {
1164 ✗ if (m_iddObject != other.iddObject()) {
1165 ✗ return false;
1166 }
1167 ✗ UnsignedVector myFields = objectListFields();
1168 ✗ UnsignedVector otherFields = other.objectListFields();
1169 ✗ if (myFields != otherFields) {
1170 ✗ return false;
1171 }
1172
1173 // iddObject() same, field indices same--compare data
1174 ✗ for (unsigned i : myFields) {
1175 // in idf, just comparing strings
1176 ✗ OptionalString oMyStringValue = getString(i);
1177 ✗ OptionalString oOtherStringValue = other.getString(i);
1178 ✗ OS_ASSERT(oMyStringValue);
1179 ✗ OS_ASSERT(oOtherStringValue);
1180 ✗ if (!istringEqual(*oMyStringValue, *oOtherStringValue)) {
1181 ✗ return false;
1182 }
1183 ✗ }
1184
1185 ✗ return true;
1186 ✗ }
1187
1188 12 bool IdfObject_Impl::objectListFieldsNonConflicting(const IdfObject& other) const {
1189
3/4
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12 times.
12 if (m_iddObject != other.iddObject()) {
1190 ✗ return false;
1191 }
1192
1/1
✓ Branch 1 taken 12 times.
12 UnsignedVector myFields = objectListFields();
1193
1/1
✓ Branch 1 taken 12 times.
12 UnsignedVector otherFields = other.objectListFields();
1194 // require same managedObjectLists fields to at least exist
1195
3/3
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 11 times.
12 if (myFields != otherFields) {
1196 1 return false;
1197 }
1198
1199 // iddObject() same--compare data
1200
2/2
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 7 times.
15 for (unsigned i : myFields) {
1201 // in idf, just comparing strings
1202
1/1
✓ Branch 1 taken 8 times.
8 OptionalString oMyStringValue = getString(i);
1203
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 4 not taken.
8 OS_ASSERT(oMyStringValue);
1204 // empty() == null pointer == ok
1205
2/3
✓ Branch 1 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 if (oMyStringValue->empty()) {
1206 ✗ continue;
1207 }
1208
1209
1/1
✓ Branch 1 taken 8 times.
8 OptionalString oOtherStringValue = other.getString(i);
1210
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 4 not taken.
8 OS_ASSERT(oOtherStringValue);
1211 // empty() == null pointer == ok
1212
2/3
✓ Branch 1 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 if (oOtherStringValue->empty()) {
1213 ✗ continue;
1214 }
1215
5/5
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 4 times.
8 if (!istringEqual(*oMyStringValue, *oOtherStringValue)) {
1216 4 return false;
1217 }
1218 12 }
1219
1220 7 return true;
1221 12 }
1222
1223 // SERIALIZATION
1224
1225 302 std::shared_ptr<IdfObject_Impl> IdfObject_Impl::load(const std::string& text) {
1226 302 std::shared_ptr<IdfObject_Impl> result;
1227
1/1
✓ Branch 1 taken 302 times.
302 IdfObject_Impl idfObjectImpl;
1228
1229 try {
1230
1/1
✓ Branch 1 taken 302 times.
302 idfObjectImpl.parse(text, true);
1231
1/1
✓ Branch 1 taken 302 times.
302 idfObjectImpl.resizeToMinFields();
1232 ✗ } catch (...) {
1233 ✗ return result;
1234 ✗ }
1235
1236
2/2
✓ Branch 1 taken 302 times.
✓ Branch 4 taken 302 times.
302 bool keepHandle = idfObjectImpl.iddObject().hasHandleField();
1237
3/5
✓ Branch 1 taken 302 times.
✓ Branch 4 taken 302 times.
✓ Branch 7 taken 302 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
302 result = std::shared_ptr<IdfObject_Impl>(new IdfObject_Impl(idfObjectImpl, keepHandle));
1238 302 return result;
1239 302 }
1240
1241 1249552 std::shared_ptr<IdfObject_Impl> IdfObject_Impl::load(const std::string& text, const IddObject& iddObject) {
1242 1249552 std::shared_ptr<IdfObject_Impl> result;
1243
1/1
✓ Branch 1 taken 1249552 times.
1249552 IdfObject_Impl idfObjectImpl(iddObject, false, true);
1244
1245 try {
1246
1/1
✓ Branch 1 taken 1249552 times.
1249552 idfObjectImpl.parse(text, false);
1247
1/1
✓ Branch 1 taken 1249552 times.
1249552 idfObjectImpl.resizeToMinFields();
1248 ✗ } catch (...) {
1249 ✗ return result;
1250 ✗ }
1251
1252
2/2
✓ Branch 1 taken 1249552 times.
✓ Branch 4 taken 1249552 times.
1249552 bool keepHandle = idfObjectImpl.iddObject().hasHandleField();
1253
3/5
✓ Branch 1 taken 1249552 times.
✓ Branch 4 taken 1249552 times.
✓ Branch 7 taken 1249552 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
1249552 result = std::shared_ptr<IdfObject_Impl>(new IdfObject_Impl(idfObjectImpl, keepHandle));
1254 1249552 return result;
1255 1249552 }
1256
1257 959432 std::ostream& IdfObject_Impl::print(std::ostream& os) const {
1258 959432 unsigned n = numFields();
1259
2/2
✓ Branch 0 taken 75 times.
✓ Branch 1 taken 959357 times.
959432 if (n == 0) {
1260 75 printName(os, false);
1261 } else {
1262 959357 printName(os, true);
1263 }
1264
1265
2/2
✓ Branch 0 taken 13433296 times.
✓ Branch 1 taken 959432 times.
14392728 for (unsigned i = 0; i < n; ++i) {
1266
2/2
✓ Branch 0 taken 12473939 times.
✓ Branch 1 taken 959357 times.
13433296 if (i < n - 1) {
1267 12473939 printField(os, i);
1268 } else {
1269 959357 printField(os, i, true);
1270 }
1271 }
1272
1273 959432 os << '\n';
1274
1275 959432 return os;
1276 }
1277
1278 959437 std::ostream& IdfObject_Impl::printName(std::ostream& os, bool hasFields) const {
1279 // print comment, if any
1280
2/2
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 959411 times.
959437 if (!m_comment.empty()) {
1281 26 os << m_comment << '\n';
1282 }
1283
1284 // if this is a comment only object, return
1285 // todo, tighten up handling of comments with comment only object type
1286
5/5
✓ Branch 2 taken 959437 times.
✓ Branch 5 taken 959437 times.
✓ Branch 8 taken 959437 times.
✓ Branch 12 taken 9 times.
✓ Branch 13 taken 959428 times.
959437 if (boost::iequals(m_iddObject.name(), iddRegex::commentOnlyObjectName())) {
1287 9 return os;
1288 }
1289
1290
2/2
✓ Branch 1 taken 959428 times.
✓ Branch 4 taken 959428 times.
959428 os << m_iddObject.name();
1291
1292
2/2
✓ Branch 0 taken 959362 times.
✓ Branch 1 taken 66 times.
959428 if (hasFields) {
1293 959362 os << "," << '\n';
1294 } else {
1295 66 os << ";" << '\n';
1296 }
1297
1298 959428 return os;
1299 }
1300
1301 13433329 std::ostream& IdfObject_Impl::printField(std::ostream& os, unsigned index, bool isLastField) const {
1302
1/2
✓ Branch 1 taken 13433329 times.
✗ Branch 2 not taken.
13433329 if (index < numFields()) {
1303 // different formatting for vertices
1304
6/6
✓ Branch 2 taken 7843302 times.
✓ Branch 3 taken 5590027 times.
✓ Branch 5 taken 4223193 times.
✓ Branch 6 taken 3620109 times.
✓ Branch 7 taken 4223193 times.
✓ Branch 8 taken 9210136 times.
13433329 if ((m_iddObject.properties().format == "vertices") && (m_iddObject.isExtensibleField(index))) {
1305
1/1
✓ Branch 1 taken 4223193 times.
4223193 ExtensibleIndex eIndex = m_iddObject.extensibleIndex(index);
1306 // making this static is a bad idea,
1307 // it makes no sense in a threaded environment
1308 static int textWidth(0);
1309
2/2
✓ Branch 0 taken 1407731 times.
✓ Branch 1 taken 2815462 times.
4223193 if (eIndex.field == 0) {
1310
1/1
✓ Branch 1 taken 1407731 times.
1407731 os << " ";
1311 1407731 textWidth = 0;
1312 } else {
1313
1/1
✓ Branch 1 taken 2815462 times.
2815462 os << " ";
1314 }
1315 // field value
1316
1/1
✓ Branch 2 taken 4223193 times.
4223193 os << m_fields[index];
1317 // delimiter
1318
2/2
✓ Branch 0 taken 335329 times.
✓ Branch 1 taken 3887864 times.
4223193 if (isLastField) {
1319
1/1
✓ Branch 1 taken 335329 times.
335329 os << ";";
1320 } else {
1321
1/1
✓ Branch 1 taken 3887864 times.
3887864 os << ",";
1322 }
1323 4223193 textWidth += m_fields[index].size();
1324 // comment
1325
3/3
✓ Branch 1 taken 4223193 times.
✓ Branch 3 taken 1407731 times.
✓ Branch 4 taken 2815462 times.
4223193 if (eIndex.field == m_iddObject.properties().numExtensible - 1) {
1326
1/1
✓ Branch 1 taken 1407731 times.
1407731 int numSpaces = IdfObject::printedFieldSpace() - textWidth - 4;
1327
2/2
✓ Branch 0 taken 905608 times.
✓ Branch 1 taken 502123 times.
1407731 if (numSpaces > 0) {
1328
1/1
✓ Branch 3 taken 905608 times.
905608 os << std::setw(numSpaces) << " ";
1329 }
1330
2/2
✓ Branch 1 taken 1407731 times.
✓ Branch 4 taken 1407731 times.
1407731 os << " !- X,Y,Z Vertex " << eIndex.group + 1;
1331
2/2
✓ Branch 1 taken 1407731 times.
✓ Branch 4 taken 1407731 times.
1407731 IddField iddField = m_iddObject.getField(index).get();
1332
3/4
✓ Branch 1 taken 1407731 times.
✓ Branch 4 taken 1407731 times.
✓ Branch 6 taken 1407731 times.
✗ Branch 7 not taken.
2815462 if (OptionalString units = iddField.properties().units) {
1333
4/4
✓ Branch 1 taken 1407731 times.
✓ Branch 4 taken 1407731 times.
✓ Branch 7 taken 1407731 times.
✓ Branch 10 taken 1407731 times.
1407731 os << " {" << *units << "}";
1334 1407731 }
1335
1/1
✓ Branch 1 taken 1407731 times.
1407731 os << '\n';
1336 1407731 }
1337 } else {
1338 // field value
1339 9210136 os << " " << m_fields[index];
1340 // delimiter
1341
2/2
✓ Branch 0 taken 624033 times.
✓ Branch 1 taken 8586103 times.
9210136 if (isLastField) {
1342 624033 os << ";";
1343 } else {
1344 8586103 os << ",";
1345 }
1346 // field comment
1347 9210136 int numSpaces = IdfObject::printedFieldSpace() - int(m_fields[index].size());
1348
2/2
✓ Branch 0 taken 6647941 times.
✓ Branch 1 taken 2562195 times.
9210136 if (numSpaces > 0) {
1349 6647941 os << std::setw(numSpaces) << " ";
1350 }
1351
3/3
✓ Branch 2 taken 9210136 times.
✓ Branch 5 taken 9210136 times.
✓ Branch 8 taken 9210136 times.
9210136 os << " " << fieldComment(index, true) << '\n';
1352 }
1353 } // if index < numFields()
1354 13433329 return os;
1355 }
1356
1357 1344639 void IdfObject_Impl::emitChangeSignals() {
1358
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1344639 times.
1344639 if (m_diffs.empty()) {
1359 ✗ return;
1360 }
1361
1362 1344639 bool nameChange = false;
1363 1344639 bool dataChange = false;
1364
1365
2/2
✓ Branch 5 taken 1786672 times.
✓ Branch 6 taken 1344639 times.
3131311 for (const IdfObjectDiff& diff : m_diffs) {
1366
1367
3/3
✓ Branch 1 taken 1786672 times.
✓ Branch 3 taken 238614 times.
✓ Branch 4 taken 1548058 times.
1786672 if (diff.isNull()) {
1368 238614 continue;
1369 }
1370
1371
1/1
✓ Branch 1 taken 1548058 times.
1548058 boost::optional<unsigned> index = diff.index();
1372
1/2
✓ Branch 0 taken 1548058 times.
✗ Branch 1 not taken.
1548058 if (index) {
1373
1374
2/2
✓ Branch 1 taken 1548058 times.
✓ Branch 4 taken 1548058 times.
1548058 OptionalIddField oIddField = m_iddObject.getField(*index);
1375
1376
7/8
✓ Branch 0 taken 1548058 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1548058 times.
✓ Branch 6 taken 1548058 times.
✓ Branch 8 taken 44579 times.
✓ Branch 9 taken 1503479 times.
✓ Branch 10 taken 44579 times.
✓ Branch 11 taken 1503479 times.
1548058 if (oIddField && oIddField->isNameField()) {
1377 44579 nameChange = true;
1378 } else {
1379 1503479 dataChange = true;
1380 }
1381 1548058 }
1382 }
1383
1384
2/2
✓ Branch 0 taken 44579 times.
✓ Branch 1 taken 1300060 times.
1344639 if (nameChange) {
1385 44579 this->onNameChange.nano_emit();
1386 }
1387
1388
2/2
✓ Branch 0 taken 1217773 times.
✓ Branch 1 taken 126866 times.
1344639 if (dataChange) {
1389 1217773 this->onDataChange.nano_emit();
1390 }
1391
1392 1344639 this->onChange.nano_emit();
1393
1394 1344639 m_diffs.clear();
1395 }
1396
1397 // PRIVATE
1398
1399 1675923 void IdfObject_Impl::resizeToMinFields() {
1400 1675923 unsigned min_n = m_iddObject.numFieldsInDefaultObject();
1401 1675923 unsigned n = numFields();
1402
2/2
✓ Branch 0 taken 214002 times.
✓ Branch 1 taken 1461921 times.
1675923 if (n < min_n) {
1403 214002 m_fields.resize(min_n);
1404 214002 n = min_n;
1405 }
1406 // also make sure extensible groups are whole
1407
2/2
✓ Branch 1 taken 916073 times.
✓ Branch 2 taken 759850 times.
1675923 if (m_iddObject.properties().extensible) {
1408 916073 int nExtFields = n - m_iddObject.numFields();
1409
2/2
✓ Branch 0 taken 730688 times.
✓ Branch 1 taken 185385 times.
916073 if (nExtFields > 0) {
1410 730688 int groupSize = m_iddObject.properties().numExtensible;
1411 730688 int modulo = nExtFields % groupSize;
1412
2/2
✓ Branch 0 taken 171 times.
✓ Branch 1 taken 730517 times.
730688 if (modulo > 0) {
1413 171 m_fields.resize(n + (groupSize - modulo));
1414 }
1415 }
1416 }
1417 1675923 }
1418
1419 1249854 void IdfObject_Impl::parse(const std::string& text, bool getIddFromFactory) {
1420 1249854 std::string objectType;
1421
1422 // cut down on this text as we parse
1423
1/1
✓ Branch 1 taken 1249854 times.
1249854 std::string parsedText(text);
1424
1425 // get preceding comments
1426
1/1
✓ Branch 1 taken 1249854 times.
1249854 boost::smatch matches;
1427
9/10
✓ Branch 1 taken 1249858 times.
✓ Branch 4 taken 1249858 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1249854 times.
✓ Branch 9 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 1249854 times.
1249858 while (boost::regex_match(parsedText, idfRegex::commentOnlyLine()) && boost::regex_search(parsedText, matches, idfRegex::commentOnlyLine())) {
1428
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
8 std::string comment(matches[1].first, matches[1].second);
1429
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
4 std::string otherText(matches[2].first, matches[2].second);
1430
1/1
✓ Branch 2 taken 4 times.
4 boost::trim_left(otherText);
1431
1432 // append the comment
1433
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (!comment.empty()) {
1434
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
4 m_comment += "!" + comment + idfRegex::newLinestring();
1435 }
1436
1437 // reduce the parsed text
1438
1/1
✓ Branch 1 taken 4 times.
4 parsedText = otherText;
1439 4 }
1440
1441 // the first entry will be the object type
1442
3/4
✓ Branch 1 taken 1249854 times.
✓ Branch 4 taken 1249854 times.
✓ Branch 6 taken 1249854 times.
✗ Branch 7 not taken.
1249854 if (boost::regex_search(parsedText, matches, idfRegex::line())) {
1443
3/3
✓ Branch 1 taken 1249854 times.
✓ Branch 4 taken 1249854 times.
✓ Branch 7 taken 1249854 times.
1249854 objectType = std::string(matches[1].first, matches[1].second);
1444
1/1
✓ Branch 2 taken 1249854 times.
1249854 boost::trim(objectType);
1445
3/3
✓ Branch 1 taken 1249854 times.
✓ Branch 4 taken 1249854 times.
✓ Branch 7 taken 1249854 times.
1249854 std::string commentOrOtherText(matches[2].first, matches[2].second);
1446
1/1
✓ Branch 2 taken 1249854 times.
1249854 boost::trim_left(commentOrOtherText);
1447
3/3
✓ Branch 1 taken 1249854 times.
✓ Branch 4 taken 1249854 times.
✓ Branch 7 taken 1249854 times.
1249854 std::string otherText(matches[3].first, matches[3].second);
1448
1449
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 1249552 times.
1249854 if (getIddFromFactory) {
1450 // find appropriate IddObject in IddFactory
1451
2/2
✓ Branch 1 taken 302 times.
✓ Branch 4 taken 302 times.
302 OptionalIddObject candidate = IddFactory::instance().getObject(objectType);
1452
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (candidate) {
1453
1/1
✓ Branch 1 taken 302 times.
302 m_iddObject = *candidate;
1454 } else {
1455 ✗ LOG(Warn, "IddObject type '" << objectType << "' not found in IddFactory. " << "Reverting to default Catchall object.");
1456 ✗ OS_ASSERT(m_iddObject.name() == "Catchall");
1457 ✗ m_fields.push_back(objectType);
1458 ✗ objectType = "Catchall";
1459 }
1460 302 } else {
1461
4/4
✓ Branch 2 taken 1249552 times.
✓ Branch 5 taken 1249552 times.
✓ Branch 9 taken 182 times.
✓ Branch 10 taken 1249370 times.
1249552 if (!boost::iequals(objectType, m_iddObject.name())) {
1462
3/4
✓ Branch 1 taken 182 times.
✓ Branch 4 taken 182 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 182 times.
182 if (m_iddObject.type() != IddObjectType::Catchall) {
1463 ✗ LOG(Error, "IdfObject type '" << objectType << "', does not equal its IddObject name '" << m_iddObject.name()
1464 << "'. Reverting to default Catchall IddObject.");
1465 }
1466
1/1
✓ Branch 1 taken 182 times.
182 m_iddObject = IddObject();
1467
1/1
✓ Branch 1 taken 182 times.
182 m_fields.push_back(objectType);
1468
1/1
✓ Branch 1 taken 182 times.
182 objectType = "Catchall";
1469 }
1470 }
1471
1472
2/2
✓ Branch 1 taken 1249854 times.
✓ Branch 4 taken 1249854 times.
1249854 if (boost::regex_match(commentOrOtherText, idfRegex::commentOnlyLine())
1473
8/8
✓ Branch 0 taken 1218427 times.
✓ Branch 1 taken 31427 times.
✓ Branch 3 taken 1218427 times.
✓ Branch 6 taken 1218427 times.
✓ Branch 8 taken 1206968 times.
✓ Branch 9 taken 11459 times.
✓ Branch 10 taken 1238395 times.
✓ Branch 11 taken 11459 times.
1249854 || boost::regex_match(commentOrOtherText, commentRegex::whitespaceOnlyBlock())) {
1474
1475 // set comment
1476
1/1
✓ Branch 1 taken 1238395 times.
1238395 m_comment += commentOrOtherText;
1477
1478 // reduce the parsed text
1479
1/1
✓ Branch 1 taken 1238395 times.
1238395 parsedText = otherText;
1480 } else {
1481 // reduce the parsed text
1482
1/1
✓ Branch 1 taken 11459 times.
11459 parsedText = commentOrOtherText + otherText;
1483 }
1484
1485 1249854 } else {
1486 ✗ LOG_AND_THROW("Cannot extract an IdfObject type from text '" << parsedText << "'");
1487 }
1488
1489 // get trailing comments
1490
9/10
✓ Branch 1 taken 1273915 times.
✓ Branch 4 taken 1273915 times.
✓ Branch 6 taken 24061 times.
✓ Branch 7 taken 1249854 times.
✓ Branch 9 taken 24061 times.
✓ Branch 12 taken 24061 times.
✓ Branch 14 taken 24061 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 24061 times.
✓ Branch 17 taken 1249854 times.
1273915 while (boost::regex_match(parsedText, idfRegex::commentOnlyLine()) && boost::regex_search(parsedText, matches, idfRegex::commentOnlyLine())) {
1491
3/3
✓ Branch 1 taken 24061 times.
✓ Branch 4 taken 24061 times.
✓ Branch 7 taken 24061 times.
48122 std::string comment(matches[1].first, matches[1].second);
1492
3/3
✓ Branch 1 taken 24061 times.
✓ Branch 4 taken 24061 times.
✓ Branch 7 taken 24061 times.
24061 std::string otherText(matches[2].first, matches[2].second);
1493
1/1
✓ Branch 2 taken 24061 times.
24061 boost::trim_left(otherText);
1494
1495 // append the comment
1496
2/2
✓ Branch 1 taken 23657 times.
✓ Branch 2 taken 404 times.
24061 if (!comment.empty()) {
1497
4/4
✓ Branch 1 taken 23657 times.
✓ Branch 4 taken 23657 times.
✓ Branch 7 taken 23657 times.
✓ Branch 10 taken 23657 times.
23657 m_comment += "!" + comment + idfRegex::newLinestring();
1498 }
1499
1500 // reduce the parsed text
1501
1/1
✓ Branch 1 taken 24061 times.
24061 parsedText = otherText;
1502 24061 }
1503
1504 // remove trailing whitespace and new lines
1505
1/1
✓ Branch 2 taken 1249854 times.
1249854 boost::trim_right(m_comment);
1506
1507 // parse the fields
1508
1/1
✓ Branch 1 taken 1249854 times.
1249854 parseFields(parsedText);
1509 1249854 }
1510
1511 1249854 void IdfObject_Impl::parseFields(const std::string& text) {
1512 // match variables
1513
1/1
✓ Branch 1 taken 1249854 times.
1249854 boost::match_results<std::string::const_iterator> matches;
1514
1515 // cut down on this text as we parse
1516 1249854 std::string::const_iterator start = text.begin();
1517 1249854 std::string::const_iterator stop = text.end();
1518
1519 // current idd field index
1520 1249854 unsigned iddFieldIndex = 0;
1521
1522 // parse all the fields
1523
4/4
✓ Branch 1 taken 20344590 times.
✓ Branch 4 taken 20344590 times.
✓ Branch 6 taken 19094738 times.
✓ Branch 7 taken 1249852 times.
20344590 while (boost::regex_search(start, stop, matches, idfRegex::line())) {
1524
3/3
✓ Branch 1 taken 19094738 times.
✓ Branch 4 taken 19094738 times.
✓ Branch 7 taken 19094738 times.
19094738 std::string fieldText(matches[1].first, matches[1].second);
1525
1/1
✓ Branch 2 taken 19094738 times.
19094738 boost::trim(fieldText);
1526
3/3
✓ Branch 1 taken 19094738 times.
✓ Branch 4 taken 19094738 times.
✓ Branch 7 taken 19094738 times.
19094738 std::string commentOrOtherText(matches[2].first, matches[2].second);
1527
1/1
✓ Branch 2 taken 19094738 times.
19094738 boost::trim(commentOrOtherText);
1528
1529
8/8
✓ Branch 1 taken 18985424 times.
✓ Branch 2 taken 109314 times.
✓ Branch 4 taken 18985424 times.
✓ Branch 7 taken 18985424 times.
✓ Branch 9 taken 15922688 times.
✓ Branch 10 taken 3062736 times.
✓ Branch 11 taken 16032002 times.
✓ Branch 12 taken 3062736 times.
19094738 if (commentOrOtherText.empty() || boost::regex_match(commentOrOtherText, idfRegex::commentOnlyLine())) {
1530 // reduce the text
1531
1/1
✓ Branch 1 taken 16032002 times.
16032002 start = matches[3].first;
1532
1/1
✓ Branch 1 taken 16032002 times.
16032002 stop = matches[3].second;
1533 } else {
1534 // reduce the text; there may be multiple fields on this line
1535
1/1
✓ Branch 1 taken 3062736 times.
3062736 start = matches[2].first;
1536
1/1
✓ Branch 1 taken 3062736 times.
3062736 stop = matches[3].second;
1537
1538 // matches[2] is not a comment
1539 3062736 commentOrOtherText.clear();
1540 }
1541
1542 // get the idd field
1543
1/1
✓ Branch 1 taken 19094738 times.
19094738 OptionalIddField iddField = m_iddObject.getField(iddFieldIndex);
1544
1545
2/2
✓ Branch 0 taken 19094736 times.
✓ Branch 1 taken 2 times.
19094738 if (iddField) {
1546
1547 // add this to our fields
1548
1/1
✓ Branch 1 taken 19094736 times.
19094736 m_fields.push_back(fieldText);
1549
1550
2/2
✓ Branch 1 taken 15922686 times.
✓ Branch 2 taken 3172050 times.
19094736 if (!commentOrOtherText.empty()) {
1551 // drop default comments
1552
4/4
✓ Branch 1 taken 15922686 times.
✓ Branch 4 taken 15922686 times.
✓ Branch 6 taken 607309 times.
✓ Branch 7 taken 15315377 times.
15922686 if (!boost::regex_match(commentOrOtherText, commentRegex::editorCommentWhitespaceOnlyLine())) {
1553
1/1
✓ Branch 2 taken 607309 times.
607309 m_fieldComments.resize(m_fields.size());
1554
1/1
✓ Branch 2 taken 607309 times.
607309 m_fieldComments.back() = commentOrOtherText;
1555 }
1556 }
1557
1558 // keep handle if this is a handle field
1559
5/5
✓ Branch 1 taken 19094736 times.
✓ Branch 4 taken 19094736 times.
✓ Branch 7 taken 19094736 times.
✓ Branch 10 taken 929979 times.
✓ Branch 11 taken 18164757 times.
19094736 if (iddField->properties().type == IddFieldType::HandleType) {
1560
1/1
✓ Branch 1 taken 929979 times.
929979 Handle candidate = toUUID(fieldText);
1561
1/2
✓ Branch 1 taken 929979 times.
✗ Branch 2 not taken.
929979 if (!candidate.isNull()) {
1562 929979 m_handle = candidate;
1563 }
1564 }
1565
1566 } else {
1567
18/18
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 31 taken 2 times.
✓ Branch 34 taken 2 times.
✓ Branch 37 taken 2 times.
✓ Branch 40 taken 2 times.
✓ Branch 43 taken 2 times.
✓ Branch 48 taken 2 times.
✓ Branch 51 taken 2 times.
✓ Branch 54 taken 2 times.
6 LOG(Error, "IdfObject of type '" << m_iddObject.name() << "' " << "cannot have field index of " << iddFieldIndex << ". "
1568 << "Cutting off IdfObject field parsing here, with the following text " << "remaining: " << '\n'
1569 << fieldText << '\n'
1570 << std::string(start, stop));
1571 2 return;
1572 }
1573
1574 // increment current idd field index
1575 19094736 ++iddFieldIndex;
1576 19094742 } // while line matches
1577
1578
1/1
✓ Branch 1 taken 1249852 times.
1249852 std::string unparsedText(start, stop);
1579
1/1
✓ Branch 2 taken 1249852 times.
1249852 boost::trim(unparsedText);
1580
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1249852 times.
1249852 if (!unparsedText.empty()) {
1581 ✗ LOG(Warn, "After parsing IdfObject fields, the following text remains unprocessed: " << '\n' << unparsedText);
1582 }
1583 1249854 }
1584
1585 // GETTER AND SETTER HELPERS
1586
1587 ✗ bool IdfObject_Impl::setIddObject(const IddObject& iddObject) {
1588 ✗ m_iddObject = iddObject;
1589 ✗ if (m_fields.size() < minFields()) {
1590 ✗ m_fields.resize(minFields());
1591 } else {
1592 // pop any fields that the IddObject does not recognize
1593 ✗ for (unsigned i = 0, n = numFields(); i < n; ++i) {
1594 ✗ if (!(m_iddObject.isNonextensibleField(i) || m_iddObject.isExtensibleField(i))) {
1595 ✗ m_fields.resize(i);
1596 ✗ if (m_fieldComments.size() > m_fields.size()) {
1597 ✗ m_fieldComments.resize(i);
1598 }
1599 ✗ break;
1600 }
1601 }
1602 }
1603 ✗ return true;
1604 }
1605
1606 404413 UnsignedVector IdfObject_Impl::trimFieldIndices(const UnsignedVector& indices) const {
1607 404413 unsigned n = m_fields.size(); // number of fields
1608 404413 UnsignedVector result = indices;
1609 // quick check to see if action is necessary
1610
6/6
✓ Branch 1 taken 310361 times.
✓ Branch 2 taken 94052 times.
✓ Branch 4 taken 76117 times.
✓ Branch 5 taken 234244 times.
✓ Branch 6 taken 76117 times.
✓ Branch 7 taken 328296 times.
404413 if (!result.empty() && (result.back() >= n)) {
1611 // assume indices are in order and find first that is out of range
1612
1/2
✓ Branch 4 taken 213738 times.
✗ Branch 5 not taken.
213738 for (auto it = result.begin(), itEnd = result.end(); it != itEnd; ++it) {
1613
2/2
✓ Branch 1 taken 76117 times.
✓ Branch 2 taken 137621 times.
213738 if (*it >= n) {
1614
1/1
✓ Branch 4 taken 76117 times.
76117 result.erase(it, result.end());
1615 76117 break;
1616 }
1617 }
1618 }
1619 404413 return result;
1620 ✗ }
1621
1622 404413 UnsignedVector IdfObject_Impl::repeatExtensibleIndices(const UnsignedVector& indices) const {
1623
1624 // assume indices is in order, and any extensible field indices are from the first
1625 // extensible group
1626
1/1
✓ Branch 1 taken 404413 times.
404413 UnsignedVector result = indices;
1627
1628 // nothing to do if not extensible
1629
3/3
✓ Branch 1 taken 404413 times.
✓ Branch 3 taken 223815 times.
✓ Branch 4 taken 180598 times.
404413 if (!m_iddObject.properties().extensible) {
1630 223815 return result;
1631 }
1632
1633 // nothing to do if last index is not in extensible group
1634
7/7
✓ Branch 1 taken 150424 times.
✓ Branch 2 taken 30174 times.
✓ Branch 5 taken 150424 times.
✓ Branch 7 taken 137259 times.
✓ Branch 8 taken 13165 times.
✓ Branch 9 taken 137259 times.
✓ Branch 10 taken 43339 times.
180598 if (!result.empty() && !m_iddObject.isExtensibleField(result.back())) {
1635 137259 return result;
1636 }
1637
1638 // otherwise, find group indices of extensible field indices in result
1639 43339 UnsignedVector groupIndices;
1640
2/2
✓ Branch 5 taken 23411 times.
✓ Branch 6 taken 43339 times.
66750 for (unsigned index : result) {
1641
3/3
✓ Branch 1 taken 23411 times.
✓ Branch 3 taken 14626 times.
✓ Branch 4 taken 8785 times.
23411 if (m_iddObject.isExtensibleField(index)) {
1642
2/2
✓ Branch 1 taken 14626 times.
✓ Branch 4 taken 14626 times.
14626 groupIndices.push_back(m_iddObject.extensibleIndex(index).field);
1643 }
1644 }
1645
1646 43339 unsigned n = m_fields.size();
1647
1/1
✓ Branch 1 taken 43339 times.
43339 unsigned nn = m_iddObject.numFields();
1648
1/1
✓ Branch 1 taken 43339 times.
43339 unsigned ne = m_iddObject.properties().numExtensible;
1649 43339 unsigned groupIndex = 1;
1650
2/2
✓ Branch 0 taken 140210 times.
✓ Branch 1 taken 43339 times.
183549 while (nn + groupIndex * ne < n) {
1651
2/2
✓ Branch 5 taken 9852 times.
✓ Branch 6 taken 140210 times.
150062 for (unsigned gi : groupIndices) {
1652 9852 unsigned index = nn + groupIndex * ne + gi;
1653
1/2
✓ Branch 0 taken 9852 times.
✗ Branch 1 not taken.
9852 if (index < n) {
1654
1/1
✓ Branch 1 taken 9852 times.
9852 result.push_back(index);
1655 }
1656 }
1657 140210 ++groupIndex;
1658 }
1659
1660 43339 return result;
1661 43339 }
1662
1663 // QUERY HELPERS
1664
1665 992284 void IdfObject_Impl::populateValidityReport(ValidityReport& report, bool /*checkNames*/) const {
1666 // field-level errors
1667
4/4
✓ Branch 1 taken 992284 times.
✓ Branch 4 taken 992284 times.
✓ Branch 7 taken 992049 times.
✓ Branch 8 taken 235 times.
992284 if (report.level() > StrictnessLevel::None) {
1668
2/2
✓ Branch 1 taken 11682286 times.
✓ Branch 2 taken 992049 times.
12674335 for (unsigned index = 0; index < m_fields.size(); ++index) {
1669
2/2
✓ Branch 1 taken 11682286 times.
✓ Branch 4 taken 11682286 times.
11682286 DataErrorVector fieldErrors = fieldDataIsValid(index, report.level());
1670
2/2
✓ Branch 5 taken 75 times.
✓ Branch 6 taken 11682286 times.
11682361 for (const DataError& error : fieldErrors) {
1671
1/1
✓ Branch 1 taken 75 times.
75 report.insertError(error);
1672 }
1673 11682286 }
1674 }
1675
1676 // StrictnessLevel::Final
1677
4/4
✓ Branch 1 taken 992284 times.
✓ Branch 4 taken 992284 times.
✓ Branch 7 taken 3472 times.
✓ Branch 8 taken 988812 times.
992284 if (report.level() > StrictnessLevel::Draft) {
1678
1679 // DataErrorType::NumberOfFields
1680 // object-level
1681
11/14
✓ Branch 1 taken 3472 times.
✓ Branch 4 taken 3472 times.
✓ Branch 6 taken 3472 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 3472 times.
✓ Branch 11 taken 2336 times.
✓ Branch 12 taken 1136 times.
✓ Branch 14 taken 2336 times.
✓ Branch 17 taken 2336 times.
✓ Branch 20 taken 2336 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 2336 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 3472 times.
6944 if ((numFields() < minFields()) || (maxFields() && (numFields() > maxFields().get()))) {
1682 ✗ report.insertError(DataError(getObject<IdfObject>(), DataErrorType(DataErrorType::NumberOfFields)));
1683 }
1684
1685 } // end StrictnessLevel::Final
1686 992284 }
1687
1688 12787824 std::vector<DataError> IdfObject_Impl::fieldDataIsValid(unsigned index, const StrictnessLevel& level) const {
1689 12787824 DataErrorVector result;
1690
1691 // StrictnessLevel::Minimal
1692
2/3
✓ Branch 1 taken 12787824 times.
✓ Branch 4 taken 12787824 times.
✗ Branch 5 not taken.
12787824 if (level > StrictnessLevel::None) {
1693
1694 // DataErrorType::NoIdd
1695 // field-level
1696
2/3
✓ Branch 1 taken 12787824 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12787824 times.
12787824 if (!m_iddObject.getField(index)) {
1697 ✗ result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::NoIdd)));
1698 // no other checks will work
1699 ✗ return result;
1700 }
1701 }
1702
1703 // StrictnessLevel::Draft
1704
3/3
✓ Branch 1 taken 12787824 times.
✓ Branch 4 taken 10932484 times.
✓ Branch 5 taken 1855340 times.
12787824 if (level > StrictnessLevel::Minimal) {
1705
1706 // DataErrorType::DataType
1707 // DataErrorType::NumericBound
1708 // field-level
1709
3/3
✓ Branch 1 taken 10932484 times.
✓ Branch 3 taken 290 times.
✓ Branch 4 taken 10932194 times.
10932484 if (!fieldDataIsCorrectType(index)) {
1710
4/4
✓ Branch 1 taken 290 times.
✓ Branch 4 taken 290 times.
✓ Branch 7 taken 290 times.
✓ Branch 10 taken 290 times.
290 result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::DataType)));
1711 }
1712
3/3
✓ Branch 1 taken 10932484 times.
✓ Branch 3 taken 493 times.
✓ Branch 4 taken 10931991 times.
10932484 if (!fieldDataIsWithinBounds(index)) {
1713
4/4
✓ Branch 1 taken 493 times.
✓ Branch 4 taken 493 times.
✓ Branch 7 taken 493 times.
✓ Branch 10 taken 493 times.
493 result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::NumericBound)));
1714 }
1715
1716 } // end StrictnessLevel::Draft
1717
1718 // StrictnessLevel::Final
1719
3/3
✓ Branch 1 taken 12787824 times.
✓ Branch 4 taken 31837 times.
✓ Branch 5 taken 12755987 times.
12787824 if (level > StrictnessLevel::Draft) {
1720
1721 // DataErrorType::NullAndRequired
1722 // field-level
1723
3/3
✓ Branch 1 taken 31837 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 31832 times.
31837 if (!fieldIsNonnullIfRequired(index)) {
1724
4/4
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
5 result.push_back(DataError(index, getObject<IdfObject>(), DataErrorType(DataErrorType::NullAndRequired)));
1725 }
1726 } // end StrictnessLevel::Final
1727
1728 12787824 return result;
1729 ✗ }
1730
1731 8632344 bool IdfObject_Impl::fieldDataIsCorrectType(unsigned index) const {
1732
1/1
✓ Branch 1 taken 8632344 times.
8632344 OptionalIddField oIddField = m_iddObject.getField(index);
1733
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8632344 times.
8632344 if (!oIddField) {
1734 ✗ return true;
1735 }
1736
1737
1/1
✓ Branch 1 taken 8632344 times.
8632344 IddField iddField = *oIddField;
1738
1/1
✓ Branch 1 taken 8632344 times.
8632344 IddFieldType fieldType = iddField.properties().type;
1739
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 8632344 times.
✗ Branch 4 not taken.
8632344 OS_ASSERT(m_fields.size() > index);
1740
1741
7/7
✓ Branch 1 taken 8632344 times.
✓ Branch 4 taken 664845 times.
✓ Branch 5 taken 7967499 times.
✓ Branch 8 taken 554021 times.
✓ Branch 9 taken 110824 times.
✓ Branch 10 taken 554021 times.
✓ Branch 11 taken 8078323 times.
8632344 if ((fieldType == IddFieldType::IntegerType) && (!m_fields[index].empty())) {
1742
1/1
✓ Branch 1 taken 554021 times.
554021 OptionalInt value = getInt(index);
1743
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 554021 times.
554021 if (!value) {
1744 // ok if autosize or autocalculate
1745 ✗ if (iddField.properties().autosizable && istringEqual(m_fields[index], "autosize")) {
1746 ✗ } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autocalculate")) {
1747 ✗ } else if (iddField.properties().autosizable && istringEqual(m_fields[index], "autocalculate")) {
1748 ✗ LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name()
1749 << " has 'autocalculate' as its value even though it is autosizable.");
1750 ✗ } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autosize")) {
1751 ✗ LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name()
1752 << " has 'autosize' as its value even though it is autocalculable.");
1753 } else {
1754 ✗ return false;
1755 }
1756 } else {
1757 // integers can't be NaN or Infinity
1758 }
1759 }
1760
1761
7/7
✓ Branch 1 taken 8632344 times.
✓ Branch 4 taken 4430335 times.
✓ Branch 5 taken 4202009 times.
✓ Branch 8 taken 3252393 times.
✓ Branch 9 taken 1177942 times.
✓ Branch 10 taken 3252393 times.
✓ Branch 11 taken 5379951 times.
8632344 if ((fieldType == IddFieldType::RealType) && (!m_fields[index].empty())) {
1762
1/1
✓ Branch 1 taken 3252393 times.
3252393 OptionalDouble value = getDouble(index);
1763
2/2
✓ Branch 1 taken 72061 times.
✓ Branch 2 taken 3180332 times.
3252393 if (!value) {
1764 // ok if autosize or autocalculate
1765
13/17
✓ Branch 1 taken 72061 times.
✓ Branch 3 taken 68071 times.
✓ Branch 4 taken 3990 times.
✓ Branch 6 taken 68071 times.
✓ Branch 10 taken 68071 times.
✓ Branch 12 taken 67811 times.
✓ Branch 13 taken 260 times.
✓ Branch 14 taken 68071 times.
✓ Branch 15 taken 3990 times.
✓ Branch 17 taken 68071 times.
✓ Branch 18 taken 3990 times.
✓ Branch 19 taken 4250 times.
✓ Branch 20 taken 67811 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
208203 if (iddField.properties().autosizable && istringEqual(m_fields[index], "autosize")) {
1766
13/17
✓ Branch 1 taken 4250 times.
✓ Branch 3 taken 3989 times.
✓ Branch 4 taken 261 times.
✓ Branch 6 taken 3989 times.
✓ Branch 10 taken 3989 times.
✓ Branch 12 taken 3983 times.
✓ Branch 13 taken 6 times.
✓ Branch 14 taken 3989 times.
✓ Branch 15 taken 261 times.
✓ Branch 17 taken 3989 times.
✓ Branch 18 taken 261 times.
✓ Branch 19 taken 267 times.
✓ Branch 20 taken 3983 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
12228 } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autocalculate")) {
1767
12/17
✓ Branch 1 taken 267 times.
✓ Branch 3 taken 260 times.
✓ Branch 4 taken 7 times.
✓ Branch 6 taken 260 times.
✓ Branch 10 taken 260 times.
✓ Branch 12 taken 260 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 260 times.
✓ Branch 15 taken 7 times.
✓ Branch 17 taken 260 times.
✓ Branch 18 taken 7 times.
✓ Branch 19 taken 260 times.
✓ Branch 20 taken 7 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
787 } else if (iddField.properties().autosizable && istringEqual(m_fields[index], "autocalculate")) {
1768
13/13
✓ Branch 1 taken 260 times.
✓ Branch 4 taken 260 times.
✓ Branch 7 taken 260 times.
✓ Branch 10 taken 260 times.
✓ Branch 13 taken 260 times.
✓ Branch 16 taken 260 times.
✓ Branch 19 taken 260 times.
✓ Branch 22 taken 260 times.
✓ Branch 25 taken 260 times.
✓ Branch 28 taken 260 times.
✓ Branch 33 taken 260 times.
✓ Branch 36 taken 260 times.
✓ Branch 39 taken 260 times.
260 LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name()
1769 << " has 'autocalculate' as its value even though it is autosizable.");
1770
12/17
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 12 taken 6 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 6 times.
✓ Branch 15 taken 1 time.
✓ Branch 17 taken 6 times.
✓ Branch 18 taken 1 time.
✓ Branch 19 taken 6 times.
✓ Branch 20 taken 1 time.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
19 } else if (iddField.properties().autocalculatable && istringEqual(m_fields[index], "autosize")) {
1771
13/13
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 19 taken 6 times.
✓ Branch 22 taken 6 times.
✓ Branch 25 taken 6 times.
✓ Branch 28 taken 6 times.
✓ Branch 33 taken 6 times.
✓ Branch 36 taken 6 times.
✓ Branch 39 taken 6 times.
6 LOG(Info, "Field " << index << ", '" << iddField.name() << "', of an object of type " << m_iddObject.name()
1772 << " has 'autosize' as its value even though it is autocalculable.");
1773 } else {
1774 9 return false;
1775 }
1776 } else {
1777
3/3
✓ Branch 1 taken 3180332 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3180329 times.
3180332 if (std::isnan(*value)) {
1778
13/13
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 16 taken 3 times.
✓ Branch 19 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 25 taken 3 times.
✓ Branch 28 taken 3 times.
✓ Branch 33 taken 3 times.
✓ Branch 36 taken 3 times.
✓ Branch 39 taken 3 times.
3 LOG(Warn, "Cannot set field " << index << ", '" << iddField.name() << "', an object of type " << m_iddObject.name() << " to NaN.");
1779 3 return false;
1780
3/3
✓ Branch 1 taken 3180329 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 3180324 times.
3180329 } else if (std::isinf(*value)) {
1781
13/13
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
✓ Branch 16 taken 5 times.
✓ Branch 19 taken 5 times.
✓ Branch 22 taken 5 times.
✓ Branch 25 taken 5 times.
✓ Branch 28 taken 5 times.
✓ Branch 33 taken 5 times.
✓ Branch 36 taken 5 times.
✓ Branch 39 taken 5 times.
5 LOG(Warn, "Cannot set field " << index << ", '" << iddField.name() << "', an object of type " << m_iddObject.name() << " to Infinity.");
1782 5 return false;
1783 }
1784 }
1785 }
1786
1787
7/7
✓ Branch 1 taken 8632335 times.
✓ Branch 4 taken 1843798 times.
✓ Branch 5 taken 6788537 times.
✓ Branch 8 taken 1438436 times.
✓ Branch 9 taken 405362 times.
✓ Branch 10 taken 1438436 times.
✓ Branch 11 taken 7193899 times.
8632335 if ((fieldType == IddFieldType::ChoiceType) && (!m_fields[index].empty())) {
1788 // value should iequal one of the keys
1789
1/1
✓ Branch 1 taken 1438436 times.
1438436 IddKeyVector keys = iddField.keys();
1790
1/1
✓ Branch 2 taken 1438436 times.
1438436 NameFinder<IddKey> finder(m_fields[index]);
1791
2/2
✓ Branch 1 taken 1438436 times.
✓ Branch 6 taken 1438436 times.
1438436 auto loc = std::find_if(keys.begin(), keys.end(), finder);
1792
2/2
✓ Branch 2 taken 281 times.
✓ Branch 3 taken 1438155 times.
1438436 if (loc == keys.end()) {
1793 281 return false;
1794 }
1795 1438717 }
1796
1797 8632054 return true;
1798 8632344 }
1799
1800 10932484 bool IdfObject_Impl::fieldDataIsWithinBounds(unsigned index) const {
1801
1/1
✓ Branch 1 taken 10932484 times.
10932484 OptionalIddField oIddField = m_iddObject.getField(index);
1802
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10932484 times.
10932484 if (!oIddField) {
1803 ✗ return true;
1804 } // default to true
1805
1806
1/1
✓ Branch 1 taken 10932484 times.
10932484 IddField iddField = *oIddField;
1807
1/1
✓ Branch 1 taken 10932484 times.
10932484 IddFieldType fieldType = iddField.properties().type;
1808
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 10932484 times.
✗ Branch 4 not taken.
10932484 OS_ASSERT(m_fields.size() > index);
1809
1810
3/3
✓ Branch 1 taken 10932484 times.
✓ Branch 4 taken 664845 times.
✓ Branch 5 taken 10267639 times.
10932484 if (fieldType == IddFieldType::IntegerType) {
1811
1/1
✓ Branch 1 taken 664845 times.
664845 OptionalInt value = getInt(index);
1812
2/2
✓ Branch 0 taken 554021 times.
✓ Branch 1 taken 110824 times.
664845 if (value) {
1813
1/1
✓ Branch 1 taken 554021 times.
554021 auto fieldValue = static_cast<double>(*value);
1814
1/1
✓ Branch 1 taken 554021 times.
554021 return withinBounds(fieldValue, iddField);
1815 }
1816 }
1817
3/3
✓ Branch 1 taken 10378463 times.
✓ Branch 4 taken 4430335 times.
✓ Branch 5 taken 5948128 times.
10378463 if (fieldType == IddFieldType::RealType) {
1818
1/1
✓ Branch 1 taken 4430335 times.
4430335 OptionalDouble value = getDouble(index);
1819
2/2
✓ Branch 0 taken 3180332 times.
✓ Branch 1 taken 1250003 times.
4430335 if (value) {
1820
2/2
✓ Branch 1 taken 3180332 times.
✓ Branch 4 taken 3180332 times.
3180332 return withinBounds(*value, iddField);
1821 }
1822 }
1823
1824 7198131 return true;
1825 10932484 }
1826
1827 27236 bool IdfObject_Impl::fieldIsNonnullIfRequired(unsigned index) const {
1828
1/1
✓ Branch 1 taken 27236 times.
27236 OptionalIddField oIddField = m_iddObject.getField(index);
1829
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 27236 times.
27236 if (!oIddField) {
1830 ✗ return true;
1831 } // default to true
1832
1833
1/1
✓ Branch 1 taken 27236 times.
27236 IddField iddField = *oIddField;
1834
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 27236 times.
✗ Branch 4 not taken.
27236 OS_ASSERT(m_fields.size() > index);
1835
1836
8/10
✓ Branch 1 taken 27236 times.
✓ Branch 3 taken 8242 times.
✓ Branch 4 taken 18994 times.
✓ Branch 6 taken 8242 times.
✓ Branch 8 taken 7945 times.
✓ Branch 9 taken 297 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7945 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 27236 times.
27236 if (iddField.properties().required && (!iddField.isObjectListField()) && m_fields[index].empty()) {
1837 ✗ return false;
1838 }
1839 27236 return true;
1840 27236 }
1841
1842 3734353 bool IdfObject_Impl::withinBounds(double fieldValue, const IddField& iddField) const {
1843
1844 // minimum bounds
1845
1/1
✓ Branch 1 taken 3734353 times.
3734353 OptionalDouble boundValue = iddField.properties().minBoundValue;
1846
1/1
✓ Branch 1 taken 3734353 times.
3734353 IddFieldProperties::BoundTypes boundType = iddField.properties().minBoundType;
1847
2/2
✓ Branch 0 taken 874265 times.
✓ Branch 1 taken 2860088 times.
3734353 if (boundType != IddFieldProperties::Unbounded) {
1848
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 874265 times.
✗ Branch 4 not taken.
874265 OS_ASSERT(boundValue);
1849 // check min bound
1850
2/2
✓ Branch 0 taken 786267 times.
✓ Branch 1 taken 87998 times.
874265 if (boundType == IddFieldProperties::InclusiveBound) {
1851
3/3
✓ Branch 1 taken 786267 times.
✓ Branch 3 taken 294 times.
✓ Branch 4 taken 785973 times.
786267 if (fieldValue < *boundValue) {
1852 294 return false;
1853 }
1854
3/3
✓ Branch 1 taken 87998 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 87838 times.
87998 } else if (fieldValue <= *boundValue) {
1855 160 return false;
1856 }
1857 }
1858
1859 // maximum bounds
1860
1/1
✓ Branch 1 taken 3733899 times.
3733899 boundValue = iddField.properties().maxBoundValue;
1861
1/1
✓ Branch 1 taken 3733899 times.
3733899 boundType = iddField.properties().maxBoundType;
1862
2/2
✓ Branch 0 taken 496149 times.
✓ Branch 1 taken 3237750 times.
3733899 if (boundType != IddFieldProperties::Unbounded) {
1863
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 496149 times.
✗ Branch 4 not taken.
496149 OS_ASSERT(boundValue);
1864
2/2
✓ Branch 0 taken 490820 times.
✓ Branch 1 taken 5329 times.
496149 if (boundType == IddFieldProperties::InclusiveBound) {
1865
3/3
✓ Branch 1 taken 490820 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 490786 times.
490820 if (fieldValue > *boundValue) {
1866 34 return false;
1867 }
1868
3/3
✓ Branch 1 taken 5329 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5324 times.
5329 } else if (fieldValue >= *boundValue) {
1869 5 return false;
1870 }
1871 }
1872
1873 3733860 return true;
1874 }
1875
1876 2 OSOptionalQuantity IdfObject_Impl::getQuantityFromDouble(unsigned index, boost::optional<double> value, bool returnIP) const {
1877
1/1
✓ Branch 1 taken 2 times.
2 OptionalIddField iddField = m_iddObject.getField(index);
1878
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!iddField) {
1879 ✗ LOG_AND_THROW("get/setQuantity not available without an IddField. Asked to getQuantity at "
1880 "field "
1881 << index << "for IdfObject with Idd:\n"
1882 << m_iddObject);
1883 }
1884
1885
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 OptionalUnit siUnit = iddField->getUnits(false);
1886
1/1
✓ Branch 1 taken 2 times.
2 OptionalUnit units = siUnit;
1887 2 OptionalUnit ipUnit;
1888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (returnIP) {
1889 ✗ ipUnit = iddField->getUnits(true);
1890 ✗ units = ipUnit;
1891 }
1892
1893
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (!units) {
1894 ✗ LOG_AND_THROW("Unable to construct a unit for field " << index << " for IdfObject with " << "Idd:\n" << m_iddObject);
1895 }
1896
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(siUnit);
1897
1898
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (value) {
1899
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 Quantity result(*value, *siUnit);
1900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (returnIP) {
1901 ✗ OptionalQuantity temp = convert(result, *ipUnit);
1902 ✗ if (temp) {
1903 ✗ result = *temp;
1904 }
1905 ✗ }
1906
1/1
✓ Branch 1 taken 2 times.
2 return OSOptionalQuantity(result);
1907 2 }
1908
1909 ✗ return OSOptionalQuantity(*units);
1910 2 }
1911
1912 1 boost::optional<double> IdfObject_Impl::getDoubleFromQuantity(unsigned index, const Quantity& q) const {
1913 1 OptionalDouble result;
1914
1915
1/1
✓ Branch 1 taken 1 time.
1 OptionalIddField iddField = m_iddObject.getField(index);
1916
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!iddField) {
1917 ✗ LOG(Error, "get/setQuantity not available without an IddField. Asked to setQuantity at field " << index << "for IdfObject with Idd:\n"
1918 << m_iddObject);
1919 ✗ return result;
1920 }
1921
1922
1/1
✓ Branch 1 taken 1 time.
1 Quantity wq(q);
1923
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 OptionalUnit unit = iddField->getUnits(false);
1924
1925 // dimensionless
1926
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!unit) {
1927 ✗ wq.setScale(0);
1928 ✗ if (wq.standardUnitsString(true).empty()) {
1929 ✗ result = wq.value();
1930 }
1931 ✗ return result;
1932 }
1933
1934 // has unit, convert to it
1935 // (QuantityConverter checks for equality first, sets scale.)
1936
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 OptionalQuantity candidate = convert(wq, *unit);
1937
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if (!candidate) {
1938 ✗ return result;
1939 }
1940
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 wq = *candidate;
1941
1942
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 12 not taken.
1 OS_ASSERT(wq.units() == *unit);
1943
1944
12/12
✓ 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.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
1 LOG(Trace, "Converted " << q << " to " << wq << "to set field with units " << *unit << ".");
1945
1946
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 result = wq.value();
1947 1 return result;
1948 1 }
1949
1950 1820167 std::vector<std::string> IdfObject_Impl::fields() const {
1951 1820167 return m_fields;
1952 }
1953
1954 1820167 std::vector<std::string> IdfObject_Impl::fieldComments() const {
1955 1820167 return m_fieldComments;
1956 }
1957
1958 4873657 std::string IdfObject_Impl::encodeString(const std::string& value) const {
1959 4873657 std::string result;
1960
2/2
✓ Branch 5 taken 48334757 times.
✓ Branch 6 taken 4873657 times.
53208414 for (auto const& s : value) {
1961
4/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 48334617 times.
48334757 switch (s) {
1962 ✗ case '\n':
1963 ✗ result.append("&#10");
1964 ✗ break;
1965 ✗ case '\r':
1966 ✗ result.append("&#13");
1967 ✗ break;
1968 75 case ',':
1969
1/1
✓ Branch 1 taken 75 times.
75 result.append("&#44");
1970 75 break;
1971 3 case ';':
1972
1/1
✓ Branch 1 taken 3 times.
3 result.append("&#59");
1973 3 break;
1974 62 case '!':
1975
1/1
✓ Branch 1 taken 62 times.
62 result.append("&#33");
1976 62 break;
1977 48334617 default:
1978
1/1
✓ Branch 1 taken 48334617 times.
48334617 result.push_back(s);
1979 48334617 break;
1980 }
1981 }
1982 4873657 return result;
1983 ✗ }
1984
1985 53855470 std::string IdfObject_Impl::decodeString(const std::string& value) const {
1986 53855470 std::string result;
1987 char c;
1988 53855470 bool special_char = false;
1989 53855470 auto const max_length = value.size();
1990 53855470 auto const length = max_length - 3;
1991 // auto const * str = value.c_str();
1992
1/1
✓ Branch 1 taken 53855470 times.
53855470 result.reserve(max_length);
1993
1994
2/2
✓ Branch 0 taken 585248585 times.
✓ Branch 1 taken 53855470 times.
639104055 for (size_t i = 0; i < max_length; ++i) {
1995
8/8
✓ Branch 0 taken 451369415 times.
✓ Branch 1 taken 133879170 times.
✓ Branch 3 taken 4084 times.
✓ Branch 4 taken 451365331 times.
✓ Branch 6 taken 1199 times.
✓ Branch 7 taken 2885 times.
✓ Branch 8 taken 1199 times.
✓ Branch 9 taken 585247386 times.
585248585 if (i < length && value[i] == '&' && value[i + 1] == '#') {
1996
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1199 times.
1199 if (value[i + 2] == '1') {
1997 ✗ if (value[i + 3] == '0') {
1998 ✗ special_char = true;
1999 ✗ c = '\n'; // "&#10"
2000 ✗ } else if (value[i + 3] == '3') {
2001 ✗ special_char = true;
2002 ✗ c = '\r'; // "&#13"
2003 }
2004
5/6
✓ Branch 1 taken 911 times.
✓ Branch 2 taken 288 times.
✓ Branch 4 taken 911 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 911 times.
✓ Branch 7 taken 288 times.
1199 } else if (value[i + 2] == '3' && value[i + 3] == '3') {
2005 911 special_char = true;
2006 911 c = '!'; // "&#33"
2007
5/6
✓ Branch 1 taken 221 times.
✓ Branch 2 taken 67 times.
✓ Branch 4 taken 221 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 221 times.
✓ Branch 7 taken 67 times.
288 } else if (value[i + 2] == '4' && value[i + 3] == '4') {
2008 221 special_char = true;
2009 221 c = ','; // "&#44"
2010
3/6
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 67 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 67 times.
✗ Branch 7 not taken.
67 } else if (value[i + 2] == '5' && value[i + 3] == '9') {
2011 67 special_char = true;
2012 67 c = ';'; // "&#59"
2013 }
2014 }
2015
2016
2/2
✓ Branch 0 taken 1199 times.
✓ Branch 1 taken 585247386 times.
585248585 if (special_char) {
2017 1199 special_char = false;
2018 1199 i += 3;
2019
1/1
✓ Branch 1 taken 1199 times.
1199 result.push_back(c);
2020 } else {
2021
1/1
✓ Branch 2 taken 585247386 times.
585247386 result.push_back(value[i]);
2022 }
2023 }
2024 53855470 return result;
2025 ✗ }
2026
2027 } // namespace detail
2028
2029 // CONSTRUCTORS
2030
2031 223420 IdfObject::IdfObject(IddObjectType type, bool fastName) : m_impl(std::make_shared<detail::IdfObject_Impl>(type, fastName)) {
2032
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 223420 times.
✗ Branch 4 not taken.
223420 OS_ASSERT(m_impl);
2033 223420 }
2034
2035 21835 IdfObject::IdfObject(const IddObject& iddObject, bool fastName) : m_impl(std::make_shared<detail::IdfObject_Impl>(iddObject, fastName)) {
2036
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 21835 times.
✗ Branch 4 not taken.
21835 OS_ASSERT(m_impl);
2037 21835 }
2038
2039 56077580 IdfObject::IdfObject(std::shared_ptr<detail::IdfObject_Impl> impl) : m_impl(std::move(impl)) {
2040
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 56077580 times.
✗ Branch 4 not taken.
56077580 OS_ASSERT(m_impl);
2041 56077580 }
2042
2043 15643842 IdfObject::IdfObject(const IdfObject& other) : m_impl(other.m_impl) {
2044
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 15643842 times.
✗ Branch 4 not taken.
15643842 OS_ASSERT(m_impl);
2045 15643842 }
2046
2047 3162 IdfObject& IdfObject::operator=(const IdfObject& other) {
2048 3162 m_impl = other.m_impl;
2049
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3162 times.
3162 OS_ASSERT(m_impl);
2050 3162 return *this;
2051 }
2052
2053 62023548 IdfObject::IdfObject(IdfObject&& other) noexcept : m_impl(std::move(other.m_impl)) {}
2054
2055 10544843 IdfObject& IdfObject::operator=(IdfObject&& other) noexcept {
2056 10544843 m_impl = std::move(other.m_impl);
2057 10544843 return *this;
2058 }
2059
2060 2 IdfObject IdfObject::clone(bool keepHandle) const {
2061
2/2
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
2 IdfObject copy(std::make_shared<detail::IdfObject_Impl>(*m_impl, keepHandle));
2062 2 return copy;
2063 }
2064
2065 // GETTERS
2066
2067 13994426 Handle IdfObject::handle() const {
2068 13994426 return m_impl->handle();
2069 }
2070
2071 55711011 IddObject IdfObject::iddObject() const {
2072 55711011 return m_impl->iddObject();
2073 }
2074
2075 165 std::string IdfObject::comment() const {
2076 165 return m_impl->comment();
2077 }
2078
2079 27 boost::optional<std::string> IdfObject::fieldComment(unsigned index, bool returnDefault) const {
2080 27 return m_impl->fieldComment(index, returnDefault);
2081 }
2082
2083 30494672 boost::optional<std::string> IdfObject::name(bool returnDefault) const {
2084 30494672 return m_impl->name(returnDefault);
2085 }
2086
2087 420047 std::string IdfObject::nameString(bool returnDefault) const {
2088 420047 return m_impl->nameString(returnDefault);
2089 }
2090
2091 69587 std::string IdfObject::briefDescription() const {
2092 69587 return m_impl->briefDescription();
2093 }
2094
2095 908 bool IdfObject::isEmpty(unsigned index) const {
2096 908 return m_impl->isEmpty(index);
2097 }
2098
2099 698130 boost::optional<std::string> IdfObject::getString(unsigned index, bool returnDefault, bool returnUninitializedEmpty) const {
2100 698130 return m_impl->getString(index, returnDefault, returnUninitializedEmpty);
2101 }
2102
2103 ✗ boost::optional<std::string> IdfObject::getField(unsigned index, bool returnDefault) const {
2104 ✗ return m_impl->getField(index, returnDefault);
2105 }
2106
2107 275622 boost::optional<double> IdfObject::getDouble(unsigned index, bool returnDefault) const {
2108 275622 return m_impl->getDouble(index, returnDefault);
2109 }
2110
2111 2 OSOptionalQuantity IdfObject::getQuantity(unsigned index, bool returnDefault, bool returnIP) const {
2112 2 return m_impl->getQuantity(index, returnDefault, returnIP);
2113 }
2114
2115 5 OptionalUnsigned IdfObject::getUnsigned(unsigned index, bool returnDefault) const {
2116 5 return m_impl->getUnsigned(index, returnDefault);
2117 }
2118
2119 155419 OptionalInt IdfObject::getInt(unsigned index, bool returnDefault) const {
2120 155419 return m_impl->getInt(index, returnDefault);
2121 }
2122
2123 1911 IdfExtensibleGroup IdfObject::getExtensibleGroup(unsigned groupIndex) const {
2124 1911 return m_impl->getExtensibleGroup(groupIndex);
2125 }
2126
2127 60061 std::vector<IdfExtensibleGroup> IdfObject::extensibleGroups() const {
2128 60061 return m_impl->extensibleGroups();
2129 }
2130
2131 // SETTERS
2132
2133 73 void IdfObject::setComment(const std::string& msg) {
2134 73 return m_impl->setComment(msg);
2135 }
2136
2137 8 bool IdfObject::setFieldComment(unsigned index, const std::string& cmnt) {
2138 8 return m_impl->setFieldComment(index, cmnt);
2139 }
2140
2141 105276 boost::optional<std::string> IdfObject::setName(const std::string& newName) {
2142 105276 return m_impl->setName(newName);
2143 }
2144
2145 99 boost::optional<std::string> IdfObject::createName(bool overwrite) {
2146 99 return m_impl->createName(overwrite);
2147 }
2148
2149 445924 bool IdfObject::setString(unsigned index, const std::string& value) {
2150 445924 return m_impl->setString(index, value);
2151 }
2152
2153 190625 bool IdfObject::setDouble(unsigned index, double value) {
2154 190625 return m_impl->setDouble(index, value);
2155 }
2156
2157 1 bool IdfObject::setQuantity(unsigned index, const Quantity& q) {
2158 1 return m_impl->setQuantity(index, q);
2159 }
2160
2161 35 bool IdfObject::setUnsigned(unsigned index, unsigned value) {
2162 35 return m_impl->setUnsigned(index, value);
2163 }
2164
2165 10878 bool IdfObject::setInt(unsigned index, int value) {
2166 10878 return m_impl->setInt(index, value);
2167 }
2168
2169 41574 IdfExtensibleGroup IdfObject::pushExtensibleGroup() {
2170
1/1
✓ Branch 2 taken 41574 times.
41574 return pushExtensibleGroup(StringVector());
2171 }
2172
2173 48978 IdfExtensibleGroup IdfObject::pushExtensibleGroup(const StringVector& values) {
2174 48978 return m_impl->pushExtensibleGroup(values);
2175 }
2176
2177 5 IdfExtensibleGroup IdfObject::insertExtensibleGroup(unsigned groupIndex) {
2178
1/1
✓ Branch 2 taken 5 times.
5 return insertExtensibleGroup(groupIndex, StringVector());
2179 }
2180
2181 15 IdfExtensibleGroup IdfObject::insertExtensibleGroup(unsigned groupIndex, const std::vector<std::string>& values) {
2182 15 return m_impl->insertExtensibleGroup(groupIndex, values);
2183 }
2184
2185 3108 std::vector<std::string> IdfObject::popExtensibleGroup() {
2186 3108 return m_impl->popExtensibleGroup();
2187 }
2188
2189 296 std::vector<std::string> IdfObject::eraseExtensibleGroup(unsigned groupIndex) {
2190 296 return m_impl->eraseExtensibleGroup(groupIndex);
2191 }
2192
2193 10658 std::vector<std::vector<std::string>> IdfObject::clearExtensibleGroups() {
2194 10658 return m_impl->clearExtensibleGroups();
2195 }
2196
2197 5 void IdfObject::initializeFields(bool fill_default) {
2198 5 return m_impl->initializeFields(fill_default);
2199 }
2200
2201 // QUERIES
2202
2203 1866733 unsigned IdfObject::numFields() const {
2204 1866733 return m_impl->numFields();
2205 }
2206
2207 2348 unsigned IdfObject::numNonextensibleFields() const {
2208 2348 return m_impl->numNonextensibleFields();
2209 }
2210
2211 2 unsigned IdfObject::minFields() const {
2212 2 return m_impl->minFields();
2213 }
2214
2215 ✗ boost::optional<unsigned> IdfObject::maxFields() const {
2216 ✗ return m_impl->maxFields();
2217 }
2218
2219 1273 unsigned IdfObject::numExtensibleGroups() const {
2220 1273 return m_impl->numExtensibleGroups();
2221 }
2222
2223 ✗ unsigned IdfObject::minExtensibleGroups() const {
2224 ✗ return m_impl->minExtensibleGroups();
2225 }
2226
2227 ✗ boost::optional<unsigned> IdfObject::maxExtensibleGroups() const {
2228 ✗ return m_impl->maxExtensibleGroups();
2229 }
2230
2231 ✗ bool IdfObject::isObjectListField(unsigned index) const {
2232 ✗ return m_impl->isObjectListField(index);
2233 }
2234
2235 2126 std::vector<unsigned> IdfObject::objectListFields() const {
2236 2126 return m_impl->objectListFields();
2237 }
2238
2239 ✗ bool IdfObject::isDataField(unsigned index) const {
2240 ✗ return m_impl->isDataField(index);
2241 }
2242
2243 2268 std::vector<unsigned> IdfObject::dataFields() const {
2244 2268 return m_impl->dataFields();
2245 }
2246
2247 ✗ std::vector<unsigned> IdfObject::requiredFields() const {
2248 ✗ return m_impl->requiredFields();
2249 }
2250
2251 181858 bool IdfObject::isValid(StrictnessLevel level, bool checkNames) const {
2252 181858 return m_impl->isValid(level, checkNames);
2253 }
2254
2255 1365 ValidityReport IdfObject::validityReport(StrictnessLevel level, bool checkNames) const {
2256 1365 return m_impl->validityReport(level, checkNames);
2257 }
2258
2259 2268 bool IdfObject::dataFieldsEqual(const IdfObject& other) const {
2260 2268 return m_impl->dataFieldsEqual(other);
2261 }
2262
2263 ✗ bool IdfObject::objectListFieldsEqual(const IdfObject& other) const {
2264 ✗ return m_impl->objectListFieldsEqual(other);
2265 }
2266
2267 12 bool IdfObject::objectListFieldsNonConflicting(const IdfObject& other) const {
2268 12 return m_impl->objectListFieldsNonConflicting(other);
2269 }
2270
2271 2033130 bool IdfObject::operator==(const IdfObject& other) const {
2272 2033130 return (m_impl == other.m_impl);
2273 }
2274
2275 73728 bool IdfObject::operator!=(const IdfObject& other) const {
2276 73728 return !(operator==(other));
2277 }
2278
2279 // SERIALIZATION
2280
2281 302 OptionalIdfObject IdfObject::load(const std::string& text) {
2282
1/1
✓ Branch 1 taken 302 times.
302 std::shared_ptr<detail::IdfObject_Impl> p = detail::IdfObject_Impl::load(text);
2283
1/2
✓ Branch 1 taken 302 times.
✗ Branch 2 not taken.
302 if (p) {
2284
2/2
✓ Branch 2 taken 302 times.
✓ Branch 5 taken 302 times.
302 return IdfObject(p);
2285 }
2286 ✗ return boost::none;
2287 302 }
2288
2289 1249552 OptionalIdfObject IdfObject::load(const std::string& text, const IddObject& iddObject) {
2290
1/1
✓ Branch 1 taken 1249552 times.
1249552 std::shared_ptr<detail::IdfObject_Impl> p = detail::IdfObject_Impl::load(text, iddObject);
2291
1/2
✓ Branch 1 taken 1249552 times.
✗ Branch 2 not taken.
1249552 if (p) {
2292
2/2
✓ Branch 2 taken 1249552 times.
✓ Branch 5 taken 1249552 times.
1249552 return IdfObject(p);
2293 }
2294 ✗ return boost::none;
2295 1249552 }
2296
2297 10617868 int IdfObject::printedFieldSpace() {
2298 10617868 return 38;
2299 }
2300
2301 959432 std::ostream& IdfObject::print(std::ostream& os) const {
2302 959432 return m_impl->print(os);
2303 }
2304
2305 5 std::ostream& IdfObject::printName(std::ostream& os, bool hasFields) const {
2306 5 return m_impl->printName(os, hasFields);
2307 }
2308
2309 33 std::ostream& IdfObject::printField(std::ostream& os, unsigned index, bool isLastField) const {
2310 33 return m_impl->printField(os, index, isLastField);
2311 }
2312
2313 /** Function object for sorting by name. */
2314 315848 bool IdfObjectNameLess::operator()(const IdfObject& left, const IdfObject& right) const {
2315
1/1
✓ Branch 1 taken 315848 times.
315848 boost::optional<std::string> leftName = left.name();
2316
1/1
✓ Branch 1 taken 315848 times.
315848 boost::optional<std::string> rightName = right.name();
2317
2318 315848 bool result = false;
2319
3/6
✓ Branch 0 taken 315848 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 315848 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 315848 times.
✗ Branch 5 not taken.
631696 if (leftName && rightName) {
2320 // a < b
2321
3/3
✓ Branch 1 taken 315848 times.
✓ Branch 4 taken 315848 times.
✓ Branch 7 taken 315848 times.
315848 result = istringLess(*leftName, *rightName);
2322 ✗ } else if (!leftName && rightName) {
2323 // nil < !nil
2324 ✗ result = true;
2325 }
2326 315848 return result;
2327 315848 }
2328
2329 /** Function object for sorting by impl. */
2330 1423 bool IdfObjectImplLess::operator()(const IdfObject& left, const IdfObject& right) const {
2331 1423 return (left.getImpl<detail::IdfObject_Impl>() < right.getImpl<detail::IdfObject_Impl>());
2332 }
2333
2334 /** Function object for sorting by IddObjectType. */
2335 ✗ bool IdfObjectTypeLess::operator()(const IdfObject& left, const IdfObject& right) const {
2336 ✗ return (left.iddObject().type() < right.iddObject().type());
2337 }
2338
2339 // ostream operator
2340 860303 std::ostream& operator<<(std::ostream& os, const IdfObject& idfObject) {
2341 860303 return idfObject.print(os);
2342 }
2343
2344 ✗ std::string objectName(const IdfObject& obj) {
2345 ✗ std::string result;
2346 ✗ if (obj.name()) {
2347 ✗ result = obj.name().get();
2348 } else {
2349 ✗ result = obj.iddObject().name();
2350 }
2351 ✗ return result;
2352 ✗ }
2353
2354 } // namespace openstudio
2355