/ src / modules / LightSwitch / LightSwitchService / SettingsObserver.h
SettingsObserver.h
 1  #pragma once
 2  
 3  #include <unordered_set>
 4  #include "SettingsConstants.h"
 5  #include "LightSwitchSettings.h"
 6  
 7  class LightSwitchSettings;
 8  
 9  class SettingsObserver
10  {
11  public:
12      SettingsObserver(std::unordered_set<SettingId> observedSettings) :
13          m_observedSettings(std::move(observedSettings))
14      {
15          LightSwitchSettings::instance().AddObserver(*this);
16      }
17  
18      virtual ~SettingsObserver()
19      {
20          LightSwitchSettings::instance().RemoveObserver(*this);
21      }
22  
23      // Override this in your class to respond to updates
24      virtual void SettingsUpdate(SettingId type) {}
25  
26      virtual bool WantsToBeNotified(SettingId type) const noexcept
27      {
28          return m_observedSettings.contains(type);
29      }
30  
31  protected:
32      std::unordered_set<SettingId> m_observedSettings;
33  };