GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 10.2% 12 / 0 / 118
Functions: 7.1% 1 / 0 / 14
Branches: 13.0% 30 / 0 / 231

src/utilities/bcl/BCLMeasureOutput.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 "BCLMeasureOutput.hpp"
7
8 #include "../core/Assert.hpp"
9
10 #include <pugixml.hpp>
11 #include <json/json.h>
12
13 namespace openstudio {
14
15 141 BCLMeasureOutput::BCLMeasureOutput(const pugi::xml_node& element) {
16 // TODO: escape name
17 // cppcheck-suppress useInitializationList
18
4/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
✓ Branch 10 taken 141 times.
141 m_name = element.child("name").text().as_string();
19
20
4/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
✓ Branch 10 taken 141 times.
141 m_displayName = element.child("display_name").text().as_string();
21
22
3/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 6 taken 141 times.
✗ Branch 7 not taken.
141 if (auto child_ = element.child("short_name")) {
23
3/3
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
141 m_shortName = child_.text().as_string();
24 }
25
26
3/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 141 times.
141 if (auto child_ = element.child("description")) {
27 ✗ m_description = child_.text().as_string();
28 }
29
30
4/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
✓ Branch 10 taken 141 times.
141 m_type = element.child("type").text().as_string();
31
32
3/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 141 times.
141 if (auto child_ = element.child("units")) {
33 ✗ m_units = child_.text().as_string();
34 }
35
36
4/4
✓ Branch 1 taken 141 times.
✓ Branch 4 taken 141 times.
✓ Branch 7 taken 141 times.
✓ Branch 10 taken 141 times.
141 const std::string test = element.child("model_dependent").text().as_string();
37 141 m_modelDependent = false;
38
2/3
✓ Branch 1 taken 141 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 141 times.
141 if (test == "true") {
39 ✗ m_modelDependent = true;
40 }
41 141 }
42
43 ✗ BCLMeasureOutput::BCLMeasureOutput(const std::string& name, const std::string& displayName, const boost::optional<std::string>& shortName,
44 const boost::optional<std::string>& description, const std::string& type,
45 ✗ const boost::optional<std::string>& units, bool modelDependent)
46 ✗ : m_name(name),
47 ✗ m_displayName(displayName),
48 ✗ m_shortName(shortName),
49 ✗ m_description(description),
50 ✗ m_type(type),
51 ✗ m_units(units),
52 ✗ m_modelDependent(modelDependent) {}
53
54 ✗ std::string BCLMeasureOutput::name() const {
55 ✗ return m_name;
56 }
57
58 ✗ std::string BCLMeasureOutput::displayName() const {
59 ✗ return m_displayName;
60 }
61
62 ✗ boost::optional<std::string> BCLMeasureOutput::shortName() const {
63 ✗ return m_shortName;
64 }
65
66 ✗ boost::optional<std::string> BCLMeasureOutput::description() const {
67 ✗ return m_description;
68 }
69
70 ✗ std::string BCLMeasureOutput::type() const {
71 ✗ return m_type;
72 }
73
74 ✗ boost::optional<std::string> BCLMeasureOutput::units() const {
75 ✗ return m_units;
76 }
77
78 ✗ bool BCLMeasureOutput::modelDependent() const {
79 ✗ return m_modelDependent;
80 }
81
82 ✗ void BCLMeasureOutput::writeValues(pugi::xml_node& element) const {
83 ✗ auto subelement = element.append_child("name");
84 ✗ auto text = subelement.text();
85 ✗ text.set(m_name.c_str());
86
87 ✗ subelement = element.append_child("display_name");
88 ✗ text = subelement.text();
89 ✗ text.set(m_displayName.c_str());
90
91 ✗ if (m_shortName) {
92 ✗ subelement = element.append_child("short_name");
93 ✗ text = subelement.text();
94 ✗ text.set((*m_shortName).c_str());
95 }
96
97 ✗ if (m_description) {
98 ✗ subelement = element.append_child("description");
99 ✗ text = subelement.text();
100 ✗ text.set((*m_description).c_str());
101 }
102
103 ✗ subelement = element.append_child("type");
104 ✗ text = subelement.text();
105 ✗ text.set(m_type.c_str());
106
107 ✗ if (m_units) {
108 ✗ subelement = element.append_child("units");
109 ✗ text = subelement.text();
110 ✗ text.set((*m_units).c_str());
111 }
112
113 ✗ subelement = element.append_child("model_dependent");
114 ✗ text = subelement.text();
115 ✗ text.set(m_modelDependent ? "true" : "false");
116 ✗ }
117
118 ✗ Json::Value BCLMeasureOutput::toJSON() const {
119 ✗ Json::Value root;
120
121 ✗ root["name"] = m_name;
122
123 ✗ root["display_name"] = m_displayName;
124
125 ✗ if (m_shortName) {
126 ✗ root["short_name"] = *m_shortName;
127 }
128
129 ✗ if (m_description) {
130 ✗ root["description"] = *m_description;
131 }
132
133 ✗ root["type"] = m_type;
134
135 ✗ if (m_units) {
136 ✗ root["units"] = *m_units;
137 }
138
139 ✗ root["model_dependent"] = m_modelDependent;
140
141 ✗ return root;
142 ✗ }
143
144 ✗ std::string BCLMeasureOutput::toJSONString() const {
145 ✗ return toJSON().toStyledString();
146 }
147
148 ✗ bool BCLMeasureOutput::operator==(const BCLMeasureOutput& other) const {
149 ✗ if (m_name != other.name()) {
150 ✗ return false;
151 }
152
153 ✗ if (m_displayName != other.displayName()) {
154 ✗ return false;
155 }
156
157 ✗ if (m_shortName && !other.shortName()) {
158 ✗ return false;
159 ✗ } else if (!m_shortName && other.shortName()) {
160 ✗ return false;
161 ✗ } else if (m_shortName && other.shortName()) {
162 ✗ if (m_shortName.get() != other.shortName().get()) {
163 ✗ return false;
164 }
165 }
166
167 ✗ if (m_description && !other.description()) {
168 ✗ return false;
169 ✗ } else if (!m_description && other.description()) {
170 ✗ return false;
171 ✗ } else if (m_description && other.description()) {
172 ✗ if (m_description.get() != other.description().get()) {
173 ✗ return false;
174 }
175 }
176
177 ✗ if (m_type != other.type()) {
178 ✗ return false;
179 }
180
181 ✗ if (m_units && !other.units()) {
182 ✗ return false;
183 ✗ } else if (!m_units && other.units()) {
184 ✗ return false;
185 ✗ } else if (m_units && other.units()) {
186 ✗ if (m_units.get() != other.units().get()) {
187 ✗ return false;
188 }
189 }
190
191 ✗ if (m_modelDependent != other.modelDependent()) {
192 ✗ return false;
193 }
194
195 ✗ return true;
196 }
197
198 ✗ std::ostream& operator<<(std::ostream& os, const BCLMeasureOutput& output) {
199 ✗ pugi::xml_document doc;
200 ✗ auto element = doc.append_child("Output");
201 ✗ output.writeValues(element);
202
203 ✗ doc.save(os, " ");
204 ✗ return os;
205 ✗ }
206
207 } // namespace openstudio
208