GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 88.3% 53 / 0 / 60
Functions: 87.5% 14 / 0 / 16
Branches: 64.7% 22 / 0 / 34

src/utilities/idf/WorkspaceWatcher.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 "WorkspaceWatcher.hpp"
7 #include "Workspace_Impl.hpp"
8 #include "../core/Assert.hpp"
9
10 namespace openstudio {
11
12 7 WorkspaceWatcher::WorkspaceWatcher(const Workspace& workspace) : m_enabled(true), m_dirty(false), m_objectAdded(false), m_objectRemoved(false) {
13 7 detail::Workspace_ImplPtr wsImpl = workspace.getImpl<detail::Workspace_Impl>();
14
1/1
✓ Branch 2 taken 7 times.
7 wsImpl.get()->detail::Workspace_Impl::onChange.connect<WorkspaceWatcher, &WorkspaceWatcher::change>(this);
15
16 // ideally this would be a queued connection so objects can be initialized before signal is processed
17
1/1
✓ Branch 2 taken 7 times.
7 wsImpl.get()->detail::Workspace_Impl::addWorkspaceObject.connect<WorkspaceWatcher, &WorkspaceWatcher::objectAdd>(this);
18
19 // this signal happens immediately
20
1/1
✓ Branch 2 taken 7 times.
7 wsImpl.get()->detail::Workspace_Impl::removeWorkspaceObject.connect<WorkspaceWatcher, &WorkspaceWatcher::objectRemove>(this);
21 7 }
22
23 24 bool WorkspaceWatcher::enabled() const {
24 24 return m_enabled;
25 }
26
27 ✗ void WorkspaceWatcher::enable() {
28 ✗ m_enabled = true;
29 ✗ }
30
31 ✗ bool WorkspaceWatcher::disable() {
32 ✗ bool result = m_enabled;
33 ✗ m_enabled = false;
34 ✗ return result;
35 }
36
37 10 bool WorkspaceWatcher::dirty() const {
38 10 return m_dirty;
39 }
40
41 12 bool WorkspaceWatcher::objectAdded() const {
42 12 return m_objectAdded;
43 }
44
45 4 bool WorkspaceWatcher::objectRemoved() const {
46 4 return m_objectRemoved;
47 }
48
49 4 void WorkspaceWatcher::clearState() {
50 4 bool wasDirty = m_dirty;
51 4 m_dirty = false;
52 4 m_objectAdded = false;
53 4 m_objectRemoved = false;
54
55
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (enabled()) {
56
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (wasDirty) {
57 4 onBecomeClean();
58 }
59 }
60 4 }
61
62 14 void WorkspaceWatcher::onChangeWorkspace() {}
63
64 8 void WorkspaceWatcher::onBecomeDirty() {}
65
66 4 void WorkspaceWatcher::onBecomeClean() {}
67
68 5 void WorkspaceWatcher::onObjectAdd(const WorkspaceObject& addedObject) {
69
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
5 OS_ASSERT(addedObject.initialized());
70
4/6
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 12 not taken.
5 OS_ASSERT(addedObject.workspace().isMember(addedObject.handle()));
71 5 }
72
73 1 void WorkspaceWatcher::onObjectRemove(const WorkspaceObject& removedObject) {
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 OS_ASSERT(removedObject.initialized());
75
4/6
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 12 not taken.
1 OS_ASSERT(removedObject.workspace().isMember(removedObject.handle()));
76 1 }
77
78 14 void WorkspaceWatcher::change() {
79 14 bool wasDirty = m_dirty;
80 14 m_dirty = true;
81
82
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
14 if (enabled()) {
83
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 6 times.
14 if (!wasDirty) {
84 8 onBecomeDirty();
85 }
86 14 onChangeWorkspace();
87 }
88 14 }
89
90 5 void WorkspaceWatcher::objectAdd(const WorkspaceObject& addedObject, const openstudio::IddObjectType& /*type*/, const openstudio::UUID& /*uuid*/) {
91 // Note: Args 2 & 3 are simply to comply with Nano::Signal template parameters
92 // let change() handle m_dirty and onChangeWorkspace();
93 5 m_objectAdded = true;
94
95
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 if (enabled()) {
96
2/3
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (!addedObject.handle().isNull()) {
97 5 this->onObjectAdd(addedObject);
98 }
99 }
100 5 }
101
102 1 void WorkspaceWatcher::objectRemove(const WorkspaceObject& removedObject, const openstudio::IddObjectType& /*type*/,
103 const openstudio::UUID& /*uuid*/) {
104 // Note: Args 2 & 3 are simply to comply with Nano::Signal template parameters
105 // let change() handle m_dirty and onChangeWorkspace();
106 1 m_objectRemoved = true;
107
108
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 if (enabled()) {
109 1 this->onObjectRemove(removedObject);
110 }
111 1 }
112
113 } // namespace openstudio
114