GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 1 / 0 / 1
Functions: 100.0% 1 / 0 / 1
Branches: -% 0 / 0 / 0

src/utilities/idf/WorkspaceWatcher.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_WORKSPACEWATCHER_HPP
7 #define UTILITIES_IDF_WORKSPACEWATCHER_HPP
8
9 #include <utilities/UtilitiesAPI.hpp>
10 #include <utilities/idf/IdfObject.hpp>
11 #include <utilities/idf/Workspace.hpp>
12
13 namespace openstudio {
14
15 /** WorkspaceWatcher watches a Workspace for signals emitted on changes. This signals will cause the
16 * watcher to mark the Workspace as dirty. The dirty flag will persist until reset by the user. A virtual
17 * method onChangeWorkspace is also available to override, it is called everytime the Workspace changes. The
18 * virtual method onBecomeDirty is called only after dirty transitions from false to true. Alternatively, the
19 * virtual method onBecomeClean is called only after dirty transitions from true to false.
20 *
21 * WorkspaceWatcher an atypical object because it is designed to be stack allocated. In many cases it
22 * would be preferred to connect your own heap allocated object to the Workspace signals directly rather
23 * than using this convenience class.
24 **/
25 class UTILITIES_API WorkspaceWatcher
26 {
27
28 public:
29 WorkspaceWatcher(const Workspace& workspace);
30
31 7 virtual ~WorkspaceWatcher() = default;
32
33 /// is the watcher currently enabled
34 bool enabled() const;
35
36 /// enable the watcher
37 void enable();
38
39 // disable watcher, returns true if it was enabled
40 bool disable();
41
42 /// true if workspace has changed
43 bool dirty() const;
44
45 /// true if an object has been added
46 bool objectAdded() const;
47
48 /// true if an object has been removed
49 bool objectRemoved() const;
50
51 /// resets dirty, objectAdded, and objectRemoved
52 virtual void clearState();
53
54 /// called each time the IdfObject changes if watcher enabled
55 virtual void onChangeWorkspace();
56
57 /// called after dirty transitions from false to true if watcher enabled
58 virtual void onBecomeDirty();
59
60 /// called after dirty transitions from true to false if watcher enabled
61 virtual void onBecomeClean();
62
63 /// called immediately when a new object is added to the workspace if watcher enabled
64 /// the object may not be fully constructed
65 /// this may be called when an object is restored after a failed remove
66 virtual void onObjectAdd(const WorkspaceObject& addedObject);
67
68 /// called immediately before an object is removed from the workspace if watcher enabled
69 /// the object is still valid when this method is called
70 virtual void onObjectRemove(const WorkspaceObject& removedObject);
71
72 // public slots:
73
74 void change();
75
76 // Note: Args 2 & 3 are simply to comply with Nano::Signal template parameters
77 void objectAdd(const WorkspaceObject& addedObject, const openstudio::IddObjectType& type, const openstudio::UUID& uuid);
78
79 // Note: Args 2 & 3 are simply to comply with Nano::Signal template parameters
80 void objectRemove(const WorkspaceObject& removedObject, const openstudio::IddObjectType& type, const openstudio::UUID& uuid);
81
82 private:
83 bool m_enabled;
84 bool m_dirty;
85 bool m_objectAdded;
86 bool m_objectRemoved;
87 };
88
89 } // namespace openstudio
90 #endif
91