ConfigDatabase

A Singleton class that handles configuration options for the application.  All configuration options are stored in an OS-specific format, handled transparently by wxWidgets.  ConfigDatabase is a layer on top of wxWidgets that stores retrieved options in a local cache so that the OS is only pinged for previously unqueried values or when a configuration option changes.

Derived From

Singleton

Project

DatabaseCore

Include

ConfigDatabase.h

Summary
A Singleton class that handles configuration options for the application.
Reads a configuration option from the cache or OS.
Writes a configuration option to the cache and OS.
The ConfigDatabase constructor.
Reads a configuration key from the OS.
Writes a configuration key to the OS.
The hash of configuration options.

Public

Summary
Reads a configuration option from the cache or OS.
Writes a configuration option to the cache and OS.

Functions

read

template <typename T> T read(const wxString &section, 
const wxString &option, 
defaultValue = T())

Reads a configuration option from the cache or OS.  The cache is first checked for the option.  If it does not exist, the OS is checked for the option.  If it does not exist there, the default value is returned.  Only integer, float, and wxString values can be returned as configuration options.

Parameters

sectionThe configuration section to search.
optionThe configuration option to look for.
defaultValueA default value for the option if it does not exist in the OS repository.

Returns

The value of the configuration option.

write

template <typename T> void write(const wxString &section,
const wxString &option,
value)

Writes a configuration option to the cache and OS.  The write happens immediately.  Only integer, float, and wxString values can be written as configuration options.

Parameters

sectionThe configuration section to write to.
optionThe configuration option to write.
valueThe value of the configuration option.

Private

Summary
The ConfigDatabase constructor.
Reads a configuration key from the OS.
Writes a configuration key to the OS.
The hash of configuration options.

Constructors

ConfigDatabase

ConfigDatabase()

The ConfigDatabase constructor.  Eeven though this constructor does nothing, it still needs to exist and be instantiated in ConfigDatabase.cpp or else there is nothing to link to in the .DLL for the ConfigDatabase class and external link errors will result in other modules.

Functions

readPrivate

template <typename T> readPrivate(const wxString &key, 
&val, 
defaultValue = T()) const

Reads a configuration key from the OS.

Parameters

keyThe key path to search in the OS repository.
defaultValueThe default value if the key does not exist.  Returns: The value of the the configuration option.

writePrivate

template <typename T> void writePrivate(const wxString &key,
value)

Writes a configuration key to the OS.

Parameters

keyThe key path to write to in the OS repository.
valueThe value of the configuration option.

Variables

mCache

StringHash mCache

The hash of configuration options.

template <typename T> T read(const wxString &section, 
const wxString &option, 
defaultValue = T())
Reads a configuration option from the cache or OS.
template <typename T> void write(const wxString &section,
const wxString &option,
value)
Writes a configuration option to the cache and OS.
ConfigDatabase()
The ConfigDatabase constructor.
template <typename T> readPrivate(const wxString &key, 
&val, 
defaultValue = T()) const
Reads a configuration key from the OS.
template <typename T> void writePrivate(const wxString &key,
value)
Writes a configuration key to the OS.
StringHash mCache
The hash of configuration options.
A template class that provides an implementation of the Singleton pattern.
DatabaseCore provides a set of commonly used Singletons and namespaces that handle important, but mundane aspects of game management, such as available player colors, configuration options, image maniplulation, file paths, and playing sounds.