te::common::ApplicationSettings Class Reference

A class for managing application settings. More...

#include <ApplicationSettings.h>

Inheritance diagram for te::common::ApplicationSettings:
te::common::ObjectLevelLockable< ApplicationSettings,::boost::recursive_mutex,::boost::lock_guard< ::boost::recursive_mutex >,::boost::lock_guard< ::boost::recursive_mutex > > te::common::SystemApplicationSettings te::common::UserApplicationSettings

Public Types

typedef ObjectLevelLockingPolicy< ::boost::lock_guard< ::boost::recursive_mutex > > LockRead
 
typedef ObjectLevelLockingPolicy< ::boost::lock_guard< ::boost::recursive_mutex > > LockWrite
 
typedef volatile ApplicationSettings VolatileType
 

Public Member Functions

 ApplicationSettings ()
 Constructor. More...
 
void changed ()
 This method can be used by clients to inform manually that the internal state has changed. More...
 
const boost::property_tree::ptree & getAllSettings () const
 It return a reading reference to the internal settings. More...
 
boost::property_tree::ptree & getAllSettings ()
 It return a reference to the internal settings. More...
 
std::string getValue (const std::string &key)
 It returns the value for a given key or empty. More...
 
void load (const std::string &settingsFile)
 It initializes the application settings. More...
 
void setValue (const std::string &key, const std::string &value)
 It stores the value according to the key. More...
 
void update ()
 It updates the application settings. More...
 
 ~ApplicationSettings ()
 The destructor will automatically save the settings to a file if one is set. More...
 

Protected Attributes

bool m_dirty
 A dirty bit to indicate wheter the clients have made changes in the settings since the last update. More...
 
std::string m_file
 The settings file name. More...
 
boost::property_tree::ptree m_settings
 This will keep our settings in memory. More...
 

Detailed Description

A class for managing application settings.

This class can be used to keep user preferences that customize the application's appearance and behavior. It can also be used to keep settings applied to the system (for all users).

For each setting you must provide an unique name. The rule for setting names are the same as for XML element names: it can be any combination of letters, numbers, or an underscore, they must not start with a number and cannot have white spaces.

Definition at line 66 of file ApplicationSettings.h.

Member Typedef Documentation

typedef ObjectLevelLockingPolicy<::boost::lock_guard< ::boost::recursive_mutex > > te::common::ObjectLevelLockable< ApplicationSettings , ::boost::recursive_mutex , ::boost::lock_guard< ::boost::recursive_mutex > , ::boost::lock_guard< ::boost::recursive_mutex > >::LockRead
inherited

Definition at line 205 of file ThreadingPolicies.h.

typedef ObjectLevelLockingPolicy<::boost::lock_guard< ::boost::recursive_mutex > > te::common::ObjectLevelLockable< ApplicationSettings , ::boost::recursive_mutex , ::boost::lock_guard< ::boost::recursive_mutex > , ::boost::lock_guard< ::boost::recursive_mutex > >::LockWrite
inherited

Definition at line 206 of file ThreadingPolicies.h.

typedef volatile ApplicationSettings te::common::ObjectLevelLockable< ApplicationSettings , ::boost::recursive_mutex , ::boost::lock_guard< ::boost::recursive_mutex > , ::boost::lock_guard< ::boost::recursive_mutex > >::VolatileType
inherited

Definition at line 204 of file ThreadingPolicies.h.

Constructor & Destructor Documentation

te::common::ApplicationSettings::ApplicationSettings ( )
inline

Constructor.

Definition at line 170 of file ApplicationSettings.h.

te::common::ApplicationSettings::~ApplicationSettings ( )
inline

The destructor will automatically save the settings to a file if one is set.

Definition at line 176 of file ApplicationSettings.h.

References update().

Member Function Documentation

void te::common::ApplicationSettings::changed ( )
inline

This method can be used by clients to inform manually that the internal state has changed.

This method is useful when accessing the internal settings structure.

Note
Thread-safe depending on ThreadingPolicy.

Definition at line 237 of file ApplicationSettings.h.

References m_dirty.

const boost::property_tree::ptree & te::common::ApplicationSettings::getAllSettings ( ) const
inline

It return a reading reference to the internal settings.

Returns
A read reference to the internal settings.
Note
Take care when keeping a reference to this property in a multi-thread environment.

Definition at line 244 of file ApplicationSettings.h.

References m_settings.

boost::property_tree::ptree & te::common::ApplicationSettings::getAllSettings ( )
inline

It return a reference to the internal settings.

Returns
A reference to the internal settings.
Note
Depending on the ThreadingPolicy you can synchronize the read/write from/to the settings. The client of this method will be responsible for informing changes. Release any lock before calling the update method or any other thread-safe method if you are not using a recursive mutex in the threading policy.

Definition at line 249 of file ApplicationSettings.h.

References m_settings.

std::string te::common::ApplicationSettings::getValue ( const std::string &  key)
inline

It returns the value for a given key or empty.

Parameters
keyThe key used to identify the searched value.
Returns
The value for a given key or empty.
Note
Thread-safe depending on ThreadingPolicy.

Definition at line 189 of file ApplicationSettings.h.

References m_settings.

void te::common::ApplicationSettings::load ( const std::string &  settingsFile)
inline

It initializes the application settings.

Parameters
settingsFileThe name of the application settings file.
Note
It discards all the settings and doesnt't save changes.
If the informed file doesn't exist application settings will be empty after the excution of this method.
Thread-safe depending on ThreadingPolicy.

Definition at line 203 of file ApplicationSettings.h.

References m_dirty, m_file, and m_settings.

void te::common::ApplicationSettings::setValue ( const std::string &  key,
const std::string &  value 
)
inline

It stores the value according to the key.

Parameters
keyThe key used to identify the given value. The key must follow the same rules as XML elements and they can be subclassified using a dot notation: setValue(key.subkey.subsubkey, value).
valueThe value to be stored, any valid string.
Note
If you want to store a binary value you can encode it as an hex-string.
Thread-safe depending on ThreadingPolicy.

Definition at line 181 of file ApplicationSettings.h.

References m_dirty, and m_settings.

void te::common::ApplicationSettings::update ( )
inline

It updates the application settings.

Note
This function is called automatically from ApplicationSettings's destructor.
If application settings is empty it discards the config file.
Thread-safe depending on ThreadingPolicy.

Definition at line 215 of file ApplicationSettings.h.

References m_dirty, m_file, and m_settings.

Referenced by ~ApplicationSettings().

Member Data Documentation

bool te::common::ApplicationSettings::m_dirty
protected

A dirty bit to indicate wheter the clients have made changes in the settings since the last update.

Definition at line 167 of file ApplicationSettings.h.

Referenced by changed(), load(), setValue(), and update().

std::string te::common::ApplicationSettings::m_file
protected

The settings file name.

Definition at line 166 of file ApplicationSettings.h.

Referenced by load(), and update().

boost::property_tree::ptree te::common::ApplicationSettings::m_settings
protected

This will keep our settings in memory.

Definition at line 165 of file ApplicationSettings.h.

Referenced by getAllSettings(), getValue(), load(), setValue(), and update().


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