GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 61.4% 86 / 0 / 140
Functions: 65.8% 25 / 0 / 38
Branches: 48.5% 63 / 0 / 130

src/model/MeterCustomDecrement.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 "MeterCustomDecrement.hpp"
7 #include "MeterCustomDecrement_Impl.hpp"
8
9 #include "Model.hpp"
10 #include "Model_Impl.hpp"
11
12 #include "ModelObject.hpp"
13 #include "ModelObject_Impl.hpp"
14
15 #include <utilities/idd/IddFactory.hxx>
16 #include <utilities/idd/IddEnums.hxx>
17 #include <utilities/idd/OS_Meter_CustomDecrement_FieldEnums.hxx>
18
19 #include "../utilities/data/DataEnums.hpp"
20
21 // Needed for extensible groups
22 #include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
23
24 #include "../utilities/core/Assert.hpp"
25
26 namespace openstudio {
27 namespace model {
28
29 namespace detail {
30
31 6 MeterCustomDecrement_Impl::MeterCustomDecrement_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
32 6 : ModelObject_Impl(idfObject, model, keepHandle) {
33
4/6
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 13 not taken.
6 OS_ASSERT(idfObject.iddObject().type() == MeterCustomDecrement::iddObjectType());
34 6 }
35
36 3 MeterCustomDecrement_Impl::MeterCustomDecrement_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
37 3 : ModelObject_Impl(other, model, keepHandle) {
38
4/6
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 13 not taken.
3 OS_ASSERT(other.iddObject().type() == MeterCustomDecrement::iddObjectType());
39 3 }
40
41 ✗ MeterCustomDecrement_Impl::MeterCustomDecrement_Impl(const MeterCustomDecrement_Impl& other, Model_Impl* model, bool keepHandle)
42 ✗ : ModelObject_Impl(other, model, keepHandle) {}
43
44 // This logically doesn't produce any output variables
45 ✗ const std::vector<std::string>& MeterCustomDecrement_Impl::outputVariableNames() const {
46 ✗ static const std::vector<std::string> result;
47 //LOG(Info, "Meter:Custom does not produce any output variables.");
48 ✗ return result;
49 }
50
51 ✗ IddObjectType MeterCustomDecrement_Impl::iddObjectType() const {
52 ✗ return MeterCustomDecrement::iddObjectType();
53 }
54
55 // fuel Type
56 ✗ boost::optional<std::string> MeterCustomDecrement_Impl::fuelType() const {
57 ✗ return getString(OS_Meter_CustomDecrementFields::FuelType, true);
58 }
59
60 3 bool MeterCustomDecrement_Impl::setFuelType(const FuelType& fuelType) {
61
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 return setString(OS_Meter_CustomDecrementFields::FuelType, fuelType.valueDescription());
62 }
63
64 ✗ void MeterCustomDecrement_Impl::resetFuelType() {
65 ✗ bool result = setString(OS_Meter_CustomDecrementFields::FuelType, "");
66 ✗ OS_ASSERT(result);
67 ✗ }
68
69 // Source Meter Name
70 2 std::string MeterCustomDecrement_Impl::sourceMeterName() const {
71
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 return getString(OS_Meter_CustomDecrementFields::SourceMeterName, true).get();
72 }
73
74 4 bool MeterCustomDecrement_Impl::setSourceMeterName(const std::string& sourceMeterName) {
75 4 return setString(OS_Meter_CustomDecrementFields::SourceMeterName, sourceMeterName);
76 }
77
78 // Add a new (Key, Var) group
79 103 bool MeterCustomDecrement_Impl::addKeyVarGroup(const std::string& keyName, const std::string& outputVariableorMeterName) {
80
3/3
✓ Branch 1 taken 103 times.
✓ Branch 4 taken 103 times.
✓ Branch 7 taken 103 times.
103 auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
81
82
1/1
✓ Branch 1 taken 103 times.
103 bool temp = eg.setString(OS_Meter_CustomDecrementExtensibleFields::KeyName, keyName);
83
1/1
✓ Branch 1 taken 103 times.
103 bool ok = eg.setString(OS_Meter_CustomDecrementExtensibleFields::OutputVariableorMeterName, outputVariableorMeterName);
84
85
1/2
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
103 if (temp) {
86 103 temp = ok;
87 }
88
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (!temp) {
90 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
91 ✗ return temp;
92 }
93 103 return temp;
94 103 }
95
96 // Remove the (Key, Var) group at given index
97 1 bool MeterCustomDecrement_Impl::removeKeyVarGroup(unsigned groupIndex) {
98 1 bool ok = false;
99 1 unsigned numberofDataPairs = numExtensibleGroups();
100 // Only delete if the index is smaller than the number of groups
101
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (groupIndex < numberofDataPairs) {
102
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().eraseExtensibleGroup(groupIndex);
103 1 ok = true;
104 }
105
106 1 return ok;
107 }
108
109 // Remove all the (Key, Var) groups
110 2 void MeterCustomDecrement_Impl::removeAllKeyVarGroups() {
111
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getObject<ModelObject>().clearExtensibleGroups();
112 2 }
113
114 // Return a vector of (Key, Var) pairs
115 6 std::vector<std::pair<std::string, std::string>> MeterCustomDecrement_Impl::keyVarGroups() {
116 6 std::vector<std::pair<std::string, std::string>> result;
117
118
1/1
✓ Branch 1 taken 6 times.
6 std::vector<IdfExtensibleGroup> groups = extensibleGroups();
119
120
2/2
✓ Branch 5 taken 104 times.
✓ Branch 6 taken 6 times.
110 for (const auto& group : groups) {
121
2/2
✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
104 boost::optional<std::string> keyName = group.cast<WorkspaceExtensibleGroup>().getString(OS_Meter_CustomDecrementExtensibleFields::KeyName);
122 boost::optional<std::string> outputVariableorMeterName =
123
2/2
✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
104 group.cast<WorkspaceExtensibleGroup>().getString(OS_Meter_CustomDecrementExtensibleFields::OutputVariableorMeterName);
124
125
3/6
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 104 times.
✗ Branch 5 not taken.
208 if (keyName && outputVariableorMeterName) {
126
4/4
✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
✓ Branch 7 taken 104 times.
✓ Branch 10 taken 104 times.
104 result.push_back(std::make_pair(keyName.get(), outputVariableorMeterName.get()));
127 }
128 104 }
129
130 12 return result;
131 6 }
132
133 // Return the number of (KeyName, OutputVariableorMeterName) groups
134 5 unsigned MeterCustomDecrement_Impl::numKeyVarGroups() const {
135 5 return numExtensibleGroups();
136 }
137
138 // Lower level functions
139 /** Get the Key Name at index. Indexing starts at 0. */
140 ✗ boost::optional<std::string> MeterCustomDecrement_Impl::keyName(unsigned index) const {
141 ✗ IdfExtensibleGroup eg = getExtensibleGroup(index);
142 ✗ if (!eg.empty()) {
143 ✗ return eg.getString(OS_Meter_CustomDecrementExtensibleFields::KeyName, true);
144 }
145 ✗ return boost::none;
146 ✗ }
147
148 /** Set the Key Name at index. Indexing starts at 0. */
149 1 bool MeterCustomDecrement_Impl::setKeyName(unsigned index, const std::string& str) {
150
1/1
✓ Branch 1 taken 1 time.
1 IdfExtensibleGroup eg = getExtensibleGroup(index);
151
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!eg.empty()) {
152
1/1
✓ Branch 1 taken 1 time.
1 return eg.setString(OS_Meter_CustomDecrementExtensibleFields::KeyName, str);
153 } else {
154 ✗ StringVector values(2u);
155 ✗ values[OS_Meter_CustomDecrementExtensibleFields::KeyName] = str;
156 ✗ return !insertExtensibleGroup(index, values).empty();
157 ✗ }
158 OS_ASSERT(false);
159 return false;
160 1 }
161
162 /** Get the Output Variable of Meter Name at index. Indexing starts at 0. */
163 ✗ boost::optional<std::string> MeterCustomDecrement_Impl::outputVariableorMeterName(unsigned index) const {
164 ✗ IdfExtensibleGroup eg = getExtensibleGroup(index);
165 ✗ if (!eg.empty()) {
166 ✗ return eg.getString(OS_Meter_CustomDecrementExtensibleFields::OutputVariableorMeterName, true);
167 }
168 ✗ return boost::none;
169 ✗ }
170
171 /** Set the Output Variable of Meter Name at index. Indexing starts at 0. */
172 1 bool MeterCustomDecrement_Impl::setOutputVariableorMeterName(unsigned index, const std::string& str) {
173
1/1
✓ Branch 1 taken 1 time.
1 IdfExtensibleGroup eg = getExtensibleGroup(index);
174
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!eg.empty()) {
175
1/1
✓ Branch 1 taken 1 time.
1 return eg.setString(OS_Meter_CustomDecrementExtensibleFields::OutputVariableorMeterName, str);
176 } else {
177 ✗ StringVector values(2u);
178 ✗ values[OS_Meter_CustomDecrementExtensibleFields::OutputVariableorMeterName] = str;
179 ✗ return !insertExtensibleGroup(index, values).empty();
180 ✗ }
181 OS_ASSERT(false);
182 return false;
183 1 }
184
185 } // namespace detail
186
187 3 MeterCustomDecrement::MeterCustomDecrement(const Model& model, const std::string& sourceMeterName)
188 3 : ModelObject(MeterCustomDecrement::iddObjectType(), model) {
189
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 5 not taken.
3 OS_ASSERT(getImpl<detail::MeterCustomDecrement_Impl>());
190
191
1/1
✓ Branch 1 taken 3 times.
3 setSourceMeterName(sourceMeterName);
192
193 // Default the fuelType to Electricity (maybe "Generic"?)
194
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 setFuelType(FuelType::Electricity);
195 3 }
196
197 7742 IddObjectType MeterCustomDecrement::iddObjectType() {
198
1/1
✓ Branch 1 taken 7742 times.
7742 return {IddObjectType::OS_Meter_CustomDecrement};
199 }
200
201 ✗ std::vector<std::string> MeterCustomDecrement::fuelTypeValues() {
202 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Meter_CustomDecrementFields::FuelType);
203 }
204
205 ✗ boost::optional<std::string> MeterCustomDecrement::fuelType() const {
206 ✗ return getImpl<detail::MeterCustomDecrement_Impl>()->fuelType();
207 }
208
209 3 bool MeterCustomDecrement::setFuelType(const FuelType& fuelType) {
210
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::MeterCustomDecrement_Impl>()->setFuelType(fuelType);
211 }
212
213 ✗ bool MeterCustomDecrement::setFuelType(const std::string& fuelType) {
214 // Special case for custom meters, the only ones that have "Generic" as a possibility
215 ✗ if (openstudio::istringEqual("Generic", fuelType)) {
216 ✗ return this->setString(OS_Meter_CustomDecrementFields::FuelType, "Generic");
217 }
218 try {
219 ✗ return setFuelType(FuelType{fuelType});
220 ✗ } catch (std::runtime_error& e) {
221 ✗ LOG(Debug, e.what());
222 ✗ return false;
223 ✗ }
224 }
225
226 ✗ void MeterCustomDecrement::resetFuelType() {
227 ✗ getImpl<detail::MeterCustomDecrement_Impl>()->resetFuelType();
228 ✗ }
229
230 2 std::string MeterCustomDecrement::sourceMeterName() const {
231
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::MeterCustomDecrement_Impl>()->sourceMeterName();
232 }
233
234 4 bool MeterCustomDecrement::setSourceMeterName(const std::string& sourceMeterName) {
235
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::MeterCustomDecrement_Impl>()->setSourceMeterName(sourceMeterName);
236 }
237
238 // Add a new (Key, Var) group
239 103 bool MeterCustomDecrement::addKeyVarGroup(const std::string& keyName, const std::string& outputVariableorMeterName) {
240
1/1
✓ Branch 3 taken 103 times.
103 return getImpl<detail::MeterCustomDecrement_Impl>()->addKeyVarGroup(keyName, outputVariableorMeterName);
241 }
242
243 // Remove the (Key, Var) group at given index
244 1 bool MeterCustomDecrement::removeKeyVarGroup(unsigned groupIndex) {
245
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeterCustomDecrement_Impl>()->removeKeyVarGroup(groupIndex);
246 }
247
248 // Remove all the (Key, Var) groups
249 2 void MeterCustomDecrement::removeAllKeyVarGroups() {
250
1/1
✓ Branch 3 taken 2 times.
2 getImpl<detail::MeterCustomDecrement_Impl>()->removeAllKeyVarGroups();
251 2 }
252
253 // // Return a vector of (Key, Var) pairs
254 6 std::vector<std::pair<std::string, std::string>> MeterCustomDecrement::keyVarGroups() {
255
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::MeterCustomDecrement_Impl>()->keyVarGroups();
256 }
257
258 // Return the number of (KeyName, OutputVariableorMeterName) groups
259 5 unsigned MeterCustomDecrement::numKeyVarGroups() const {
260
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::MeterCustomDecrement_Impl>()->numKeyVarGroups();
261 }
262
263 // Lower level functions
264 /** Get the Key Name at index. Indexing starts at 0. */
265 ✗ boost::optional<std::string> MeterCustomDecrement::keyName(unsigned index) const {
266 ✗ return getImpl<detail::MeterCustomDecrement_Impl>()->keyName(index);
267 }
268 /** Set the Key Name at index. Indexing starts at 0. */
269 1 bool MeterCustomDecrement::setKeyName(unsigned index, const std::string& str) {
270
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeterCustomDecrement_Impl>()->setKeyName(index, str);
271 }
272
273 /** Get the Output Variable of Meter Name at index. Indexing starts at 0. */
274 ✗ boost::optional<std::string> MeterCustomDecrement::outputVariableorMeterName(unsigned index) const {
275 ✗ return getImpl<detail::MeterCustomDecrement_Impl>()->outputVariableorMeterName(index);
276 }
277 /** Set the Output Variable of Meter Name at index. Indexing starts at 0. */
278 1 bool MeterCustomDecrement::setOutputVariableorMeterName(unsigned index, const std::string& str) {
279
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeterCustomDecrement_Impl>()->setOutputVariableorMeterName(index, str);
280 }
281
282 /// @cond
283
1/1
✓ Branch 3 taken 1 time.
1 MeterCustomDecrement::MeterCustomDecrement(std::shared_ptr<detail::MeterCustomDecrement_Impl> impl) : ModelObject(std::move(impl)) {}
284 /// @endcond
285
286 } // namespace model
287 } // namespace openstudio
288