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 1447535 void insert(DelegateKey const& key, Observer* obs) {
28 1447535 head = new SSNode{{key, obs}, head};
29 1447535 }
30
31 // cppcheck-suppress constParameterPointer
32 731413 void remove(DelegateKey const& key, Observer* obs) {
33 731413 SSNode* node = head;
34 731413 SSNode* prev = nullptr;
35 // Only delete the first occurrence
36 // cppcheck-suppress nullPointerRedundantCheck
37
1/2
✓ Branch 0 taken 12504951 times.
✗ Branch 1 not taken.
12504951 for (; node; prev = node, node = node->next) {
38
6/6
✓ Branch 1 taken 12412738 times.
✓ Branch 2 taken 92213 times.
✓ Branch 3 taken 731413 times.
✓ Branch 4 taken 11681325 times.
✓ Branch 5 taken 731413 times.
✓ Branch 6 taken 11773538 times.
12504951 if (node->data.delegate == key && node->data.observer == obs) {
39
2/2
✓ Branch 0 taken 234739 times.
✓ Branch 1 taken 496674 times.
731413 if (prev) {
40 234739 prev->next = node->next;
41 } else {
42 496674 head = head->next;
43 }
44
1/2
✓ Branch 0 taken 731413 times.
✗ Branch 1 not taken.
731413 delete node;
45 731413 break;
46 }
47 }
48 731413 }
49
50 15915922 void removeAll() {
51
2/2
✓ Branch 0 taken 711765 times.
✓ Branch 1 taken 15915922 times.
16627687 for (auto node = head; node;) {
52 711765 auto temp = node;
53 // If this is us we only need to delete
54
2/2
✓ Branch 0 taken 711480 times.
✓ Branch 1 taken 285 times.
711765 if (this != node->data.observer) {
55 // Remove this slot from this listening Observer
56 711480 node->data.observer->remove(node->data.delegate, this);
57 }
58 711765 node = node->next;
59
1/2
✓ Branch 0 taken 711765 times.
✗ Branch 1 not taken.
711765 delete temp;
60 }
61 15915922 head = nullptr;
62 15915922 }
63
64 bool ss_isEmpty() const {
65 return head == nullptr;
66 }
67
68 template <typename Delegate, typename... Uref>
69 10745161 void onEach(Uref&&... args) {
70
21/36
void Nano::Observer::onEach<Nano::Function<void ()>>():
✓ Branch 0 taken 1690980 times.
✓ Branch 1 taken 6630382 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 1994693 times.
void Nano::Observer::onEach<Nano::Function<void (int)>, int>(int&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 210373 times.
void Nano::Observer::onEach<Nano::Function<void (int, int)>, int, int>(int&&, int&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 228867 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 276508 times.
void Nano::Observer::onEach<Nano::Function<void (openstudio::UUID const&)>, openstudio::UUID&>(openstudio::UUID&):
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 9974 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 572785 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 9959 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 179761 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 30612 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 18494 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 9959 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 572785 times.
12438616 for (auto node = head, next = head; node; node = next) {
71 1693455 next = node->next;
72 // Perfect forward and emit
73
6/18
void Nano::Observer::onEach<Nano::Function<void ()>>():
✓ Branch 2 taken 1690980 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.
1693455 Delegate(node->data.delegate)(std::forward<Uref>(args)...);
74 }
75 10745161 }
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 15915922 ~Observer() {
90 15915922 removeAll();
91 15915922 }
92
93 //--------------------------------------------------------------------PUBLIC
94
95 public:
96 15932926 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