Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::base::SettingBase Class Referenceabstract

Base class for Setting, which encapsulates the name of the setting and any functors that should be called via NotifyListeners(). More...

#include "setting.h"

Inheritance diagram for ion::base::SettingBase:

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...
 

Detailed Description

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.

Definition at line 43 of file setting.h.

Member Typedef Documentation

typedef std::function<void(SettingBase* setting)> ion::base::SettingBase::Listener

A function that is called when the value changes.

Definition at line 46 of file setting.h.

Constructor & Destructor Documentation

ion::base::SettingBase::SettingBase ( const std::string &  name,
const std::string &  doc_string 
)
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().

ion::base::SettingBase::~SettingBase ( )
protectedvirtual

Definition at line 31 of file setting.cc.

References ion::base::SettingManager::UnregisterSetting().

Member Function Documentation

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.

virtual bool ion::base::SettingBase::FromString ( const std::string &  str)
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 >.

const std::string& ion::base::SettingBase::GetDocString ( ) const
inline

Returns the documentation string associated with this.

Definition at line 59 of file setting.h.

const std::string& ion::base::SettingBase::GetName ( ) const
inline

Returns the name associated with this.

Definition at line 56 of file setting.h.

const std::string& ion::base::SettingBase::GetTypeDescriptor ( ) const
inline

Definition at line 66 of file setting.h.

void ion::base::SettingBase::NotifyListeners ( )
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.

void ion::base::SettingBase::SetTypeDescriptor ( const std::string &  desc)
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().

virtual const std::string ion::base::SettingBase::ToString ( ) const
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.

Friends And Related Function Documentation

friend class SettingManager
friend

Holds on to a reference to SettingData.

We don't need to access it directly through this pointer, just keep it alive.

Definition at line 104 of file setting.h.


The documentation for this class was generated from the following files: