GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 89.1% 164 / 0 / 184
Functions: 86.2% 50 / 0 / 58
Branches: 66.4% 95 / 0 / 143

src/model/TableIndependentVariable.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 "TableIndependentVariable.hpp"
7 #include "TableIndependentVariable_Impl.hpp"
8
9 #include "TableLookup.hpp"
10 #include "TableLookup_Impl.hpp"
11 #include "Model.hpp"
12 #include "Model_Impl.hpp"
13
14 #include "../utilities/idf/IdfExtensibleGroup.hpp"
15 #include <utilities/idd/IddFactory.hxx>
16
17 #include <utilities/idd/OS_Table_IndependentVariable_FieldEnums.hxx>
18 #include <utilities/idd/IddEnums.hxx>
19
20 #include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
21 #include "../utilities/core/Assert.hpp"
22
23 namespace openstudio {
24 namespace model {
25
26 namespace detail {
27
28 74 TableIndependentVariable_Impl::TableIndependentVariable_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
29 74 : ResourceObject_Impl(idfObject, model, keepHandle) {
30
4/6
✓ Branch 1 taken 74 times.
✓ Branch 4 taken 74 times.
✓ Branch 7 taken 74 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 74 times.
✗ Branch 13 not taken.
74 OS_ASSERT(idfObject.iddObject().type() == TableIndependentVariable::iddObjectType());
31 74 }
32
33 13 TableIndependentVariable_Impl::TableIndependentVariable_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model,
34 13 bool keepHandle)
35 13 : ResourceObject_Impl(other, model, keepHandle) {
36
4/6
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
✓ Branch 7 taken 13 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 13 times.
✗ Branch 13 not taken.
13 OS_ASSERT(other.iddObject().type() == TableIndependentVariable::iddObjectType());
37 13 }
38
39 25 TableIndependentVariable_Impl::TableIndependentVariable_Impl(const TableIndependentVariable_Impl& other, Model_Impl* model, bool keepHandle)
40 25 : ResourceObject_Impl(other, model, keepHandle) {}
41
42 ✗ const std::vector<std::string>& TableIndependentVariable_Impl::outputVariableNames() const {
43 ✗ static const std::vector<std::string> result;
44 ✗ return result;
45 }
46
47 ✗ IddObjectType TableIndependentVariable_Impl::iddObjectType() const {
48 ✗ return TableIndependentVariable::iddObjectType();
49 }
50
51 14 std::string TableIndependentVariable_Impl::interpolationMethod() const {
52
1/1
✓ Branch 1 taken 14 times.
14 boost::optional<std::string> value = getString(OS_Table_IndependentVariableFields::InterpolationMethod, true);
53
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
14 OS_ASSERT(value);
54
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
28 return value.get();
55 14 }
56
57 14 std::string TableIndependentVariable_Impl::extrapolationMethod() const {
58
1/1
✓ Branch 1 taken 14 times.
14 boost::optional<std::string> value = getString(OS_Table_IndependentVariableFields::ExtrapolationMethod, true);
59
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
14 OS_ASSERT(value);
60
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
28 return value.get();
61 14 }
62
63 16 boost::optional<double> TableIndependentVariable_Impl::minimumValue() const {
64 16 return getDouble(OS_Table_IndependentVariableFields::MinimumValue, true);
65 }
66
67 16 boost::optional<double> TableIndependentVariable_Impl::maximumValue() const {
68 16 return getDouble(OS_Table_IndependentVariableFields::MaximumValue, true);
69 }
70
71 15 boost::optional<double> TableIndependentVariable_Impl::normalizationReferenceValue() const {
72 15 return getDouble(OS_Table_IndependentVariableFields::NormalizationReferenceValue, true);
73 }
74
75 14 std::string TableIndependentVariable_Impl::unitType() const {
76
1/1
✓ Branch 1 taken 14 times.
14 boost::optional<std::string> value = getString(OS_Table_IndependentVariableFields::UnitType, true);
77
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
14 OS_ASSERT(value);
78
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
28 return value.get();
79 14 }
80
81 3 std::vector<TableLookup> TableIndependentVariable_Impl::tableLookups() const {
82 3 std::vector<TableLookup> result;
83
4/4
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 3 times.
7 for (const TableLookup& tableLookup : this->model().getConcreteModelObjects<TableLookup>()) {
84
3/3
✓ Branch 1 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 4 times.
8 for (const TableIndependentVariable& independentVariable : tableLookup.independentVariables()) {
85
4/5
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
4 if (independentVariable.handle() == this->handle()) {
86
1/1
✓ Branch 1 taken 4 times.
4 result.push_back(tableLookup);
87 }
88 4 }
89 3 }
90 3 return result;
91 ✗ }
92
93 115 bool TableIndependentVariable_Impl::setInterpolationMethod(const std::string& interpolationMethod) {
94 115 bool result = setString(OS_Table_IndependentVariableFields::InterpolationMethod, interpolationMethod);
95 115 return result;
96 }
97
98 115 bool TableIndependentVariable_Impl::setExtrapolationMethod(const std::string& extrapolationMethod) {
99 115 bool result = setString(OS_Table_IndependentVariableFields::ExtrapolationMethod, extrapolationMethod);
100 115 return result;
101 }
102
103 53 bool TableIndependentVariable_Impl::setMinimumValue(double minimumValue) {
104 53 bool result = setDouble(OS_Table_IndependentVariableFields::MinimumValue, minimumValue);
105 53 return result;
106 }
107
108 1 void TableIndependentVariable_Impl::resetMinimumValue() {
109
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Table_IndependentVariableFields::MinimumValue, "");
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
111 1 }
112
113 53 bool TableIndependentVariable_Impl::setMaximumValue(double maximumValue) {
114 53 bool result = setDouble(OS_Table_IndependentVariableFields::MaximumValue, maximumValue);
115 53 return result;
116 }
117
118 1 void TableIndependentVariable_Impl::resetMaximumValue() {
119
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Table_IndependentVariableFields::MaximumValue, "");
120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
121 1 }
122
123 1 bool TableIndependentVariable_Impl::setNormalizationReferenceValue(double normalizationReferenceValue) {
124 1 bool result = setDouble(OS_Table_IndependentVariableFields::NormalizationReferenceValue, normalizationReferenceValue);
125 1 return result;
126 }
127
128 1 void TableIndependentVariable_Impl::resetNormalizationReferenceValue() {
129
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 bool result = setString(OS_Table_IndependentVariableFields::NormalizationReferenceValue, "");
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 OS_ASSERT(result);
131 1 }
132
133 109 bool TableIndependentVariable_Impl::setUnitType(const std::string& unitType) {
134 109 bool result = setString(OS_Table_IndependentVariableFields::UnitType, unitType);
135 109 return result;
136 }
137
138 267 bool TableIndependentVariable_Impl::addValue(double value) {
139
2/2
✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
267 IdfExtensibleGroup eg = getObject<ModelObject>().pushExtensibleGroup();
140
1/1
✓ Branch 1 taken 267 times.
267 bool result = eg.setDouble(OS_Table_IndependentVariableExtensibleFields::Value, value);
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 267 times.
267 if (!result) {
142 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
143 }
144
145 267 return result;
146 267 }
147
148 1 bool TableIndependentVariable_Impl::removeValue(unsigned groupIndex) {
149 1 bool result = false;
150
151 1 unsigned num = numberofValues();
152
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (groupIndex < num) {
153
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().eraseExtensibleGroup(groupIndex);
154 1 result = true;
155 }
156 1 return result;
157 }
158
159 1 void TableIndependentVariable_Impl::removeAllValues() {
160
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().clearExtensibleGroups();
161 1 }
162
163 67 std::vector<double> TableIndependentVariable_Impl::values() const {
164 67 std::vector<double> result;
165
3/3
✓ Branch 1 taken 67 times.
✓ Branch 8 taken 184 times.
✓ Branch 9 taken 67 times.
251 for (const auto& eg : extensibleGroups()) {
166
1/1
✓ Branch 1 taken 184 times.
184 auto _d = eg.getDouble(OS_Table_IndependentVariableExtensibleFields::Value);
167
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 184 times.
✗ Branch 4 not taken.
184 OS_ASSERT(_d);
168
2/2
✓ Branch 1 taken 184 times.
✓ Branch 4 taken 184 times.
184 result.push_back(_d.get());
169 67 }
170 67 return result;
171 ✗ }
172
173 5 unsigned TableIndependentVariable_Impl::numberofValues() const {
174 5 return numExtensibleGroups();
175 }
176
177 41 bool TableIndependentVariable_Impl::setValues(const std::vector<double>& values) {
178 41 bool result = true;
179
180
1/1
✓ Branch 1 taken 41 times.
41 this->clearExtensibleGroups();
181
2/2
✓ Branch 4 taken 224 times.
✓ Branch 5 taken 41 times.
265 for (const auto& val : values) {
182
1/1
✓ Branch 1 taken 224 times.
224 result &= addValue(val);
183 }
184 41 return result;
185 }
186
187 } // namespace detail
188
189 61 TableIndependentVariable::TableIndependentVariable(const Model& model) : ResourceObject(TableIndependentVariable::iddObjectType(), model) {
190
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 61 times.
✗ Branch 5 not taken.
61 OS_ASSERT(getImpl<detail::TableIndependentVariable_Impl>());
191
192 61 bool ok = true;
193
2/2
✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
61 ok = setInterpolationMethod("Linear");
194
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
✗ Branch 3 not taken.
61 OS_ASSERT(ok);
195
2/2
✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
61 ok = setExtrapolationMethod("Constant");
196
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
✗ Branch 3 not taken.
61 OS_ASSERT(ok);
197
2/2
✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
61 ok = setUnitType("Dimensionless");
198
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
✗ Branch 3 not taken.
61 OS_ASSERT(ok);
199 61 }
200
201 7759 IddObjectType TableIndependentVariable::iddObjectType() {
202
1/1
✓ Branch 1 taken 7759 times.
7759 return {IddObjectType::OS_Table_IndependentVariable};
203 }
204
205 ✗ std::vector<std::string> TableIndependentVariable::interpolationMethodValues() {
206 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Table_IndependentVariableFields::InterpolationMethod);
207 }
208
209 ✗ std::vector<std::string> TableIndependentVariable::validInterpolationMethodValues() {
210 ✗ return interpolationMethodValues();
211 }
212
213 ✗ std::vector<std::string> TableIndependentVariable::extrapolationMethodValues() {
214 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Table_IndependentVariableFields::ExtrapolationMethod);
215 }
216
217 ✗ std::vector<std::string> TableIndependentVariable::validExtrapolationMethodValues() {
218 ✗ return extrapolationMethodValues();
219 }
220
221 ✗ std::vector<std::string> TableIndependentVariable::unitTypeValues() {
222 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Table_IndependentVariableFields::UnitType);
223 }
224
225 ✗ std::vector<std::string> TableIndependentVariable::validUnitTypeValues() {
226 ✗ return unitTypeValues();
227 }
228
229 14 std::string TableIndependentVariable::interpolationMethod() const {
230
1/1
✓ Branch 3 taken 14 times.
14 return getImpl<detail::TableIndependentVariable_Impl>()->interpolationMethod();
231 }
232
233 14 std::string TableIndependentVariable::extrapolationMethod() const {
234
1/1
✓ Branch 3 taken 14 times.
14 return getImpl<detail::TableIndependentVariable_Impl>()->extrapolationMethod();
235 }
236
237 16 boost::optional<double> TableIndependentVariable::minimumValue() const {
238
1/1
✓ Branch 3 taken 16 times.
16 return getImpl<detail::TableIndependentVariable_Impl>()->minimumValue();
239 }
240
241 16 boost::optional<double> TableIndependentVariable::maximumValue() const {
242
1/1
✓ Branch 3 taken 16 times.
16 return getImpl<detail::TableIndependentVariable_Impl>()->maximumValue();
243 }
244
245 15 boost::optional<double> TableIndependentVariable::normalizationReferenceValue() const {
246
1/1
✓ Branch 3 taken 15 times.
15 return getImpl<detail::TableIndependentVariable_Impl>()->normalizationReferenceValue();
247 }
248
249 14 std::string TableIndependentVariable::unitType() const {
250
1/1
✓ Branch 3 taken 14 times.
14 return getImpl<detail::TableIndependentVariable_Impl>()->unitType();
251 }
252
253 3 std::vector<TableLookup> TableIndependentVariable::tableLookups() const {
254
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::TableIndependentVariable_Impl>()->tableLookups();
255 }
256
257 115 bool TableIndependentVariable::setInterpolationMethod(const std::string& interpolationMethod) {
258
1/1
✓ Branch 3 taken 115 times.
115 return getImpl<detail::TableIndependentVariable_Impl>()->setInterpolationMethod(interpolationMethod);
259 }
260
261 115 bool TableIndependentVariable::setExtrapolationMethod(const std::string& extrapolationMethod) {
262
1/1
✓ Branch 3 taken 115 times.
115 return getImpl<detail::TableIndependentVariable_Impl>()->setExtrapolationMethod(extrapolationMethod);
263 }
264
265 53 bool TableIndependentVariable::setMinimumValue(double minimumValue) {
266
1/1
✓ Branch 3 taken 53 times.
53 return getImpl<detail::TableIndependentVariable_Impl>()->setMinimumValue(minimumValue);
267 }
268
269 1 void TableIndependentVariable::resetMinimumValue() {
270
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::TableIndependentVariable_Impl>()->resetMinimumValue();
271 1 }
272
273 53 bool TableIndependentVariable::setMaximumValue(double maximumValue) {
274
1/1
✓ Branch 3 taken 53 times.
53 return getImpl<detail::TableIndependentVariable_Impl>()->setMaximumValue(maximumValue);
275 }
276
277 1 void TableIndependentVariable::resetMaximumValue() {
278
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::TableIndependentVariable_Impl>()->resetMaximumValue();
279 1 }
280
281 1 bool TableIndependentVariable::setNormalizationReferenceValue(double normalizationReferenceValue) {
282
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::TableIndependentVariable_Impl>()->setNormalizationReferenceValue(normalizationReferenceValue);
283 }
284
285 1 void TableIndependentVariable::resetNormalizationReferenceValue() {
286
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::TableIndependentVariable_Impl>()->resetNormalizationReferenceValue();
287 1 }
288
289 109 bool TableIndependentVariable::setUnitType(const std::string& unitType) {
290
1/1
✓ Branch 3 taken 109 times.
109 return getImpl<detail::TableIndependentVariable_Impl>()->setUnitType(unitType);
291 }
292
293 43 bool TableIndependentVariable::addValue(double value) {
294
1/1
✓ Branch 3 taken 43 times.
43 return getImpl<detail::TableIndependentVariable_Impl>()->addValue(value);
295 }
296
297 1 bool TableIndependentVariable::removeValue(unsigned groupIndex) {
298
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::TableIndependentVariable_Impl>()->removeValue(groupIndex);
299 }
300
301 1 void TableIndependentVariable::removeAllValues() {
302
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::TableIndependentVariable_Impl>()->removeAllValues();
303 1 }
304
305 67 std::vector<double> TableIndependentVariable::values() const {
306
1/1
✓ Branch 3 taken 67 times.
67 return getImpl<detail::TableIndependentVariable_Impl>()->values();
307 }
308
309 4 unsigned TableIndependentVariable::numberofValues() const {
310
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::TableIndependentVariable_Impl>()->numberofValues();
311 }
312
313 41 bool TableIndependentVariable::setValues(const std::vector<double>& values) {
314
1/1
✓ Branch 3 taken 41 times.
41 return getImpl<detail::TableIndependentVariable_Impl>()->setValues(values);
315 }
316
317 /// @cond
318
1/1
✓ Branch 3 taken 133 times.
133 TableIndependentVariable::TableIndependentVariable(std::shared_ptr<detail::TableIndependentVariable_Impl> impl) : ResourceObject(std::move(impl)) {}
319 /// @endcond
320
321 } // namespace model
322 } // namespace openstudio
323