GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 63.9% 69 / 0 / 108
Functions: 71.4% 10 / 0 / 14
Branches: 65.1% 71 / 0 / 109

src/model/ParentObject.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 "ParentObject.hpp"
7 #include "ParentObject_Impl.hpp"
8 #include "ResourceObject.hpp"
9 #include "ResourceObject_Impl.hpp"
10 #include "Curve.hpp"
11 #include "Curve_Impl.hpp"
12 #include "LifeCycleCost.hpp"
13 #include "Component.hpp"
14 #include "AdditionalProperties.hpp"
15 #include "AdditionalProperties_Impl.hpp"
16
17 #include "../utilities/idf/Workspace_Impl.hpp"
18
19 #include "../utilities/core/Assert.hpp"
20 #include "../utilities/core/ContainersMove.hpp"
21
22 #include <deque>
23
24 namespace openstudio {
25 namespace model {
26
27 namespace detail {
28
29 162084 ParentObject_Impl::ParentObject_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
30 162084 : ModelObject_Impl(idfObject, model, keepHandle) {}
31
32 ✗ ParentObject_Impl::ParentObject_Impl(IddObjectType type, Model_Impl* model) : ModelObject_Impl(type, model) {}
33
34 52531 ParentObject_Impl::ParentObject_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
35 52531 : ModelObject_Impl(other, model, keepHandle) {}
36
37 65685 ParentObject_Impl::ParentObject_Impl(const ParentObject_Impl& other, Model_Impl* model, bool keepHandle)
38 65685 : ModelObject_Impl(other, model, keepHandle) {}
39
40 15362 std::vector<ModelObject> ParentObject_Impl::children() const {
41 15362 return {};
42 }
43
44 /// remove self and all children objects recursively
45 1755 std::vector<IdfObject> ParentObject_Impl::remove() {
46 1755 std::vector<IdfObject> result;
47
48 // DLM: the following code does not work because subTree includes this object
49 // and we don't want to call remove on the same object recursively
50 //
51 //ModelObjectVector subTree = getRecursiveChildren(getObject<ParentObject>());
52 //for (ModelObject& object : subTree) {
53 // std::vector<IdfObject> removed = object.remove();
54 // result.insert(result.end(), removed.begin(), removed.end());
55 //}
56
57 // subTree includes this object, make sure to include costs as well
58 // drop the ResourceObject instances, if they are used by other objects
59 // This is probably the unique situation where you want to get children minus ResourceObjects
60
2/2
✓ Branch 1 taken 1755 times.
✓ Branch 4 taken 1755 times.
1755 auto subTree = getRecursiveChildren(getObject<ParentObject>(), true, false);
61
1/1
✓ Branch 2 taken 1755 times.
1755 result.reserve(subTree.size());
62
2/2
✓ Branch 4 taken 3684 times.
✓ Branch 5 taken 1755 times.
5439 for (const ModelObject& object : subTree) {
63
2/2
✓ Branch 1 taken 3684 times.
✓ Branch 4 taken 3684 times.
3684 result.emplace_back(object.idfObject());
64 }
65
66
3/3
✓ Branch 1 taken 1755 times.
✓ Branch 4 taken 1755 times.
✓ Branch 7 taken 1755 times.
1755 bool ok = model().removeObjects(getHandles<ModelObject>(subTree));
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1755 times.
1755 if (!ok) {
68 ✗ result.clear();
69 }
70
71 3510 return result;
72 1755 }
73
74 /// get a vector of allowable children types
75 ✗ std::vector<IddObjectType> ParentObject_Impl::allowableChildTypes() const {
76 ✗ IddObjectTypeVector result;
77 ✗ return result;
78 }
79
80 4823 ModelObject ParentObject_Impl::clone(Model model) const {
81
2/2
✓ Branch 1 taken 4823 times.
✓ Branch 4 taken 4823 times.
4823 ModelObject newParentAsModelObject = ModelObject_Impl::clone(model);
82
1/1
✓ Branch 1 taken 4823 times.
4823 auto newParent = newParentAsModelObject.cast<ParentObject>();
83
3/3
✓ Branch 1 taken 4823 times.
✓ Branch 8 taken 3210 times.
✓ Branch 9 taken 4823 times.
8033 for (const ModelObject& child : children()) {
84
2/2
✓ Branch 1 taken 3210 times.
✓ Branch 4 taken 3210 times.
3210 ModelObject newChild = child.clone(model);
85
1/1
✓ Branch 1 taken 3210 times.
3210 newChild.setParent(newParent);
86 8033 }
87 9646 return newParentAsModelObject;
88 4823 }
89
90 } // namespace detail
91
92 109179 ParentObject::ParentObject(IddObjectType type, const Model& model) : ModelObject(type, model) {
93
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 109179 times.
✗ Branch 5 not taken.
109179 OS_ASSERT(getImpl<detail::ParentObject_Impl>());
94 109179 }
95
96
1/1
✓ Branch 3 taken 7167945 times.
7167945 ParentObject::ParentObject(std::shared_ptr<detail::ParentObject_Impl> impl) : ModelObject(std::move(impl)) {}
97
98 /// return any children objects in the hierarchy
99 37248 ModelObjectVector ParentObject::children() const {
100
1/1
✓ Branch 3 taken 37248 times.
37248 return getImpl<detail::ParentObject_Impl>()->children();
101 }
102
103 /// get a vector of allowable children types
104 ✗ std::vector<IddObjectType> ParentObject::allowableChildTypes() const {
105 ✗ return getImpl<detail::ParentObject_Impl>()->allowableChildTypes();
106 }
107
108 2497 std::vector<ModelObject> getRecursiveChildren(const ParentObject& object, bool includeLifeCycleCostsAndAdditionalProperties,
109 bool includeUsedResources) {
110 2497 std::set<Handle> resultSet;
111 2497 std::pair<HandleSet::const_iterator, bool> insertResult;
112
2/2
✓ Branch 1 taken 2497 times.
✓ Branch 4 taken 2497 times.
2497 resultSet.insert(object.handle());
113 2497 std::vector<ModelObject> result;
114
1/1
✓ Branch 1 taken 2497 times.
2497 result.push_back(object);
115
116
1/2
✓ Branch 0 taken 2497 times.
✗ Branch 1 not taken.
2497 if (includeLifeCycleCostsAndAdditionalProperties) {
117
2/2
✓ Branch 1 taken 2497 times.
✓ Branch 4 taken 2497 times.
2497 openstudio::detail::concat_helper(result, object.lifeCycleCosts());
118
3/3
✓ Branch 1 taken 2497 times.
✓ Branch 3 taken 189 times.
✓ Branch 4 taken 2308 times.
2497 if (object.hasAdditionalProperties()) {
119
2/2
✓ Branch 1 taken 189 times.
✓ Branch 4 taken 189 times.
189 result.push_back(object.additionalProperties());
120 }
121 }
122
123
1/1
✓ Branch 1 taken 2497 times.
2497 std::deque<ParentObject> parents;
124
1/1
✓ Branch 1 taken 2497 times.
2497 parents.push_back(object);
125
126
2/2
✓ Branch 1 taken 3697 times.
✓ Branch 2 taken 2497 times.
6194 while (!parents.empty()) {
127
1/1
✓ Branch 2 taken 3697 times.
3697 ParentObject currentParent(parents[0]);
128 3697 parents.pop_front();
129
130 // parent's costs have already been added
131
132
3/3
✓ Branch 1 taken 3697 times.
✓ Branch 8 taken 1504 times.
✓ Branch 9 taken 3697 times.
5201 for (const ModelObject& child : currentParent.children()) {
133
2/2
✓ Branch 0 taken 1436 times.
✓ Branch 1 taken 68 times.
1504 if (!includeUsedResources) {
134
1/1
✓ Branch 1 taken 1436 times.
1436 auto _ro = child.optionalCast<ResourceObject>();
135
8/8
✓ Branch 0 taken 638 times.
✓ Branch 1 taken 798 times.
✓ Branch 3 taken 638 times.
✓ Branch 6 taken 638 times.
✓ Branch 8 taken 83 times.
✓ Branch 9 taken 555 times.
✓ Branch 10 taken 83 times.
✓ Branch 11 taken 1353 times.
1436 if (_ro && _ro->directUseCount() > 1) {
136 83 continue;
137 }
138 1436 }
139
2/2
✓ Branch 1 taken 1421 times.
✓ Branch 4 taken 1421 times.
1421 insertResult = resultSet.insert(child.handle());
140
2/2
✓ Branch 0 taken 1413 times.
✓ Branch 1 taken 8 times.
1421 if (insertResult.second) {
141
1/1
✓ Branch 1 taken 1413 times.
1413 result.push_back(child);
142
143
1/2
✓ Branch 0 taken 1413 times.
✗ Branch 1 not taken.
1413 if (includeLifeCycleCostsAndAdditionalProperties) {
144
2/2
✓ Branch 1 taken 1413 times.
✓ Branch 4 taken 1413 times.
1413 openstudio::detail::concat_helper(result, child.lifeCycleCosts());
145
3/3
✓ Branch 1 taken 1413 times.
✓ Branch 3 taken 389 times.
✓ Branch 4 taken 1024 times.
1413 if (child.hasAdditionalProperties()) {
146
2/2
✓ Branch 1 taken 389 times.
✓ Branch 4 taken 389 times.
389 result.emplace_back(child.additionalProperties());
147 }
148 }
149
150
1/1
✓ Branch 1 taken 1413 times.
1413 OptionalParentObject opo = child.optionalCast<ParentObject>();
151
2/2
✓ Branch 0 taken 1200 times.
✓ Branch 1 taken 213 times.
1413 if (opo) {
152
2/2
✓ Branch 1 taken 1200 times.
✓ Branch 4 taken 1200 times.
1200 parents.push_back(*opo);
153 }
154 1413 }
155 3697 }
156 3697 }
157
158 4994 return result;
159 2497 }
160
161 ✗ std::vector<ModelObject> getRecursiveChildrenAndResources(const ModelObject& object) {
162 ✗ std::set<Handle> resultSet;
163 ✗ std::pair<HandleSet::const_iterator, bool> insertResult;
164 ✗ std::vector<ModelObject> result;
165 ✗ resultSet.insert(object.handle());
166 ✗ result.push_back(object);
167
168 ✗ std::deque<ModelObject> objectQueue;
169 ✗ objectQueue.push_back(object);
170
171 ✗ while (!objectQueue.empty()) {
172 ✗ ModelObject currentObject(objectQueue[0]);
173 ✗ objectQueue.pop_front();
174 // resources
175 ✗ for (const ResourceObject& resource : currentObject.resources()) {
176 ✗ insertResult = resultSet.insert(resource.handle());
177 ✗ if (insertResult.second) {
178 // new object
179 ✗ auto mo = resource.cast<ModelObject>();
180 ✗ result.push_back(mo);
181 ✗ objectQueue.push_back(mo);
182 ✗ }
183 ✗ }
184 // children
185 ✗ OptionalParentObject opo = currentObject.optionalCast<ParentObject>();
186 ✗ if (opo) {
187 ✗ ParentObject currentParent(*opo);
188 ✗ for (const ModelObject& child : currentParent.children()) {
189 ✗ insertResult = resultSet.insert(child.handle());
190 ✗ if (insertResult.second) {
191 // new object
192 ✗ result.push_back(child);
193 ✗ objectQueue.push_back(child);
194 }
195 ✗ }
196 ✗ }
197 ✗ }
198
199 ✗ return result;
200 ✗ }
201
202 } // namespace model
203 } // namespace openstudio
204