Relacs Options Library
0.9.8
|
#include <configureclasses.h>
Public Member Functions | |
ConfigureClasses (void) | |
ConfigureClasses (int groups) | |
ConfigureClasses (const string &file) | |
~ConfigureClasses (void) | |
int | groups (void) const |
void | addGroup (const string &files="") |
void | clearGroups (void) |
string | configFile (int group=0, int level=0) const |
void | setConfigFile (const string &file, int group=0, int level=0) |
void | setConfigFiles (const string &files, int group=0) |
void | addConfigFile (const string &file, int group=0) |
void | addConfigFiles (const string &files, int group=0) |
void | clearConfigFiles (int group) |
void | clearConfigFiles (void) |
int | read (int group, const string &file) |
int | read (int group, int level) |
int | read (int group) |
int | read (void) |
int | read (int level, ConfigClass &config) |
int | read (ConfigClass &config) |
void | preConfigure (int group, const string &ident) |
void | preConfigure (int group) |
void | preConfigure (void) |
void | configure (int group, const string &ident) |
void | configure (int group) |
void | configure (void) |
void | save (int group, const string &file) |
void | save (int group, int level) |
void | save (int group) |
void | save (void) |
void | setSaveStyle (int flags) |
Protected Member Functions | |
void | addConfigClass (ConfigClass *cfg) |
void | eraseConfigClass (ConfigClass *cfg) |
Friends | |
class | ConfigClass |
ostream & | operator<< (ostream &str, const ConfigureClasses &c) |
Coordinates storage of configuration settings of ConfigClass instances.
ConfigureClasses stores a pointer to each instance of a ConfigClass. The configuration of each ConfigClass instance can be read in from configuration files by the read() functions and saved by the save() functions. The configure() functions call the config() function of the ConfigClass instances for some post-configuration, and the preConfigure() functions call the preConfig() function of the ConfigClass instances for some pre-configuration before the configuration files are read in.
ConfigClass instances are organized in configurations groups via their ConfigClass::configGroup() flag. The configuration groups are indexed starting with 0. Each configuration group gets its own set of configuration files. Configuration groups can be added with addGroup(), cleared with clearGroups(), and the number of defined groups is returned by groups().
To each configuration group several configuration files of increasing level can be added by addConfigFile(), set by setConfigFile(), and cleared by clearConfigFiles(). The read() functions read in the configuration files with increasing level, such that configuration files of higher levels may overwrite the settings specified by the configuration files of lower levels.
For example, if your program should first read in a system wide configuration file in /etc/myprog
.cfg, then a personal configuration file in /home/me/
.myprog.cfg, and finally a configuration file myprog.cfg
in the current working directory, then you would specify three levels of configuration files in the following order:
The name of a configuration file of a given configuration group and level is returned by configFile().
ConfigureClasses | ( | void | ) |
Constructs a ConfigureClasses with a single but empty (no configuration files) group of configuration files and makes itself and the list of configureable classes known to the ConfigClass (ConfigClass::setConfigureClasses() and ConfigClass::setConfigClassList() ). You need to add configuration files to the group by calling addConfigFile(). You can add further configuration groups by calling addGroup().
References ConfigClass::setConfigureClasses().
ConfigureClasses | ( | int | groups | ) |
Constructs an empty ConfigureClasses (no configuration files) that is set up for groups of configuration files and makes itself and the list of configureable classes known to the ConfigClass (ConfigClass::setConfigureClasses() and ConfigClass::setConfigClassList() ). You then can specify configuration file names by calling addConfigFile( const string&, int) for each of the groups at least once.
[in] | groups | the number of groups of configuration files to be used. |
References ConfigClass::setConfigureClasses().
ConfigureClasses | ( | const string & | file | ) |
Constructs an ConfigureClasses with a single configuration file file (in one configuration group) and makes itself and the list of configureable classes known to the ConfigClass (ConfigClass::setConfigureClasses() and ConfigClass::setConfigClassList() ).
[in] | file | the name of the configuration file to be used. |
References ConfigureClasses::addConfigFile(), and ConfigClass::setConfigureClasses().
~ConfigureClasses | ( | void | ) |
Destructs ConfigureClasses and removes itself and the list of configureable classes from ConfigClass.
References ConfigClass::setConfigureClasses().
int groups | ( | void | ) | const |
void addGroup | ( | const string & | files = "" | ) |
Adds a new group of configuration files and optionally initializes the new configuration group with the configuration file names given in files.
[in] | files | names (full pathes) of the configuration files for the added group separated by '|'. If left empty, then no filename is assigned to the group. |
References ConfigureClasses::setConfigFiles().
void clearGroups | ( | void | ) |
Clear all configuration groups and all levels of configuration files they contain.
References ConfigureClasses::clearConfigFiles().
string configFile | ( | int | group = 0 , |
int | level = 0 |
||
) | const |
[in] | group | the configuration group index of the requested configuration file. |
[in] | level | the level of the requested configuration file. |
void setConfigFile | ( | const string & | file, |
int | group = 0 , |
||
int | level = 0 |
||
) |
Set the name (full path) of the configuration file of group group for level level to file. Configuration files of level 0 are read in first. Thus, configuration files of higher levels may overwrite the settings specified by the configuration files of lower levels. If the configuration group index or level do not exist or file is an empty string, this function has no effect. The configuration group must have been created before via the constructor or addGroup(). The level must have been created before by addConfigFile().
[in] | file | the name (full path) of the configuration file. |
[in] | group | the index of the configuration group. |
[in] | level | the level index. |
void setConfigFiles | ( | const string & | files, |
int | group = 0 |
||
) |
Set the names (full pathes) of the configuration files of group group according to files. If the configuration group index does not exist this function has no effect. The configuration group must have been created before via the constructor or addGroup().
[in] | files | the names (full pathes) of the configuration files separated by '|'. |
[in] | group | the index of the configuration group. |
References StrQueue::size(), and StrQueue::strip().
Referenced by ConfigureClasses::addGroup().
void addConfigFile | ( | const string & | file, |
int | group = 0 |
||
) |
Add a new level to the configuration group group and set the name of the corresponding configuration file to file. This configuration file is read in after the previously added configuration files of the same group and might therefore overwrite their settings. If the configuration group index does not exist or file is an empty string, this function has no effect. The configuration group must have been created before via the constructor or addGroup().
[in] | file | the name (full path) of the configuration file. |
[in] | group | the configuration group index. |
Referenced by ConfigureClasses::ConfigureClasses().
void addConfigFiles | ( | const string & | files, |
int | group = 0 |
||
) |
Add the names (full pathes) of the configuration files of group group according to files. If the configuration group index does not exist this function has no effect. The configuration group must have been created before via the constructor or addGroup().
[in] | files | the names (full pathes) of the configuration files separated by '|'. |
[in] | group | the index of the configuration group. |
References StrQueue::size(), and StrQueue::strip().
void clearConfigFiles | ( | int | group | ) |
Clear all levels of configuration files of the configuration group with index group.
[in] | group | the configuration group index. |
void clearConfigFiles | ( | void | ) |
Clear all levels of configuration files of all configuration groups. The groups are not erased, this is done by clearGroups().
Referenced by ConfigureClasses::clearGroups().
int read | ( | int | group, |
const string & | file | ||
) |
Read in the configuration of the configuration group with index group from file file and pass each section to the corresponding ConfigClass instances via ConfigClass::readConfig().
[in] | group | the configuration group index. |
[in] | file | the file from which the configuration is read in. |
References Str::empty(), StrQueue::load(), StrQueue::strip(), Str::strip(), and Str::substr().
Referenced by ConfigClass::readConfig().
int read | ( | int | group, |
int | level | ||
) |
Read in the configuration file of the configuration group with index group and the level level and pass each section to the corresponding ConfigClass instances via ConfigClass::readConfig().
[in] | group | the configuration group index of the requested configuration file. |
[in] | level | the level of the requested configuration file. |
References ConfigureClasses::read().
int read | ( | int | group | ) |
Read in the configuration files of all levels of the configuration group with index group and pass each section to the corresponding ConfigClass instances via ConfigClass::readConfig(). Configuration files of level 0 are read in first. Thus, configuration files of higher levels may overwrite the settings specified by the configuration files of lower levels.
[in] | group | the configuration group index of the requested configuration files. |
References ConfigureClasses::read().
int read | ( | void | ) |
Read in the configuration files of all configuration groups and all levels and pass each section to the corresponding ConfigClass instances via ConfigClass::readConfig(). Configuration files of level 0 are read in first. Thus, configuration files of higher levels may overwrite the settings specified by the configuration files of lower levels.
Referenced by ConfigureClasses::read().
int read | ( | int | level, |
ConfigClass & | config | ||
) |
Read in the configuration file of the configuration group as specified by config.configGroup() and the level level. Pass the section for config to config via ConfigClass::readConfig().
[in] | level | the level of the requested configuration file. |
[in] | config | the ConfigClass instance for which the configuration settings should be read in. |
References ConfigClass::configGroup(), ConfigClass::configIdent(), Str::empty(), StrQueue::load(), ConfigClass::readConfig(), StrQueue::strip(), Str::strip(), and Str::substr().
int read | ( | ConfigClass & | config | ) |
Read in the configuration files of the configuration group as specified by config.configGroup() and all levels. Pass the sections for config to config via ConfigClass::readConfig(). Configuration files of level 0 are read in first. Thus, configuration files of higher levels may overwrite the settings specified by the configuration files of lower levels.
[in] | config | the ConfigClass instance for which the configuration settings should be read in. |
References ConfigClass::configGroup(), and ConfigureClasses::read().
void preConfigure | ( | int | group, |
const string & | ident | ||
) |
Pre-configure, i.e. call ConfigClass::preConfig() of the ConfigClass instance from the configuration group with index group and identifier (ConfigClass::configIdent()) matching ident.
[in] | group | the configuration group index. |
[in] | ident | the configuration identifier specifying a ConfigClass instance. |
void preConfigure | ( | int | group | ) |
Pre-configure, i.e. call ConfigClass::preConfig() of all the ConfigClass instances from the configuration group with index group.
[in] | group | the configuration group index. |
void preConfigure | ( | void | ) |
Pre-configure, i.e. call ConfigClass::preConfig() of all ConfigClass instances.
void configure | ( | int | group, |
const string & | ident | ||
) |
Configure, i.e. call ConfigClass::config() of the ConfigClass instance from the configuration group with index group and identifier (ConfigClass::configIdent()) matching ident.
[in] | group | the configuration group index. |
[in] | ident | the configuration identifier specifying a ConfigClass instance. |
void configure | ( | int | group | ) |
Configure, i.e. call ConfigClass::config() of all the ConfigClass instances from the configuration group with index group.
[in] | group | the configuration group index. |
void configure | ( | void | ) |
Configure, i.e. call ConfigClass::config() of all ConfigClass instances.
void save | ( | int | group, |
const string & | file | ||
) |
Save the configuration of all ConfigClass instances of the configuration group with index group to the file file by calling ConfigClass::saveConfig(). Only the settings of those ConfigClass instances are saved that have the ConfigClass::Save flag in their ConfigClass::configMode() set.
[in] | group | the configuration group index. |
[in] | file | the name (full path) of the file. |
References ConfigClass::Save.
void save | ( | int | group, |
int | level | ||
) |
Save the configuration of all ConfigClass instances of the configuration group with index group to the configuration file from level level by calling ConfigClass::saveConfig(). Only the settings of those ConfigClass instances are saved that have the ConfigClass::Save flag in their ConfigClass::configMode() set.
[in] | group | the configuration group index. |
[in] | level | the level of the requested configuration file. |
References ConfigureClasses::save().
void save | ( | int | group | ) |
Save the configuration of all ConfigClass instances of the configuration group with index group to the respective top-level configuration file by calling ConfigClass::saveConfig(). Only the settings of those ConfigClass instances are saved that have the ConfigClass::Save flag in their ConfigClass::configMode() set.
[in] | group | the configuration group index. |
References ConfigureClasses::save().
void save | ( | void | ) |
Save the configuration of all ConfigClass instances to the respective top-level configuration file of each configuration group by calling ConfigClass::saveConfig(). Only the settings of those ConfigClass instances are saved that have the ConfigClass::Save flag in their ConfigClass::configMode() set.
Referenced by ConfigureClasses::save().
void setSaveStyle | ( | int | flags | ) |
Set the way how the configuration is saved for the default implementation of ConfigClass::saveConfig().
[in] | flags | a combination of flags for the Options::save() function from Options. |
|
protected |
Adds a class that wants to be configured to the list of classes.
[in] | cfg | a pointer to the configureable class. |
Referenced by ConfigClass::addConfig().
|
protected |
Removes a class from the list of classes.
[in] | cfg | a pointer to the configureable class. |
Referenced by ConfigClass::~ConfigClass().
|
friend |
|
friend |
Write the names of all configuration files to str. The file names of each configuration group are written in a single line, levels are separated by ','.
[in] | str | the output stream. |
[in] | c | the ConfigureClasses instance. |