Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
setting.cc
Go to the documentation of this file.
1 
18 #include "ion/base/setting.h"
19 
21 
22 namespace ion {
23 namespace base {
24 
25 SettingBase::SettingBase(const std::string& name, const std::string& doc_string)
26  : name_(name), doc_string_(doc_string) {
29 }
30 
33 }
34 
35 void SettingBase::RegisterListener(const std::string& key,
36  const Listener& listener) {
37  listeners_[key] = ListenerInfo(listener, true);
38 }
39 
40 void SettingBase::EnableListener(const std::string& key, bool enable) {
41  ListenerMap::iterator it = listeners_.find(key);
42  if (it != listeners_.end())
43  it->second.enabled = enable;
44 }
45 
46 void SettingBase::UnregisterListener(const std::string& key) {
47  listeners_.erase(key);
48 }
49 
51  for (ListenerMap::const_iterator it = listeners_.begin();
52  it != listeners_.end(); ++it) {
53  if (it->second.enabled)
54  it->second.listener(this);
55  }
56 }
57 
58 } // namespace base
59 } // namespace ion
void NotifyListeners()
Notify listeners that this setting has changed.
Definition: setting.cc:50
void RegisterListener(const std::string &key, const Listener &listener)
Adds a function that will be called when this setting's value changes.
Definition: setting.cc:35
void UnregisterListener(const std::string &key)
Removes the listener identified by key, if one exists.
Definition: setting.cc:46
virtual ~SettingBase()
Definition: setting.cc:31
static void RegisterSetting(SettingBase *setting)
Adds the setting to the manager and its groups.
std::string name
Definition: printer.cc:324
void EnableListener(const std::string &key, bool enable)
Enables or disables the listener identified by key, if one exists.
Definition: setting.cc:40
std::function< void(SettingBase *setting)> Listener
A function that is called when the value changes.
Definition: setting.h:46
SettingBase(const std::string &name, const std::string &doc_string)
The constructor and destructor are protected because this is an abstract base class.
Definition: setting.cc:25
static void UnregisterSetting(SettingBase *setting)
Removes the setting from the manager and its groups.