src/utilities/idf/IdfObjectWatcher.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 "IdfObjectWatcher.hpp" | ||
| 7 | #include "IdfObject_Impl.hpp" | ||
| 8 | |||
| 9 | namespace openstudio { | ||
| 10 | |||
| 11 | 16 | IdfObjectWatcher::IdfObjectWatcher(const IdfObject& idfObject) : m_enabled(true), m_dirty(false), m_dataChanged(false), m_nameChanged(false) { | |
| 12 | 16 | detail::IdfObject_ImplPtr objectImpl = idfObject.getImpl<detail::IdfObject_Impl>(); | |
| 13 |
1/1✓ Branch 2 taken 16 times.
|
16 | objectImpl.get()->detail::IdfObject_Impl::onChange.connect<IdfObjectWatcher, &IdfObjectWatcher::change>(this); |
| 14 |
1/1✓ Branch 2 taken 16 times.
|
16 | objectImpl.get()->detail::IdfObject_Impl::onDataChange.connect<IdfObjectWatcher, &IdfObjectWatcher::dataChange>(this); |
| 15 |
1/1✓ Branch 2 taken 16 times.
|
16 | objectImpl.get()->detail::IdfObject_Impl::onNameChange.connect<IdfObjectWatcher, &IdfObjectWatcher::nameChange>(this); |
| 16 | 16 | } | |
| 17 | |||
| 18 | 60721 | bool IdfObjectWatcher::enabled() const { | |
| 19 | 60721 | return m_enabled; | |
| 20 | } | ||
| 21 | |||
| 22 | ✗ | void IdfObjectWatcher::enable() { | |
| 23 | ✗ | m_enabled = true; | |
| 24 | ✗ | } | |
| 25 | |||
| 26 | 2 | bool IdfObjectWatcher::disable() { | |
| 27 | 2 | bool result = m_enabled; | |
| 28 | 2 | m_enabled = false; | |
| 29 | 2 | return result; | |
| 30 | } | ||
| 31 | |||
| 32 | 64 | bool IdfObjectWatcher::dirty() const { | |
| 33 | 64 | return m_dirty; | |
| 34 | } | ||
| 35 | |||
| 36 | 36 | bool IdfObjectWatcher::dataChanged() const { | |
| 37 | 36 | return m_dataChanged; | |
| 38 | } | ||
| 39 | |||
| 40 | 21 | bool IdfObjectWatcher::nameChanged() const { | |
| 41 | 21 | return m_nameChanged; | |
| 42 | } | ||
| 43 | |||
| 44 | 21 | void IdfObjectWatcher::clearState() { | |
| 45 | 21 | bool wasDirty = m_dirty; | |
| 46 | 21 | m_dirty = false; | |
| 47 | 21 | m_dataChanged = false; | |
| 48 | 21 | m_nameChanged = false; | |
| 49 | |||
| 50 |
1/2✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
|
21 | if (enabled()) { |
| 51 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | if (wasDirty) { |
| 52 | 21 | onBecomeClean(); | |
| 53 | } | ||
| 54 | } | ||
| 55 | 21 | } | |
| 56 | |||
| 57 | 15187 | void IdfObjectWatcher::onChangeIdfObject() {} | |
| 58 | |||
| 59 | 15174 | void IdfObjectWatcher::onDataFieldChange() {} | |
| 60 | |||
| 61 | 5 | void IdfObjectWatcher::onNameChange() {} | |
| 62 | |||
| 63 | 25 | void IdfObjectWatcher::onBecomeDirty() {} | |
| 64 | |||
| 65 | 21 | void IdfObjectWatcher::onBecomeClean() {} | |
| 66 | |||
| 67 | 30349 | void IdfObjectWatcher::change() { | |
| 68 | 30349 | bool wasDirty = m_dirty; | |
| 69 | 30349 | m_dirty = true; | |
| 70 | |||
| 71 |
2/2✓ Branch 1 taken 15187 times.
✓ Branch 2 taken 15162 times.
|
30349 | if (enabled()) { |
| 72 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 15162 times.
|
15187 | if (!wasDirty) { |
| 73 | 25 | onBecomeDirty(); | |
| 74 | } | ||
| 75 | 15187 | onChangeIdfObject(); | |
| 76 | } | ||
| 77 | 30349 | } | |
| 78 | |||
| 79 | 30336 | void IdfObjectWatcher::dataChange() { | |
| 80 | 30336 | m_dataChanged = true; | |
| 81 | |||
| 82 |
2/2✓ Branch 1 taken 15174 times.
✓ Branch 2 taken 15162 times.
|
30336 | if (enabled()) { |
| 83 | 15174 | onDataFieldChange(); | |
| 84 | } | ||
| 85 | 30336 | } | |
| 86 | |||
| 87 | 5 | void IdfObjectWatcher::nameChange() { | |
| 88 | 5 | m_nameChanged = true; | |
| 89 | |||
| 90 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | if (enabled()) { |
| 91 | 5 | onNameChange(); | |
| 92 | } | ||
| 93 | 5 | } | |
| 94 | |||
| 95 | } // namespace openstudio | ||
| 96 |