src/utilities/idf/IdfObjectWatcher.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_IDFOBJECTWATCHER_HPP | ||
| 7 | #define UTILITIES_IDF_IDFOBJECTWATCHER_HPP | ||
| 8 | |||
| 9 | #include <nano/nano_signal_slot.hpp> // Signal-Slot replacement | ||
| 10 | #include <utilities/UtilitiesAPI.hpp> | ||
| 11 | #include <utilities/idf/IdfObject.hpp> | ||
| 12 | |||
| 13 | namespace openstudio { | ||
| 14 | |||
| 15 | /** IdfObjectWatcher watches an IdfObject for signals emitted on changes. These signals will cause | ||
| 16 | * the watcher to mark the IdfObject as dirty. The dirty flag will persist until reset by the | ||
| 17 | * user. Virtual methods onChangeIdfObject and onDataFieldChange are also available to override. | ||
| 18 | * The former is called every time the IdfObject changes in any way; the latter is called whenever | ||
| 19 | * a data field changes (not triggered by comment changes, and is superceded by | ||
| 20 | * onRelationshipChange for WorkspaceObject pointer fields.) The virtual method onBecomeDirty is | ||
| 21 | * called only after dirty transitions from false to true. Alternatively, the virtual method | ||
| 22 | * onBecomeClean is called only after dirty transitions from true to false. | ||
| 23 | * | ||
| 24 | * IdfObjectWatcher is an atypical object because it is designed to be stack allocated. In many | ||
| 25 | * cases it would be preferred to connect your own heap allocated object to the Workspace signals | ||
| 26 | * directly rather than using this convenience class. **/ | ||
| 27 | class UTILITIES_API IdfObjectWatcher : public Nano::Observer | ||
| 28 | { | ||
| 29 | |||
| 30 | public: | ||
| 31 | /// constructor with IdfObject to watch | ||
| 32 | IdfObjectWatcher(const IdfObject& idfObject); | ||
| 33 | |||
| 34 | /// virtual destructor | ||
| 35 | 16 | virtual ~IdfObjectWatcher() = default; | |
| 36 | |||
| 37 | /// is the watcher currently enabled | ||
| 38 | bool enabled() const; | ||
| 39 | |||
| 40 | /// enable the watcher | ||
| 41 | void enable(); | ||
| 42 | |||
| 43 | // disable watcher, returns true if it was enabled | ||
| 44 | bool disable(); | ||
| 45 | |||
| 46 | /// true if object has changed | ||
| 47 | bool dirty() const; | ||
| 48 | |||
| 49 | /// if dirty, then true if data field changed, false if some other change | ||
| 50 | bool dataChanged() const; | ||
| 51 | |||
| 52 | /// if dirty, then true if name field changed, false otherwise | ||
| 53 | bool nameChanged() const; | ||
| 54 | |||
| 55 | /// reset dirty, dataChanged, and nameChanged | ||
| 56 | virtual void clearState(); | ||
| 57 | |||
| 58 | /// called each time the IdfObject changes if watcher enabled | ||
| 59 | virtual void onChangeIdfObject(); | ||
| 60 | |||
| 61 | /// called each time one of the IdfObject's data fields changes if watcher enabled | ||
| 62 | virtual void onDataFieldChange(); | ||
| 63 | |||
| 64 | /// called each time the IdfObject's name changes if watcher enabled | ||
| 65 | virtual void onNameChange(); | ||
| 66 | |||
| 67 | /// called after dirty transitions from false to true if watcher enabled | ||
| 68 | virtual void onBecomeDirty(); | ||
| 69 | |||
| 70 | /// called after dirty transitions from true to false if watcher enabled | ||
| 71 | virtual void onBecomeClean(); | ||
| 72 | |||
| 73 | // public slots: | ||
| 74 | void change(); | ||
| 75 | void dataChange(); | ||
| 76 | void nameChange(); | ||
| 77 | |||
| 78 | protected: | ||
| 79 | bool m_enabled; | ||
| 80 | bool m_dirty; | ||
| 81 | bool m_dataChanged; | ||
| 82 | bool m_nameChanged; | ||
| 83 | }; | ||
| 84 | |||
| 85 | } // namespace openstudio | ||
| 86 | |||
| 87 | #endif // UTILITIES_IDF_IDFOBJECTWATCHER_HPP | ||
| 88 |