GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 70.4% 38 / 0 / 54
Functions: 66.7% 12 / 0 / 18
Branches: 37.0% 30 / 0 / 81

src/utilities/idd/IddKey.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 "IddKey.hpp"
7 #include "IddKey_Impl.hpp"
8
9 #include "IddRegex.hpp"
10
11 namespace openstudio {
12
13 namespace detail {
14
15 ✗ IddKey_Impl::IddKey_Impl() = default;
16
17 /// equality operator
18 7 bool IddKey_Impl::operator==(const IddKey_Impl& other) const {
19
5/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
7 return ((this == &other) || ((m_name == other.m_name) && (m_properties == other.m_properties)));
20 }
21
22 /// get name
23 9428776 std::string IddKey_Impl::name() const {
24 9428776 return m_name;
25 }
26
27 ✗ const IddKeyProperties& IddKey_Impl::properties() const {
28 ✗ return m_properties;
29 }
30
31 6643593 std::shared_ptr<IddKey_Impl> IddKey_Impl::load(const std::string& name, const std::string& text) {
32
33 6643593 std::shared_ptr<IddKey_Impl> result;
34
1/1
✓ Branch 1 taken 6643593 times.
6643593 IddKey_Impl iddKeyImpl(name);
35
36 try {
37
1/1
✓ Branch 1 taken 6643593 times.
6643593 iddKeyImpl.parse(text);
38 ✗ } catch (...) {
39 ✗ return result;
40 ✗ }
41
42
3/5
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 7 taken 6643593 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
6643593 result = std::shared_ptr<IddKey_Impl>(new IddKey_Impl(iddKeyImpl));
43 6643593 return result;
44 6643593 }
45
46 346368 std::ostream& IddKey_Impl::print(std::ostream& os) const {
47 346368 os << " \\key " << m_name << '\n';
48 346368 return os;
49 }
50
51 // PRIVATE
52
53
1/1
✓ Branch 2 taken 6643593 times.
6643593 IddKey_Impl::IddKey_Impl(const std::string& name) : m_name(name) {}
54
55 6643593 void IddKey_Impl::parse(const std::string& text) {
56
1/1
✓ Branch 1 taken 6643593 times.
6643593 boost::smatch matches;
57
3/4
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 6 taken 6643593 times.
✗ Branch 7 not taken.
6643593 if (boost::regex_search(text, matches, iddRegex::contentAndCommentLine())) {
58
3/3
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 7 taken 6643593 times.
6643593 std::string keyName(matches[1].first, matches[1].second);
59
1/1
✓ Branch 2 taken 6643593 times.
6643593 boost::trim(keyName);
60
3/4
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6643593 times.
6643593 if (!boost::equals(name(), keyName)) {
61 ✗ LOG_AND_THROW("Key name '" << keyName << "' does not match expected '" << name() << "'");
62 };
63
64
3/3
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
✓ Branch 7 taken 6643593 times.
6643593 std::string note(matches[2].first, matches[2].second);
65
1/1
✓ Branch 1 taken 6643593 times.
6643593 m_properties.note = note;
66 6643593 } else {
67 ✗ LOG_AND_THROW("Key name could not be determined from text '" << text << "'");
68 }
69 6643593 }
70
71 } // namespace detail
72
73 ✗ IddKey::IddKey() : m_impl(std::shared_ptr<detail::IddKey_Impl>(new detail::IddKey_Impl())) {}
74
75 33875842 IddKey::IddKey(const IddKey& other) = default;
76
77 7 bool IddKey::operator==(const IddKey& other) const {
78 7 return (*m_impl == *(other.m_impl));
79 }
80
81 ✗ bool IddKey::operator!=(const IddKey& other) const {
82 ✗ return !(*m_impl == *(other.m_impl));
83 }
84
85 2785183 std::string IddKey::name() const {
86 2785183 return m_impl->name();
87 }
88
89 ✗ const IddKeyProperties& IddKey::properties() const {
90 ✗ return m_impl->properties();
91 }
92
93 6643593 OptionalIddKey IddKey::load(const std::string& name, const std::string& text) {
94
1/1
✓ Branch 1 taken 6643593 times.
6643593 std::shared_ptr<detail::IddKey_Impl> p = detail::IddKey_Impl::load(name, text);
95
1/2
✓ Branch 1 taken 6643593 times.
✗ Branch 2 not taken.
6643593 if (p) {
96
2/2
✓ Branch 1 taken 6643593 times.
✓ Branch 4 taken 6643593 times.
6643593 return IddKey(p);
97 } else {
98 ✗ return boost::none;
99 }
100 6643593 }
101
102 346368 std::ostream& IddKey::print(std::ostream& os) const {
103 346368 return m_impl->print(os);
104 }
105
106 // PRIVATE
107
108 6643593 IddKey::IddKey(const std::shared_ptr<detail::IddKey_Impl>& impl) : m_impl(impl) {}
109
110 // NON-MEMBER FUNCTIONS
111
112 ✗ std::ostream& operator<<(std::ostream& os, const IddKey& iddKey) {
113 ✗ return iddKey.print(os);
114 }
115
116 } // namespace openstudio
117