GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 47.1% 32 / 0 / 68
Functions: 47.6% 10 / 0 / 21
Branches: 51.9% 27 / 0 / 52

src/measure/OSOutput.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 "OSOutput.hpp"
7
8 #include "../utilities/core/Assert.hpp"
9
10 #include <json/value.h>
11
12 #include <sstream>
13
14 namespace openstudio {
15 namespace measure {
16
17 1 OSOutput OSOutput::makeBoolOutput(const std::string& name, bool modelDependent) {
18
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 OSOutput result(name, OSOutputType::Boolean, modelDependent);
19 1 return result;
20 }
21
22 1 OSOutput OSOutput::makeDoubleOutput(const std::string& name, bool modelDependent) {
23
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 OSOutput result(name, OSOutputType::Double, modelDependent);
24 1 return result;
25 }
26
27 1 OSOutput OSOutput::makeIntegerOutput(const std::string& name, bool modelDependent) {
28
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 OSOutput result(name, OSOutputType::Integer, modelDependent);
29 1 return result;
30 }
31
32 1 OSOutput OSOutput::makeStringOutput(const std::string& name, bool modelDependent) {
33
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 OSOutput result(name, OSOutputType::String, modelDependent);
34 1 return result;
35 }
36
37 4 std::string OSOutput::name() const {
38 4 return m_name;
39 }
40
41 8 std::string OSOutput::displayName() const {
42 8 return m_displayName;
43 }
44
45 ✗ std::string OSOutput::shortName() const {
46 ✗ return m_shortName;
47 }
48
49 ✗ boost::optional<std::string> OSOutput::description() const {
50 ✗ return m_description;
51 }
52
53 8 OSOutputType OSOutput::type() const {
54 8 return m_type;
55 }
56
57 ✗ boost::optional<std::string> OSOutput::units() const {
58 ✗ return m_units;
59 }
60
61 ✗ bool OSOutput::modelDependent() const {
62 ✗ return m_modelDependent;
63 }
64
65 ✗ void OSOutput::setDisplayName(const std::string& displayName) {
66 ✗ m_displayName = displayName;
67 ✗ }
68
69 ✗ void OSOutput::setShortName(const std::string& shortName) {
70 ✗ m_shortName = shortName;
71 ✗ }
72
73 ✗ void OSOutput::setDescription(const std::string& description) {
74 ✗ m_description = description;
75 ✗ }
76
77 ✗ void OSOutput::setUnits(const std::string& units) {
78 ✗ m_units = units;
79 ✗ }
80
81 4 std::string OSOutput::print() const {
82
1/1
✓ Branch 1 taken 4 times.
4 std::stringstream ss;
83
84 // name
85
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 ss << name();
86
2/3
✓ Branch 1 taken 4 times.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
4 if (!displayName().empty()) {
87
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
4 ss << " (" << displayName() << ")";
88 }
89
1/1
✓ Branch 1 taken 4 times.
4 ss << '\n';
90
91 // type and required
92
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
4 ss << type().valueName() << '\n';
93
94
1/1
✓ Branch 1 taken 4 times.
8 return ss.str();
95 4 }
96
97 ✗ OSOutput::OSOutput() = default;
98
99 4 OSOutput::OSOutput(const std::string& name, const OSOutputType& type, bool modelDependent)
100
2/2
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
4 : m_name(name), m_displayName(name), m_shortName(name), m_type(type), m_modelDependent(modelDependent) {}
101
102 4 std::ostream& operator<<(std::ostream& os, const OSOutput& output) {
103
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 os << output.print();
104 4 return os;
105 }
106
107 ✗ Json::Value OSOutput::toJSON() const {
108 ✗ Json::Value root;
109 ✗ root["name"] = m_name;
110 ✗ root["display_name"] = m_displayName;
111 ✗ root["m_shortName"] = m_shortName;
112 ✗ if (m_description) {
113 ✗ root["description"] = *m_description;
114 }
115 ✗ root["type"] = m_type.valueName();
116 ✗ if (m_units) {
117 ✗ root["units"] = *m_units;
118 }
119 ✗ root["model_dependent"] = m_modelDependent;
120
121 ✗ return root;
122 ✗ }
123
124 ✗ std::string OSOutput::toJSONString() const {
125 ✗ return toJSON().toStyledString();
126 }
127
128 } // namespace measure
129 } // namespace openstudio
130