GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 58.5% 76 / 0 / 130
Functions: 61.8% 21 / 0 / 34
Branches: 46.0% 57 / 0 / 124

src/model/MeterCustom.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 "MeterCustom.hpp"
7 #include "MeterCustom_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_Custom_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 MeterCustom_Impl::MeterCustom_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() == MeterCustom::iddObjectType());
34 6 }
35
36 3 MeterCustom_Impl::MeterCustom_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() == MeterCustom::iddObjectType());
39 3 }
40
41 ✗ MeterCustom_Impl::MeterCustom_Impl(const MeterCustom_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>& MeterCustom_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 MeterCustom_Impl::iddObjectType() const {
52 ✗ return MeterCustom::iddObjectType();
53 }
54
55 // fuel Type
56 ✗ boost::optional<std::string> MeterCustom_Impl::fuelType() const {
57 ✗ return getString(OS_Meter_CustomFields::FuelType, true);
58 }
59
60 3 bool MeterCustom_Impl::setFuelType(const FuelType& fuelType) {
61
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 return setString(OS_Meter_CustomFields::FuelType, fuelType.valueDescription());
62 }
63
64 ✗ void MeterCustom_Impl::resetFuelType() {
65 ✗ bool result = setString(OS_Meter_CustomFields::FuelType, "");
66 ✗ OS_ASSERT(result);
67 ✗ }
68
69 // Add a new (Key, Var) group
70 103 bool MeterCustom_Impl::addKeyVarGroup(const std::string& keyName, const std::string& outputVariableorMeterName) {
71
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>();
72
73
1/1
✓ Branch 1 taken 103 times.
103 bool temp = eg.setString(OS_Meter_CustomExtensibleFields::KeyName, keyName);
74
1/1
✓ Branch 1 taken 103 times.
103 bool ok = eg.setString(OS_Meter_CustomExtensibleFields::OutputVariableorMeterName, outputVariableorMeterName);
75
76
1/2
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
103 if (temp) {
77 103 temp = ok;
78 }
79
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (!temp) {
81 ✗ getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
82 ✗ return temp;
83 }
84 103 return temp;
85 103 }
86
87 // Remove the (Key, Var) group at given index
88 1 bool MeterCustom_Impl::removeKeyVarGroup(unsigned groupIndex) {
89 1 bool ok = false;
90 1 unsigned numberofDataPairs = numExtensibleGroups();
91 // Only delete if the index is smaller than the number of groups
92
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 if (groupIndex < numberofDataPairs) {
93
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 getObject<ModelObject>().eraseExtensibleGroup(groupIndex);
94 1 ok = true;
95 }
96
97 1 return ok;
98 }
99
100 // Remove all the (Key, Var) groups
101 2 void MeterCustom_Impl::removeAllKeyVarGroups() {
102
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 getObject<ModelObject>().clearExtensibleGroups();
103 2 }
104
105 // Return a vector of (Key, Var) pairs
106 6 std::vector<std::pair<std::string, std::string>> MeterCustom_Impl::keyVarGroups() {
107 6 std::vector<std::pair<std::string, std::string>> result;
108
109
1/1
✓ Branch 1 taken 6 times.
6 std::vector<IdfExtensibleGroup> groups = extensibleGroups();
110
111
2/2
✓ Branch 5 taken 104 times.
✓ Branch 6 taken 6 times.
110 for (const auto& group : groups) {
112
2/2
✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
104 boost::optional<std::string> keyName = group.cast<WorkspaceExtensibleGroup>().getString(OS_Meter_CustomExtensibleFields::KeyName);
113 boost::optional<std::string> outputVariableorMeterName =
114
2/2
✓ Branch 1 taken 104 times.
✓ Branch 4 taken 104 times.
104 group.cast<WorkspaceExtensibleGroup>().getString(OS_Meter_CustomExtensibleFields::OutputVariableorMeterName);
115
116
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) {
117
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()));
118 }
119 104 }
120
121 12 return result;
122 6 }
123
124 // Return the number of (KeyName, OutputVariableorMeterName) groups
125 5 unsigned MeterCustom_Impl::numKeyVarGroups() const {
126 5 return numExtensibleGroups();
127 }
128
129 // Lower level functions
130 /** Get the Key Name at index. Indexing starts at 0. */
131 ✗ boost::optional<std::string> MeterCustom_Impl::keyName(unsigned index) const {
132 ✗ IdfExtensibleGroup eg = getExtensibleGroup(index);
133 ✗ if (!eg.empty()) {
134 ✗ return eg.getString(OS_Meter_CustomExtensibleFields::KeyName, true);
135 }
136 ✗ return boost::none;
137 ✗ }
138
139 /** Set the Key Name at index. Indexing starts at 0. */
140 1 bool MeterCustom_Impl::setKeyName(unsigned index, const std::string& str) {
141
1/1
✓ Branch 1 taken 1 time.
1 IdfExtensibleGroup eg = getExtensibleGroup(index);
142
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!eg.empty()) {
143
1/1
✓ Branch 1 taken 1 time.
1 return eg.setString(OS_Meter_CustomExtensibleFields::KeyName, str);
144 } else {
145 ✗ StringVector values(2u);
146 ✗ values[OS_Meter_CustomExtensibleFields::KeyName] = str;
147 ✗ return !insertExtensibleGroup(index, values).empty();
148 ✗ }
149 OS_ASSERT(false);
150 return false;
151 1 }
152
153 /** Get the Output Variable of Meter Name at index. Indexing starts at 0. */
154 ✗ boost::optional<std::string> MeterCustom_Impl::outputVariableorMeterName(unsigned index) const {
155 ✗ IdfExtensibleGroup eg = getExtensibleGroup(index);
156 ✗ if (!eg.empty()) {
157 ✗ return eg.getString(OS_Meter_CustomExtensibleFields::OutputVariableorMeterName, true);
158 }
159 ✗ return boost::none;
160 ✗ }
161
162 /** Set the Output Variable of Meter Name at index. Indexing starts at 0. */
163 1 bool MeterCustom_Impl::setOutputVariableorMeterName(unsigned index, const std::string& str) {
164
1/1
✓ Branch 1 taken 1 time.
1 IdfExtensibleGroup eg = getExtensibleGroup(index);
165
2/3
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 if (!eg.empty()) {
166
1/1
✓ Branch 1 taken 1 time.
1 return eg.setString(OS_Meter_CustomExtensibleFields::OutputVariableorMeterName, str);
167 } else {
168 ✗ StringVector values(2u);
169 ✗ values[OS_Meter_CustomExtensibleFields::OutputVariableorMeterName] = str;
170 ✗ return !insertExtensibleGroup(index, values).empty();
171 ✗ }
172 OS_ASSERT(false);
173 return false;
174 1 }
175
176 } // namespace detail
177
178 3 MeterCustom::MeterCustom(const Model& model) : ModelObject(MeterCustom::iddObjectType(), model) {
179
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 5 not taken.
3 OS_ASSERT(getImpl<detail::MeterCustom_Impl>());
180
181 // Default the fuelType to Electricity (maybe "Generic"?)
182
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
3 setFuelType(FuelType::Electricity);
183 3 }
184
185 7612 IddObjectType MeterCustom::iddObjectType() {
186
1/1
✓ Branch 1 taken 7612 times.
7612 return {IddObjectType::OS_Meter_Custom};
187 }
188
189 ✗ std::vector<std::string> MeterCustom::fuelTypeValues() {
190 ✗ return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_Meter_CustomFields::FuelType);
191 }
192
193 ✗ boost::optional<std::string> MeterCustom::fuelType() const {
194 ✗ return getImpl<detail::MeterCustom_Impl>()->fuelType();
195 }
196
197 3 bool MeterCustom::setFuelType(const FuelType& fuelType) {
198
1/1
✓ Branch 3 taken 3 times.
3 return getImpl<detail::MeterCustom_Impl>()->setFuelType(fuelType);
199 }
200
201 ✗ bool MeterCustom::setFuelType(const std::string& fuelType) {
202 // Special case for custom meters, the only ones that have "Generic" as a possibility
203 ✗ if (openstudio::istringEqual("Generic", fuelType)) {
204 ✗ return this->setString(OS_Meter_CustomFields::FuelType, "Generic");
205 }
206 try {
207 ✗ return setFuelType(FuelType{fuelType});
208 ✗ } catch (std::runtime_error& e) {
209 ✗ LOG(Debug, e.what());
210 ✗ return false;
211 ✗ }
212 }
213
214 ✗ void MeterCustom::resetFuelType() {
215 ✗ getImpl<detail::MeterCustom_Impl>()->resetFuelType();
216 ✗ }
217
218 // Add a new (Key, Var) group
219 103 bool MeterCustom::addKeyVarGroup(const std::string& keyName, const std::string& outputVariableorMeterName) {
220
1/1
✓ Branch 3 taken 103 times.
103 return getImpl<detail::MeterCustom_Impl>()->addKeyVarGroup(keyName, outputVariableorMeterName);
221 }
222
223 // Remove the (Key, Var) group at given index
224 1 bool MeterCustom::removeKeyVarGroup(unsigned groupIndex) {
225
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeterCustom_Impl>()->removeKeyVarGroup(groupIndex);
226 }
227
228 // Remove all the (Key, Var) groups
229 2 void MeterCustom::removeAllKeyVarGroups() {
230
1/1
✓ Branch 3 taken 2 times.
2 getImpl<detail::MeterCustom_Impl>()->removeAllKeyVarGroups();
231 2 }
232
233 // // Return a vector of (Key, Var) pairs
234 6 std::vector<std::pair<std::string, std::string>> MeterCustom::keyVarGroups() {
235
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::MeterCustom_Impl>()->keyVarGroups();
236 }
237
238 // Return the number of (KeyName, OutputVariableorMeterName) groups
239 5 unsigned MeterCustom::numKeyVarGroups() const {
240
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::MeterCustom_Impl>()->numKeyVarGroups();
241 }
242
243 // Lower level functions
244 /** Get the Key Name at index. Indexing starts at 0. */
245 ✗ boost::optional<std::string> MeterCustom::keyName(unsigned index) const {
246 ✗ return getImpl<detail::MeterCustom_Impl>()->keyName(index);
247 }
248 /** Set the Key Name at index. Indexing starts at 0. */
249 1 bool MeterCustom::setKeyName(unsigned index, const std::string& str) {
250
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeterCustom_Impl>()->setKeyName(index, str);
251 }
252
253 /** Get the Output Variable of Meter Name at index. Indexing starts at 0. */
254 ✗ boost::optional<std::string> MeterCustom::outputVariableorMeterName(unsigned index) const {
255 ✗ return getImpl<detail::MeterCustom_Impl>()->outputVariableorMeterName(index);
256 }
257 /** Set the Output Variable of Meter Name at index. Indexing starts at 0. */
258 1 bool MeterCustom::setOutputVariableorMeterName(unsigned index, const std::string& str) {
259
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeterCustom_Impl>()->setOutputVariableorMeterName(index, str);
260 }
261
262 /// @cond
263
1/1
✓ Branch 3 taken 1 time.
1 MeterCustom::MeterCustom(std::shared_ptr<detail::MeterCustom_Impl> impl) : ModelObject(std::move(impl)) {}
264 /// @endcond
265
266 } // namespace model
267 } // namespace openstudio
268