GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 93.3% 14 / 0 / 15
Functions: 100.0% 3 / 0 / 3
Branches: 85.7% 6 / 0 / 7

src/utilities/idf/IdfObjectDiff.hpp
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 #ifndef UTILITIES_IDF_IDFOBJECTDIFF_HPP
7 #define UTILITIES_IDF_IDFOBJECTDIFF_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include <boost/optional.hpp>
12
13 #include <memory>
14
15 namespace openstudio {
16 namespace detail {
17 class IdfObjectDiff_Impl;
18 }
19
20 /** IdfObjectDiff represents a change to an IdfObject.
21 **/
22 class UTILITIES_API IdfObjectDiff
23 {
24 public:
25 IdfObjectDiff();
26
27 IdfObjectDiff(boost::optional<unsigned> index, boost::optional<std::string> oldValue, boost::optional<std::string> newValue);
28
29 /// get the index that changed, uninitialized means no field (e.g. object level comment changed)
30 boost::optional<unsigned> index() const;
31
32 /// returns true if oldValue == newValue
33 bool isNull() const;
34
35 /// get the old value, uninitialized optional means that the field did not previously exist
36 boost::optional<std::string> oldValue() const;
37
38 /// get the new value, uninitialized optional means that the field no longer exists
39 boost::optional<std::string> newValue() const;
40
41 /// cast to type T, can throw std::bad_cast
42 template <typename T>
43 276508 T cast() const {
44 276508 std::shared_ptr<typename T::ImplType> impl = this->getImpl<typename T::ImplType>();
45
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 276508 times.
276508 if (!impl) {
46 ✗ throw(std::bad_cast());
47 }
48
1/1
✓ Branch 2 taken 276508 times.
553016 return T(std::move(impl));
49 276508 }
50
51 /// cast to optional of type T
52 template <typename T>
53 358950 boost::optional<T> optionalCast() const {
54 358950 boost::optional<T> result;
55 358950 std::shared_ptr<typename T::ImplType> impl = this->getImpl<typename T::ImplType>();
56
2/2
✓ Branch 1 taken 276508 times.
✓ Branch 2 taken 82442 times.
358950 if (impl) {
57
2/2
✓ Branch 2 taken 276508 times.
✓ Branch 5 taken 276508 times.
276508 result = T(std::move(impl));
58 }
59 717900 return result;
60 358950 }
61
62 protected:
63 IdfObjectDiff(const std::shared_ptr<detail::IdfObjectDiff_Impl>& impl);
64
65 // get the impl
66 template <typename T>
67 2714751 std::shared_ptr<T> getImpl() const {
68 2714751 return std::dynamic_pointer_cast<T>(m_impl);
69 }
70
71 private:
72 std::shared_ptr<detail::IdfObjectDiff_Impl> m_impl;
73 };
74
75 } // namespace openstudio
76
77 #endif // UTILITIES_IDF_IDFOBJECTDIFF_HPP
78