GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 66.1% 123 / 0 / 186
Functions: 69.8% 30 / 0 / 43
Branches: 56.8% 108 / 0 / 190

src/model/PortList.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 "PortList.hpp"
7 #include "PortList_Impl.hpp"
8 #include "Connection.hpp"
9 #include "Connection_Impl.hpp"
10 #include "Node.hpp"
11 #include "Node_Impl.hpp"
12 #include "Model.hpp"
13 #include "Model_Impl.hpp"
14 #include "ThermalZone.hpp"
15 #include "ThermalZone_Impl.hpp"
16 #include "HVACComponent.hpp"
17 #include "HVACComponent_Impl.hpp"
18 #include <utilities/idd/OS_PortList_FieldEnums.hxx>
19 #include <utilities/idd/OS_ThermalZone_FieldEnums.hxx>
20 #include <utilities/idd/IddEnums.hxx>
21 #include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
22 #include "../utilities/core/Assert.hpp"
23
24 namespace openstudio {
25
26 namespace model {
27
28 namespace detail {
29
30 11227 PortList_Impl::PortList_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : ModelObject_Impl(idfObject, model, keepHandle) {
31
4/6
✓ Branch 1 taken 11227 times.
✓ Branch 4 taken 11227 times.
✓ Branch 7 taken 11227 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 11227 times.
✗ Branch 13 not taken.
11227 OS_ASSERT(idfObject.iddObject().type() == PortList::iddObjectType());
32 11227 }
33
34 4071 PortList_Impl::PortList_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
35 4071 : ModelObject_Impl(other, model, keepHandle) {
36
4/6
✓ Branch 1 taken 4071 times.
✓ Branch 4 taken 4071 times.
✓ Branch 7 taken 4071 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4071 times.
✗ Branch 13 not taken.
4071 OS_ASSERT(other.iddObject().type() == PortList::iddObjectType());
37 4071 }
38
39 1830 PortList_Impl::PortList_Impl(const PortList_Impl& other, Model_Impl* model, bool keepHandle) : ModelObject_Impl(other, model, keepHandle) {}
40
41 3 const std::vector<std::string>& PortList_Impl::outputVariableNames() const {
42
3/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
3 static const std::vector<std::string> result;
43 3 return result;
44 }
45
46 3 IddObjectType PortList_Impl::iddObjectType() const {
47 3 return PortList::iddObjectType();
48 }
49
50 6549 ThermalZone PortList_Impl::thermalZone() const {
51 6549 boost::optional<ThermalZone> result;
52
53 //std::vector<ThermalZone> thermalZones = model().getConcreteModelObjects<ThermalZone>();
54
55 //for( std::vector<ThermalZone>::iterator it = thermalZones.begin();
56 // it != thermalZones.end();
57 // it++ )
58 //{
59 // if( boost::optional<WorkspaceObject> wo = it->getTarget(OS_ThermalZoneFields::ZoneAirInletPortList) )
60 // {
61 // if( wo->handle() == handle() )
62 // {
63 // result = it->optionalCast<ThermalZone>();
64
65 // break;
66 // }
67 // }
68
69 // if( boost::optional<WorkspaceObject> wo = it->getTarget(OS_ThermalZoneFields::ZoneAirExhaustPortList) )
70 // {
71 // if( wo->handle() == handle() )
72 // {
73 // result = it->optionalCast<ThermalZone>();
74
75 // break;
76 // }
77 // }
78 //}
79
80
2/2
✓ Branch 1 taken 6549 times.
✓ Branch 4 taken 6549 times.
6549 result = hvacComponent().optionalCast<ThermalZone>();
81
82
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 6549 times.
✗ Branch 4 not taken.
6549 OS_ASSERT(result);
83
84
2/2
✓ Branch 1 taken 6549 times.
✓ Branch 4 taken 6549 times.
13098 return result.get();
85 6549 }
86
87 87 std::vector<openstudio::IdfObject> PortList_Impl::remove() {
88 //std::vector<Node> nodes = this->nodes();
89
90 //for( std::vector<Node>::iterator it = nodes.begin();
91 // it < nodes.end();
92 // it++ )
93 //{
94 // removeNode(*it);
95 //}
96
97 87 return ModelObject_Impl::remove();
98 }
99
100 58691 unsigned PortList_Impl::port(unsigned portIndex) const {
101 unsigned result;
102 58691 result = numNonextensibleFields();
103 58691 result = result + portIndex;
104 58691 return result;
105 }
106
107 ✗ unsigned PortList_Impl::portIndex(unsigned port) const {
108 unsigned result;
109 ✗ result = numNonextensibleFields();
110 ✗ result = port - result;
111 ✗ return result;
112 }
113
114 893 unsigned PortList_Impl::nextPort() const {
115 893 return port(nextPortIndex());
116 }
117
118 7332 boost::optional<ModelObject> PortList_Impl::modelObject(unsigned portIndex) const {
119 7332 return connectedObject(port(portIndex));
120 }
121
122 31 boost::optional<ModelObject> PortList_Impl::lastModelObject() {
123
1/1
✓ Branch 1 taken 31 times.
31 std::vector<ModelObject> objects = modelObjects();
124
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 11 times.
31 if (!objects.empty()) {
125
1/1
✓ Branch 2 taken 20 times.
20 return OptionalModelObject(objects.back());
126 } else {
127 11 return {};
128 }
129 31 }
130
131 27285 std::vector<ModelObject> PortList_Impl::modelObjects() const {
132 27285 std::vector<ModelObject> result;
133
3/3
✓ Branch 1 taken 34553 times.
✓ Branch 3 taken 7268 times.
✓ Branch 4 taken 27285 times.
34553 for (int i = 0; i <= int(nextPortIndex()) - 1; i++) {
134
3/3
✓ Branch 1 taken 7268 times.
✓ Branch 4 taken 7268 times.
✓ Branch 7 taken 7268 times.
7268 result.push_back(this->modelObject(i).get());
135 }
136 27285 return result;
137 ✗ }
138
139 ✗ unsigned PortList_Impl::newPortAfterIndex(unsigned portIndex) {
140 //std::vector<ModelObject> modelObjects = this->modelObjects();
141 ✗ for (int i = portIndex; i < int(nextPortIndex()) - 1; i++) {
142 ✗ ModelObject mo = modelObject(i).get();
143 ✗ unsigned port = connectedObjectPort(this->port(i)).get();
144 ✗ model().connect(getObject<ModelObject>(), this->port(i + 2), mo, port);
145 ✗ }
146
147 ✗ Model _model = model();
148 ✗ Node node(_model);
149
150 ✗ _model.connect(getObject<ModelObject>(), this->port(portIndex + 1), node, node.inletPort());
151
152 ✗ return this->port(portIndex++);
153 ✗ }
154
155 62 unsigned PortList_Impl::portIndexForModelObject(ModelObject& modelObject, bool* ok) const {
156
1/2
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
64 for (unsigned i = 0; i < nextPortIndex(); i++) {
157
4/4
✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 62 times.
✓ Branch 8 taken 2 times.
64 if (this->modelObject(i) == modelObject) {
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (ok) {
159 ✗ *ok = true;
160 }
161 62 return i;
162 }
163 }
164 ✗ if (ok) {
165 ✗ *ok = false;
166 }
167 ✗ return 0;
168 }
169
170 35510 unsigned PortList_Impl::nextPortIndex() const {
171 35510 unsigned i = 0;
172 35510 OptionalModelObject modelObject;
173
2/2
✓ Branch 1 taken 35510 times.
✓ Branch 4 taken 35510 times.
35510 modelObject = connectedObject(this->port(i));
174
2/2
✓ Branch 0 taken 14872 times.
✓ Branch 1 taken 35510 times.
85892 while (modelObject) {
175 14872 i++;
176
2/2
✓ Branch 1 taken 14872 times.
✓ Branch 4 taken 14872 times.
14872 modelObject = connectedObject(this->port(i));
177 }
178 35510 return i;
179 35510 }
180
181 94 void PortList_Impl::removePort(unsigned port) {
182 94 unsigned t_numFields = numFields();
183
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 94 times.
102 for (unsigned i = port + 1; i < t_numFields; i++) {
184
3/4
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
16 if (boost::optional<Connection> connection = getObject<ModelObject>().getModelObjectTarget<Connection>(i)) {
185
3/4
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
16 if (boost::optional<ModelObject> targetObject = connection->targetObject()) {
186
6/6
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
✓ Branch 10 taken 8 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 4 times.
8 if (targetObject->handle() == handle()) {
187
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 connection->setTargetObjectPort(i - 1);
188 4 continue;
189 }
190 8 }
191
192
3/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
8 if (boost::optional<ModelObject> sourceObject = connection->sourceObject()) {
193
5/6
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 if (sourceObject->handle() == handle()) {
194
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 connection->setSourceObjectPort(i - 1);
195 4 continue;
196 }
197 4 }
198 8 }
199 }
200
2/2
✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
94 eraseExtensibleGroup(port - numNonextensibleFields());
201 94 }
202
203 ✗ std::vector<unsigned> PortList_Impl::airLoopHVACPortIndexes() const {
204 ✗ std::vector<unsigned> result;
205
206 ✗ std::vector<ModelObject> objects = modelObjects();
207 ✗ for (const auto& elem : objects) {
208 ✗ if (boost::optional<HVACComponent> hvacComponent = elem.optionalCast<HVACComponent>()) {
209 ✗ if (hvacComponent->airLoopHVAC()) {
210 ✗ result.push_back(portIndexForModelObject(hvacComponent.get()));
211 }
212 ✗ }
213 }
214
215 ✗ return result;
216 ✗ }
217
218 ✗ unsigned PortList_Impl::airLoopHVACPortIndex() const {
219 ✗ std::vector<ModelObject> objects = modelObjects();
220
221 ✗ for (const auto& elem : objects) {
222 ✗ if (boost::optional<HVACComponent> hvacComponent = elem.optionalCast<HVACComponent>()) {
223 ✗ if (hvacComponent->airLoopHVAC()) {
224 ✗ return portIndexForModelObject(hvacComponent.get());
225 }
226 ✗ }
227 }
228
229 ✗ return nextPortIndex();
230 ✗ }
231
232 ✗ unsigned PortList_Impl::airLoopHVACPort() const {
233 ✗ unsigned portIndex = airLoopHVACPortIndex();
234
235 ✗ return port(portIndex);
236 }
237
238 ✗ std::vector<unsigned> PortList_Impl::airLoopHVACPorts() const {
239 ✗ std::vector<unsigned> result;
240
241 ✗ auto indexes = airLoopHVACPortIndexes();
242 ✗ for (auto index : indexes) {
243 ✗ result.push_back(port(index));
244 }
245
246 ✗ return result;
247 ✗ }
248
249 122 boost::optional<ModelObject> PortList_Impl::airLoopHVACModelObject() const {
250 122 boost::optional<ModelObject> result;
251
252
1/1
✓ Branch 1 taken 122 times.
122 std::vector<ModelObject> objects = modelObjects();
253
2/2
✓ Branch 5 taken 113 times.
✓ Branch 6 taken 122 times.
235 for (const auto& elem : objects) {
254
2/3
✓ Branch 1 taken 113 times.
✓ Branch 3 taken 113 times.
✗ Branch 4 not taken.
226 if (boost::optional<HVACComponent> hvacComponent = elem.optionalCast<HVACComponent>()) {
255
4/4
✓ Branch 1 taken 113 times.
✓ Branch 4 taken 113 times.
✓ Branch 7 taken 107 times.
✓ Branch 8 taken 6 times.
226 if (hvacComponent->airLoopHVAC()) {
256
1/1
✓ Branch 1 taken 107 times.
107 result = hvacComponent;
257 }
258 113 }
259 }
260
261 244 return result;
262 122 }
263
264 20438 std::vector<ModelObject> PortList_Impl::airLoopHVACModelObjects() const {
265 20438 std::vector<ModelObject> result;
266
267
1/1
✓ Branch 1 taken 20438 times.
20438 std::vector<ModelObject> objects = modelObjects();
268
2/2
✓ Branch 5 taken 510 times.
✓ Branch 6 taken 20438 times.
20948 for (const auto& elem : objects) {
269
2/3
✓ Branch 1 taken 510 times.
✓ Branch 3 taken 510 times.
✗ Branch 4 not taken.
1020 if (boost::optional<HVACComponent> hvacComponent = elem.optionalCast<HVACComponent>()) {
270
3/4
✓ Branch 1 taken 510 times.
✓ Branch 4 taken 510 times.
✓ Branch 7 taken 510 times.
✗ Branch 8 not taken.
1020 if (hvacComponent->airLoopHVAC()) {
271
2/2
✓ Branch 1 taken 510 times.
✓ Branch 4 taken 510 times.
510 result.push_back(hvacComponent.get());
272 }
273 510 }
274 }
275
276 40876 return result;
277 20438 }
278
279 6597 HVACComponent PortList_Impl::hvacComponent() const {
280 6597 boost::optional<HVACComponent> result;
281
282
2/2
✓ Branch 1 taken 6597 times.
✓ Branch 4 taken 6597 times.
6597 result = getObject<ModelObject>().getModelObjectTarget<HVACComponent>(OS_PortListFields::HVACComponent);
283
284
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 6597 times.
✗ Branch 4 not taken.
6597 OS_ASSERT(result);
285
286
2/2
✓ Branch 1 taken 6597 times.
✓ Branch 4 taken 6597 times.
13194 return result.get();
287 6597 }
288
289 7153 bool PortList_Impl::setHVACComponent(const HVACComponent& hvacComponent) {
290
2/2
✓ Branch 1 taken 7153 times.
✓ Branch 4 taken 7153 times.
7153 return setPointer(OS_PortListFields::HVACComponent, hvacComponent.handle());
291 }
292
293 } // namespace detail
294
295 7153 PortList::PortList(const HVACComponent& comp)
296
3/3
✓ Branch 1 taken 7153 times.
✓ Branch 4 taken 7153 times.
✓ Branch 7 taken 7153 times.
7153 : ModelObject(PortList::iddObjectType(), comp.model(), false) // No FastName
297 {
298
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 7153 times.
✗ Branch 5 not taken.
7153 OS_ASSERT(getImpl<detail::PortList_Impl>());
299
300
1/1
✓ Branch 3 taken 7153 times.
7153 getImpl<detail::PortList_Impl>()->setHVACComponent(comp);
301 7153 }
302
303 30185 IddObjectType PortList::iddObjectType() {
304
1/1
✓ Branch 1 taken 30185 times.
30185 return {IddObjectType::OS_PortList};
305 }
306
307 84 unsigned PortList::port(unsigned portIndex) const {
308
1/1
✓ Branch 3 taken 84 times.
84 return getImpl<detail::PortList_Impl>()->port(portIndex);
309 }
310
311 ✗ unsigned PortList::portIndex(unsigned port) const {
312 ✗ return getImpl<detail::PortList_Impl>()->portIndex(port);
313 }
314
315 893 unsigned PortList::nextPort() const {
316
1/1
✓ Branch 3 taken 893 times.
893 return getImpl<detail::PortList_Impl>()->nextPort();
317 }
318
319 ✗ boost::optional<ModelObject> PortList::modelObject(unsigned portIndex) const {
320 ✗ return getImpl<detail::PortList_Impl>()->modelObject(portIndex);
321 }
322
323 31 boost::optional<ModelObject> PortList::lastModelObject() {
324
1/1
✓ Branch 3 taken 31 times.
31 return getImpl<detail::PortList_Impl>()->lastModelObject();
325 }
326
327 6694 std::vector<ModelObject> PortList::modelObjects() const {
328
1/1
✓ Branch 3 taken 6694 times.
6694 return getImpl<detail::PortList_Impl>()->modelObjects();
329 }
330
331 62 unsigned PortList::portIndexForModelObject(ModelObject& modelObject) const {
332
1/1
✓ Branch 3 taken 62 times.
62 return getImpl<detail::PortList_Impl>()->portIndexForModelObject(modelObject);
333 }
334
335 ✗ unsigned PortList::nextPortIndex() const {
336 ✗ return getImpl<detail::PortList_Impl>()->nextPortIndex();
337 }
338
339 6549 ThermalZone PortList::thermalZone() const {
340
1/1
✓ Branch 3 taken 6549 times.
6549 return getImpl<detail::PortList_Impl>()->thermalZone();
341 }
342
343 ✗ unsigned PortList::airLoopHVACPort() const {
344 ✗ return getImpl<detail::PortList_Impl>()->airLoopHVACPort();
345 }
346
347 ✗ std::vector<unsigned> PortList::airLoopHVACPorts() const {
348 ✗ return getImpl<detail::PortList_Impl>()->airLoopHVACPorts();
349 }
350
351 ✗ unsigned PortList::airLoopHVACPortIndex() const {
352 ✗ return getImpl<detail::PortList_Impl>()->airLoopHVACPortIndex();
353 }
354
355 ✗ std::vector<unsigned> PortList::airLoopHVACPortIndexes() const {
356 ✗ return getImpl<detail::PortList_Impl>()->airLoopHVACPortIndexes();
357 }
358
359 122 boost::optional<ModelObject> PortList::airLoopHVACModelObject() const {
360
1/1
✓ Branch 3 taken 122 times.
122 return getImpl<detail::PortList_Impl>()->airLoopHVACModelObject();
361 }
362
363 20438 std::vector<ModelObject> PortList::airLoopHVACModelObjects() const {
364
1/1
✓ Branch 3 taken 20438 times.
20438 return getImpl<detail::PortList_Impl>()->airLoopHVACModelObjects();
365 }
366
367 /// @cond
368
1/1
✓ Branch 3 taken 35026 times.
35026 PortList::PortList(std::shared_ptr<detail::PortList_Impl> impl) : ModelObject(std::move(impl)) {}
369 /// @endcond
370
371 } // namespace model
372 } // namespace openstudio
373