Ion
|
Base class for Setting, which encapsulates the name of the setting and any functors that should be called via NotifyListeners(). More...
#include "setting.h"
Classes | |
struct | ListenerInfo |
Public Types | |
typedef std::function< void(SettingBase *setting)> | Listener |
A function that is called when the value changes. More... | |
Public Member Functions | |
const std::string & | GetName () const |
Returns the name associated with this. More... | |
const std::string & | GetDocString () const |
Returns the documentation string associated with this. More... | |
void | SetTypeDescriptor (const std::string &desc) |
Sets/returns a string containing information about the Setting's type. More... | |
const std::string & | GetTypeDescriptor () const |
void | RegisterListener (const std::string &key, const Listener &listener) |
Adds a function that will be called when this setting's value changes. More... | |
void | EnableListener (const std::string &key, bool enable) |
Enables or disables the listener identified by key, if one exists. More... | |
void | UnregisterListener (const std::string &key) |
Removes the listener identified by key, if one exists. More... | |
void | NotifyListeners () |
Notify listeners that this setting has changed. More... | |
virtual const std::string | ToString () const =0 |
Returns a string version of this setting. More... | |
virtual bool | FromString (const std::string &str)=0 |
Parses the passed string to set the value of this and returns whether the parsing was successful. More... | |
Protected Member Functions | |
SettingBase (const std::string &name, const std::string &doc_string) | |
The constructor and destructor are protected because this is an abstract base class. More... | |
virtual | ~SettingBase () |
Friends | |
class | SettingManager |
Holds on to a reference to SettingData. More... | |
Base class for Setting, which encapsulates the name of the setting and any functors that should be called via NotifyListeners().
The name represents both the name of the Setting as well as the groups it belongs to. For example the Setting with the name "Ion/RenderOptions/CacheUniforms" belongs to the "Ion" and "RenderOptions" groups. See SettingManager for how to listen for changes to groups.
typedef std::function<void(SettingBase* setting)> ion::base::SettingBase::Listener |
|
protected |
The constructor and destructor are protected because this is an abstract base class.
Definition at line 25 of file setting.cc.
References ion::base::SettingManager::RegisterSetting().
|
protectedvirtual |
Definition at line 31 of file setting.cc.
References ion::base::SettingManager::UnregisterSetting().
void ion::base::SettingBase::EnableListener | ( | const std::string & | key, |
bool | enable | ||
) |
Enables or disables the listener identified by key, if one exists.
Definition at line 40 of file setting.cc.
|
pure virtual |
Parses the passed string to set the value of this and returns whether the parsing was successful.
If the parsing does not succeed then nothing should change in this.
Implemented in ion::base::Setting< std::atomic< T > >, ion::base::Setting< T >, and ion::base::Setting< bool >.
|
inline |
|
inline |
|
inline |
void ion::base::SettingBase::NotifyListeners | ( | ) |
Notify listeners that this setting has changed.
Definition at line 50 of file setting.cc.
Referenced by ion::base::Setting< bool >::operator=(), ion::base::Setting< std::atomic< T > >::operator=(), ion::base::Setting< bool >::SetValue(), and ion::base::Setting< std::atomic< T > >::SetValue().
void ion::base::SettingBase::RegisterListener | ( | const std::string & | key, |
const Listener & | listener | ||
) |
Adds a function that will be called when this setting's value changes.
The function is identified by the passed key. The same key must be used to remove the listener.
Definition at line 35 of file setting.cc.
|
inline |
Sets/returns a string containing information about the Setting's type.
This string can be used, for example, in an interactive program to present a specialized interface for displaying or modifying the settings. See the remote::SettingHandler documentation for examples.
Definition at line 65 of file setting.h.
Referenced by ion::base::SetTypeDescriptorForType().
|
pure virtual |
Returns a string version of this setting.
The same string may be passed to FromString to reconstruct an identical setting.
Implemented in ion::base::Setting< std::atomic< T > >, ion::base::Setting< T >, and ion::base::Setting< bool >.
void ion::base::SettingBase::UnregisterListener | ( | const std::string & | key | ) |
Removes the listener identified by key, if one exists.
Definition at line 46 of file setting.cc.
|
friend |