GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 71.8% 84 / 0 / 117
Functions: 87.0% 20 / 0 / 23
Branches: 58.3% 42 / 0 / 72

src/nano/nano_observer.hpp
Line Branch Exec Source
1 #ifndef MODEL_NANO_OBSERVER_HPP
2 #define MODEL_NANO_OBSERVER_HPP
3
4 #include "nano_function.hpp"
5
6 namespace Nano {
7
8 class Observer
9 {
10
11 template <typename T>
12 friend class Signal;
13
14 struct DelegateKeyObserver
15 {
16 DelegateKey delegate;
17 Observer* observer;
18 };
19 struct SSNode
20 {
21 DelegateKeyObserver data;
22 SSNode* next;
23 }* head = nullptr;
24
25 //-----------------------------------------------------------PRIVATE METHODS
26
27 1442047 void insert(DelegateKey const& key, Observer* obs) {
28 1442047 head = new SSNode{{key, obs}, head};
29 1442047 }
30
31 // cppcheck-suppress constParameterPointer
32 728626 void remove(DelegateKey const& key, Observer* obs) {
33 728626 SSNode* node = head;
34 728626 SSNode* prev = nullptr;
35 // Only delete the first occurrence
36 // cppcheck-suppress nullPointerRedundantCheck
37
1/2
✓ Branch 0 taken 12556993 times.
✗ Branch 1 not taken.
12556993 for (; node; prev = node, node = node->next) {
38
6/6
✓ Branch 1 taken 12465253 times.
✓ Branch 2 taken 91740 times.
✓ Branch 3 taken 728626 times.
✓ Branch 4 taken 11736627 times.
✓ Branch 5 taken 728626 times.
✓ Branch 6 taken 11828367 times.
12556993 if (node->data.delegate == key && node->data.observer == obs) {
39
2/2
✓ Branch 0 taken 241146 times.
✓ Branch 1 taken 487480 times.
728626 if (prev) {
40 241146 prev->next = node->next;
41 } else {
42 487480 head = head->next;
43 }
44
1/2
✓ Branch 0 taken 728626 times.
✗ Branch 1 not taken.
728626 delete node;
45 728626 break;
46 }
47 }
48 728626 }
49
50 15881950 void removeAll() {
51
2/2
✓ Branch 0 taken 709064 times.
✓ Branch 1 taken 15881950 times.
16591014 for (auto node = head; node;) {
52 709064 auto temp = node;
53 // If this is us we only need to delete
54
2/2
✓ Branch 0 taken 708779 times.
✓ Branch 1 taken 285 times.
709064 if (this != node->data.observer) {
55 // Remove this slot from this listening Observer
56 708779 node->data.observer->remove(node->data.delegate, this);
57 }
58 709064 node = node->next;
59
1/2
✓ Branch 0 taken 709064 times.
✗ Branch 1 not taken.
709064 delete temp;
60 }
61 15881950 head = nullptr;
62 15881950 }
63
64 bool ss_isEmpty() const {
65 return head == nullptr;
66 }
67
68 template <typename Delegate, typename... Uref>
69 10700966 void onEach(Uref&&... args) {
70
21/36
void Nano::Observer::onEach<Nano::Function<void ()>>():
✓ Branch 0 taken 1685809 times.
✓ Branch 1 taken 6604506 times.
void Nano::Observer::onEach<Nano::Function<void (double)>, double&>(double&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void Nano::Observer::onEach<Nano::Function<void (int)>, int&>(int&):
✗ Branch 0 not taken.
✓ Branch 1 taken 1986541 times.
void Nano::Observer::onEach<Nano::Function<void (int)>, int>(int&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 209117 times.
void Nano::Observer::onEach<Nano::Function<void (int, int)>, int, int>(int&&, int&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 227476 times.
void Nano::Observer::onEach<Nano::Function<void (int, openstudio::UUID, openstudio::UUID)>, unsigned int&, openstudio::UUID&, openstudio::UUID&>(unsigned int&, openstudio::UUID&, openstudio::UUID&):
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 275400 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::UUID const&)>, openstudio::UUID&>(openstudio::UUID&):
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 9931 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::WorkspaceObject const&, openstudio::IddObjectType const&, openstudio::UUID const&)>, openstudio::WorkspaceObject const&, openstudio::IddObjectType, openstudio::UUID>(openstudio::WorkspaceObject const&, openstudio::IddObjectType&&, openstudio::UUID&&):
✓ Branch 0 taken 2445 times.
✓ Branch 1 taken 570339 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::WorkspaceObject const&, openstudio::IddObjectType const&, openstudio::UUID const&)>, openstudio::WorkspaceObject, openstudio::IddObjectType, openstudio::UUID&>(openstudio::WorkspaceObject&&, openstudio::IddObjectType&&, openstudio::UUID&):
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9916 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::model::ComponentWatcher const&)>, openstudio::model::ComponentWatcher>(openstudio::model::ComponentWatcher&&):
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::model::detail::ModelObject_Impl*, openstudio::IddObjectType, openstudio::UUID)>, openstudio::model::detail::ModelObject_Impl*, openstudio::IddObjectType, openstudio::UUID>(openstudio::model::detail::ModelObject_Impl*&&, openstudio::IddObjectType&&, openstudio::UUID&&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>, char const (&) [15]>(char const (&) [15]):
✗ Branch 0 not taken.
✓ Branch 1 taken 178657 times.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>, char const (&) [16]>(char const (&) [16]):
✗ Branch 0 not taken.
✓ Branch 1 taken 30460 times.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>, char const (&) [18]>(char const (&) [18]):
✗ Branch 0 not taken.
✓ Branch 1 taken 18359 times.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::optional<openstudio::BCLComponent> const&)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLComponent>&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLComponent>&):
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::optional<openstudio::BCLMeasure> const&)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLMeasure>&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLMeasure>&):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>, openstudio::IddObjectType const&, openstudio::UUID const&)>, std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType, openstudio::UUID&>(std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType&&, openstudio::UUID&):
✗ Branch 0 not taken.
✓ Branch 1 taken 9916 times.
void Nano::Observer::onEach<Nano::Function<void (std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>, openstudio::IddObjectType const&, openstudio::UUID const&)>, std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType, openstudio::UUID>(std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType&&, openstudio::UUID&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 570339 times.
12389250 for (auto node = head, next = head; node; node = next) {
71 1688284 next = node->next;
72 // Perfect forward and emit
73
6/18
void Nano::Observer::onEach<Nano::Function<void ()>>():
✓ Branch 2 taken 1685809 times.
void Nano::Observer::onEach<Nano::Function<void (double)>, double&>(double&):
✗ Branch 3 not taken.
void Nano::Observer::onEach<Nano::Function<void (int)>, int&>(int&):
✗ Branch 3 not taken.
void Nano::Observer::onEach<Nano::Function<void (int)>, int>(int&&):
✗ Branch 3 not taken.
void Nano::Observer::onEach<Nano::Function<void (int, int)>, int, int>(int&&, int&&):
✗ Branch 4 not taken.
void Nano::Observer::onEach<Nano::Function<void (int, openstudio::UUID, openstudio::UUID)>, unsigned int&, openstudio::UUID&, openstudio::UUID&>(unsigned int&, openstudio::UUID&, openstudio::UUID&):
✓ Branch 5 taken 6 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::UUID const&)>, openstudio::UUID&>(openstudio::UUID&):
✓ Branch 3 taken 16 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::WorkspaceObject const&, openstudio::IddObjectType const&, openstudio::UUID const&)>, openstudio::WorkspaceObject const&, openstudio::IddObjectType, openstudio::UUID>(openstudio::WorkspaceObject const&, openstudio::IddObjectType&&, openstudio::UUID&&):
✓ Branch 5 taken 2445 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::WorkspaceObject const&, openstudio::IddObjectType const&, openstudio::UUID const&)>, openstudio::WorkspaceObject, openstudio::IddObjectType, openstudio::UUID&>(openstudio::WorkspaceObject&&, openstudio::IddObjectType&&, openstudio::UUID&):
✓ Branch 5 taken 2 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::model::ComponentWatcher const&)>, openstudio::model::ComponentWatcher>(openstudio::model::ComponentWatcher&&):
✓ Branch 3 taken 6 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::model::detail::ModelObject_Impl*, openstudio::IddObjectType, openstudio::UUID)>, openstudio::model::detail::ModelObject_Impl*, openstudio::IddObjectType, openstudio::UUID>(openstudio::model::detail::ModelObject_Impl*&&, openstudio::IddObjectType&&, openstudio::UUID&&):
✗ Branch 5 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>, char const (&) [15]>(char const (&) [15]):
✗ Branch 3 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>, char const (&) [16]>(char const (&) [16]):
✗ Branch 3 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)>, char const (&) [18]>(char const (&) [18]):
✗ Branch 3 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::optional<openstudio::BCLComponent> const&)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLComponent>&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLComponent>&):
✗ Branch 4 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::optional<openstudio::BCLMeasure> const&)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLMeasure>&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::optional<openstudio::BCLMeasure>&):
✗ Branch 4 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>, openstudio::IddObjectType const&, openstudio::UUID const&)>, std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType, openstudio::UUID&>(std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType&&, openstudio::UUID&):
✗ Branch 5 not taken.
void Nano::Observer::onEach<Nano::Function<void (std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>, openstudio::IddObjectType const&, openstudio::UUID const&)>, std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType, openstudio::UUID>(std::shared_ptr<openstudio::detail::WorkspaceObject_Impl>&, openstudio::IddObjectType&&, openstudio::UUID&&):
✗ Branch 5 not taken.
1688284 Delegate(node->data.delegate)(std::forward<Uref>(args)...);
74 }
75 10700966 }
76
77 template <typename Delegate, typename Accumulate, typename... Uref>
78 void onEach_Accumulate(Accumulate&& accumulate, Uref&&... args) {
79 for (auto node = head, next = head; node; node = next) {
80 next = node->next;
81 // Perfect forward, emit, and accumulate the return value
82 accumulate(Delegate(node->data.delegate)(std::forward<Uref>(args)...));
83 }
84 }
85
86 //-----------------------------------------------------------------PROTECTED
87
88 protected:
89 15881950 ~Observer() {
90 15881950 removeAll();
91 15881950 }
92
93 //--------------------------------------------------------------------PUBLIC
94
95 public:
96 15898954 Observer() = default;
97 Observer(const Observer& other) = delete; // non construction-copyable
98 Observer& operator=(const Observer&) = delete; // non copyable
99 };
100
101 } // namespace Nano
102
103 #endif // MODEL_NANO_OBSERVER_HPP
104