GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 1.9% 1 / 0 / 54
Functions: 5.3% 1 / 0 / 19
Branches: 8.3% 2 / 0 / 24

src/measure/ModelicaParameters.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 "ModelicaParameters.hpp"
7 #include <map>
8
9 namespace openstudio {
10 namespace measure {
11
12 namespace detail {
13 class ModelicaParameter_Impl
14 {
15 public:
16 ✗ ModelicaParameter_Impl(const std::string& model, const std::string& key, const std::string& value)
17 ✗ : m_model(model), m_key(key), m_value(value) {}
18
19 ✗ std::string model() const {
20 ✗ return m_model;
21 };
22
23 ✗ std::string key() const {
24 ✗ return m_key;
25 };
26
27 ✗ std::string value() const {
28 ✗ return m_value;
29 }
30
31 ✗ void setValue(const std::string& value) {
32 ✗ m_value = value;
33 ✗ }
34
35 private:
36 std::string m_model;
37 std::string m_key;
38 std::string m_value;
39 };
40
41 class ModelicaParameters_Impl
42 {
43 public:
44 ✗ std::string getParameterValue(const std::string& model, const std::string& key) const {
45 ✗ const auto it = m_parameters.find({model, key});
46 ✗ if (it != m_parameters.end()) {
47 ✗ return it->second.value();
48 }
49
50 ✗ return "";
51 }
52
53 ✗ void setParameterValue(const std::string& model, const std::string& key, const std::string& value) {
54 ✗ const auto it = m_parameters.find({model, key});
55 ✗ if (it != m_parameters.end()) {
56 ✗ it->second.setValue(value);
57 ✗ return;
58 }
59
60 ✗ m_parameters.emplace(std::pair<std::string, std::string>({model, key}), ModelicaParameter(model, key, value));
61 }
62
63 ✗ std::vector<ModelicaParameter> getAllParameters() const {
64 ✗ std::vector<ModelicaParameter> parameters;
65 ✗ parameters.reserve(m_parameters.size());
66
67 ✗ for (const auto& [_, value] : m_parameters) {
68 ✗ parameters.push_back(value);
69 }
70
71 ✗ return parameters;
72 ✗ }
73
74 ✗ void clearAllParameters() {
75 ✗ m_parameters.clear();
76 ✗ }
77
78 private:
79 static std::string keyHash(const std::string& model, const std::string& key) {
80 return model + key;
81 }
82
83 std::map<std::pair<std::string, std::string>, ModelicaParameter> m_parameters;
84 };
85 } // namespace detail
86
87 ✗ ModelicaParameter::ModelicaParameter(const std::string& model, const std::string& key, const std::string& value)
88 ✗ : m_impl{std::make_unique<detail::ModelicaParameter_Impl>(model, key, value)} {};
89
90 ✗ std::string ModelicaParameter::model() const {
91 ✗ return m_impl->model();
92 }
93
94 ✗ std::string ModelicaParameter::key() const {
95 ✗ return m_impl->key();
96 }
97
98 ✗ std::string ModelicaParameter::value() const {
99 ✗ return m_impl->value();
100 }
101
102 ✗ void ModelicaParameter::setValue(const std::string& value) {
103 ✗ m_impl->setValue(value);
104 ✗ }
105
106
2/2
✓ Branch 1 taken 53 times.
✓ Branch 4 taken 53 times.
53 ModelicaParameters::ModelicaParameters() : m_impl{std::make_unique<detail::ModelicaParameters_Impl>()} {};
107
108 ✗ std::string ModelicaParameters::getParameterValue(const std::string& model, const std::string& key) const {
109 ✗ return m_impl->getParameterValue(model, key);
110 }
111
112 ✗ void ModelicaParameters::setParameterValue(const std::string& model, const std::string& key, const std::string& value) {
113 ✗ m_impl->setParameterValue(model, key, value);
114 ✗ }
115
116 ✗ std::vector<ModelicaParameter> ModelicaParameters::getAllParameters() const {
117 ✗ return m_impl->getAllParameters();
118 }
119
120 ✗ void ModelicaParameters::clearAllParameters() {
121 ✗ m_impl->clearAllParameters();
122 ✗ }
123
124 } // namespace measure
125 } // namespace openstudio
126