GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 73.3% 74 / 0 / 101
Functions: 71.4% 20 / 0 / 28
Branches: 36.9% 58 / 0 / 157

src/model/ComponentData.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 "ComponentData.hpp"
7 #include "ComponentData_Impl.hpp"
8
9 #include "Model.hpp"
10 #include "ModelExtensibleGroup.hpp"
11
12 #include "../utilities/idf/IdfExtensibleGroup.hpp"
13 #include <utilities/idd/OS_ComponentData_FieldEnums.hxx>
14 #include <utilities/idd/IddEnums.hxx>
15
16 #include "../utilities/core/Assert.hpp"
17
18 #include <ctime>
19
20 namespace openstudio {
21 namespace model {
22
23 namespace detail {
24
25 244 ComponentData_Impl::ComponentData_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
26 244 : ResourceObject_Impl(idfObject, model, keepHandle) {
27
4/6
✓ Branch 1 taken 244 times.
✓ Branch 4 taken 244 times.
✓ Branch 7 taken 244 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 244 times.
✗ Branch 13 not taken.
244 OS_ASSERT(idfObject.iddObject().type() == ComponentData::iddObjectType());
28 244 }
29
30 115 ComponentData_Impl::ComponentData_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
31 115 : ResourceObject_Impl(other, model, keepHandle) {
32
4/6
✓ Branch 1 taken 115 times.
✓ Branch 4 taken 115 times.
✓ Branch 7 taken 115 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 115 times.
✗ Branch 13 not taken.
115 OS_ASSERT(other.iddObject().type() == ComponentData::iddObjectType());
33 115 }
34
35 513 ComponentData_Impl::ComponentData_Impl(const ComponentData_Impl& other, Model_Impl* model, bool keepHandle)
36 513 : ResourceObject_Impl(other, model, keepHandle) {}
37
38 ✗ const std::vector<std::string>& ComponentData_Impl::outputVariableNames() const {
39 ✗ static const std::vector<std::string> result;
40 ✗ return result;
41 }
42
43 ✗ IddObjectType ComponentData_Impl::iddObjectType() const {
44 ✗ return ComponentData::iddObjectType();
45 }
46
47 11 UUID ComponentData_Impl::uuid() const {
48
1/1
✓ Branch 1 taken 11 times.
11 OptionalString os = getString(OS_ComponentDataFields::UUID);
49
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 4 not taken.
11 OS_ASSERT(os);
50
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
22 return toUUID(*os);
51 11 }
52
53 163 UUID ComponentData_Impl::versionUUID() const {
54
1/1
✓ Branch 1 taken 163 times.
163 OptionalString os = getString(OS_ComponentDataFields::VersionUUID);
55
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 163 times.
✗ Branch 4 not taken.
163 OS_ASSERT(os);
56
2/2
✓ Branch 1 taken 163 times.
✓ Branch 4 taken 163 times.
326 return toUUID(*os);
57 163 }
58
59 ✗ boost::optional<int> ComponentData_Impl::creationTimestamp() const {
60 ✗ return getInt(OS_ComponentDataFields::CreationTimestamp, true);
61 }
62
63 ✗ boost::optional<int> ComponentData_Impl::versionTimestamp() const {
64 ✗ return getInt(OS_ComponentDataFields::VersionTimestamp, true);
65 }
66
67 29 ModelObject ComponentData_Impl::primaryComponentObject() const {
68
2/2
✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
29 OptionalModelObject omo = getComponentObject(0);
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 29 times.
29 if (!omo) {
70 ✗ LOG_AND_THROW("ComponentData objects must always be able to return the primary object in the component.");
71 }
72
2/2
✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
58 return *omo;
73 29 }
74
75 8 std::vector<ModelObject> ComponentData_Impl::componentObjects() const {
76 8 ModelObjectVector result;
77
3/3
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 44 times.
✓ Branch 4 taken 8 times.
52 for (unsigned i = 0, n = numComponentObjects(); i < n; ++i) {
78
2/2
✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
44 result.push_back(getComponentObject(i));
79 }
80 8 return result;
81 ✗ }
82
83 1238 ModelObject ComponentData_Impl::getComponentObject(unsigned objectIndex) const {
84
2/3
✓ Branch 1 taken 1238 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1238 times.
1238 if (objectIndex >= numComponentObjects()) {
85 ✗ LOG_AND_THROW("objectIndex = " << objectIndex << " >= numComponentObjects() = " << numComponentObjects() << ".");
86 }
87
88
1/1
✓ Branch 1 taken 1238 times.
1238 IdfExtensibleGroup eg = getExtensibleGroup(objectIndex);
89
2/3
✓ Branch 1 taken 1238 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1238 times.
1238 if (eg.empty()) {
90 ✗ LOG_AND_THROW("Cannot retrieve IdfExtensibleGroup at objectIndex = " << objectIndex);
91 }
92
93
1/1
✓ Branch 1 taken 1238 times.
1238 auto componentObjectData = eg.cast<ModelExtensibleGroup>();
94
1/1
✓ Branch 1 taken 1238 times.
1238 OptionalModelObject omo = componentObjectData.getModelObjectTarget<ModelObject>(OS_ComponentDataExtensibleFields::NameofObject);
95
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1238 times.
1238 if (!omo) {
96 ✗ LOG_AND_THROW("Cannot retrieve ModelObject at objectIndex = " << objectIndex);
97 }
98
99
2/2
✓ Branch 1 taken 1238 times.
✓ Branch 4 taken 1238 times.
2476 return *omo;
100 1238 }
101
102 135 UUID ComponentData_Impl::createVersionUUID() {
103
3/3
✓ Branch 1 taken 135 times.
✓ Branch 4 taken 135 times.
✓ Branch 7 taken 135 times.
135 bool ok = setString(OS_ComponentDataFields::VersionUUID, toString(createUUID()));
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
135 OS_ASSERT(ok);
105 135 ok = setInt(OS_ComponentDataFields::VersionTimestamp, (int)time(nullptr));
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
135 OS_ASSERT(ok);
107 135 return versionUUID();
108 }
109
110 313 bool ComponentData_Impl::registerObject(const ModelObject& object) {
111
1/1
✓ Branch 2 taken 313 times.
313 IdfExtensibleGroup eg = pushExtensibleGroup(StringVector());
112
1/1
✓ Branch 1 taken 313 times.
313 bool result = !eg.empty();
113
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if (result) {
114
1/1
✓ Branch 1 taken 313 times.
313 auto meg = eg.cast<ModelExtensibleGroup>();
115
4/6
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 313 times.
✓ Branch 6 taken 313 times.
✓ Branch 8 taken 313 times.
✗ Branch 9 not taken.
313 result = result && meg.setPointer(OS_ComponentDataExtensibleFields::NameofObject, object.handle());
116 313 }
117 313 return result;
118 313 }
119
120 3020 unsigned ComponentData_Impl::numComponentObjects() const {
121 3020 return numExtensibleGroups();
122 }
123
124 ✗ boost::optional<ModelObject> ComponentData_Impl::primaryComponentObjectAsModelObject() const {
125 ✗ OptionalModelObject result = primaryComponentObject();
126 ✗ return result;
127 }
128
129 } // namespace detail
130
131 9711 IddObjectType ComponentData::iddObjectType() {
132
1/1
✓ Branch 1 taken 9711 times.
9711 IddObjectType result(IddObjectType::OS_ComponentData);
133 9711 return result;
134 }
135
136 11 UUID ComponentData::uuid() const {
137
1/1
✓ Branch 3 taken 11 times.
11 return getImpl<detail::ComponentData_Impl>()->uuid();
138 }
139
140 28 UUID ComponentData::versionUUID() const {
141
1/1
✓ Branch 3 taken 28 times.
28 return getImpl<detail::ComponentData_Impl>()->versionUUID();
142 }
143
144 ✗ boost::optional<int> ComponentData::creationTimestamp() const {
145 ✗ return getImpl<detail::ComponentData_Impl>()->creationTimestamp();
146 }
147
148 ✗ boost::optional<int> ComponentData::versionTimestamp() const {
149 ✗ return getImpl<detail::ComponentData_Impl>()->versionTimestamp();
150 }
151
152 29 ModelObject ComponentData::primaryComponentObject() const {
153
1/1
✓ Branch 3 taken 29 times.
29 return getImpl<detail::ComponentData_Impl>()->primaryComponentObject();
154 }
155
156 8 std::vector<ModelObject> ComponentData::componentObjects() const {
157
1/1
✓ Branch 3 taken 8 times.
8 return getImpl<detail::ComponentData_Impl>()->componentObjects();
158 }
159
160 1165 ModelObject ComponentData::getComponentObject(unsigned objectIndex) const {
161
1/1
✓ Branch 3 taken 1165 times.
1165 return getImpl<detail::ComponentData_Impl>()->getComponentObject(objectIndex);
162 }
163
164 135 UUID ComponentData::createVersionUUID() {
165
1/1
✓ Branch 3 taken 135 times.
135 return getImpl<detail::ComponentData_Impl>()->createVersionUUID();
166 }
167
168 1774 unsigned ComponentData::numComponentObjects() const {
169
1/1
✓ Branch 3 taken 1774 times.
1774 return getImpl<detail::ComponentData_Impl>()->numComponentObjects();
170 }
171
172 /// @cond
173 ✗ ComponentData::ComponentData(const Model& model) : ResourceObject(iddObjectType(), model) {
174 ✗ OS_ASSERT(getImpl<detail::ComponentData_Impl>());
175 ✗ setString(OS_ComponentDataFields::UUID, toString(createUUID()));
176 ✗ setInt(OS_ComponentDataFields::CreationTimestamp, (int)time(nullptr));
177 ✗ createVersionUUID();
178 ✗ }
179
180
1/1
✓ Branch 3 taken 1072 times.
1072 ComponentData::ComponentData(std::shared_ptr<detail::ComponentData_Impl> impl) : ResourceObject(std::move(impl)) {}
181 /// @endcond
182
183 } // namespace model
184 } // namespace openstudio
185