Relacs  0.9.8
Public Member Functions | Protected Member Functions | Friends | List of all members
ConfigureClasses Class Reference

#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)
 

Detailed Description

Coordinates storage of configuration settings of ConfigClass instances.

Author
Jan Benda

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:

c.addConfigFile( "/etc/myprog.cfg" );
c.addConfigFile( "/home/me/.myprog.cfg" );
c.addConfigFile( "myprog.cfg" );

The name of a configuration file of a given configuration group and level is returned by configFile().

Constructor & Destructor Documentation

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.

Parameters
[in]groupsthe 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() ).

Parameters
[in]filethe 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().

Member Function Documentation

int groups ( void  ) const
Returns
the number of different groups of configuration files.
See Also
addGroup()
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.

Parameters
[in]filesnames (full pathes) of the configuration files for the added group separated by '|'. If left empty, then no filename is assigned to the group.
See Also
groups(), addConfigFile()

References ConfigureClasses::setConfigFiles().

Referenced by RELACSWidget::RELACSWidget().

void clearGroups ( void  )

Clear all configuration groups and all levels of configuration files they contain.

See Also
clearConfigFiles(), addGroup()

References ConfigureClasses::clearConfigFiles().

Referenced by RELACSWidget::RELACSWidget().

string configFile ( int  group = 0,
int  level = 0 
) const
Returns
the name (full path) of the configuration file for configuration group group and level level or an empty string if group or level are invalid.
Parameters
[in]groupthe configuration group index of the requested configuration file.
[in]levelthe level of the requested configuration file.
See Also
setConfigFile(), setConfigFiles(), addConfigFile(), addConfigFiles(), clearConfigFiles()
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().

Parameters
[in]filethe name (full path) of the configuration file.
[in]groupthe index of the configuration group.
[in]levelthe level index.
See Also
configFile(), setConfigFiles(), addConfigFile(), addConfigFiles(), clearConfigFiles()
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().

Parameters
[in]filesthe names (full pathes) of the configuration files separated by '|'.
[in]groupthe index of the configuration group.
See Also
configFile(), setConfigFile(), addConfigFile(), addConfigFiles(), clearConfigFiles()

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

Parameters
[in]filethe name (full path) of the configuration file.
[in]groupthe configuration group index.
See Also
addGroup(), configFile(), setConfigFile(), setConfigFiles(), addConfigFiles(), clearConfigFiles()

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

Parameters
[in]filesthe names (full pathes) of the configuration files separated by '|'.
[in]groupthe index of the configuration group.
See Also
addGroup(), configFile(), setConfigFile(), setConfigFiles(), addConfigFile(), clearConfigFiles()

References StrQueue::size(), and StrQueue::strip().

void clearConfigFiles ( int  group)

Clear all levels of configuration files of the configuration group with index group.

Parameters
[in]groupthe configuration group index.
See Also
clearGroups(), configFile(), setConfigFile(), setConfigFiles(), addConfigFile(), addConfigFiles()
void clearConfigFiles ( void  )

Clear all levels of configuration files of all configuration groups. The groups are not erased, this is done by clearGroups().

See Also
configFile(), setConfigFile(), setConfigFiles(), addConfigFile(), addConfigFiles()

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

Parameters
[in]groupthe configuration group index.
[in]filethe file from which the configuration is read in.
Returns
the number of read in configuration files (0 or 1).
See Also
read( int, int), save(), configure()

References Str::empty(), relacs::line(), StrQueue::load(), StrQueue::strip(), Str::strip(), and Str::substr().

Referenced by ConfigClass::readConfig(), RELACSWidget::RELACSWidget(), RELACSWidget::startFirstAcquisition(), and RELACSWidget::startIdle().

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

Parameters
[in]groupthe configuration group index of the requested configuration file.
[in]levelthe level of the requested configuration file.
Returns
the number of read in configuration files (0 or 1).
See Also
read( int, ConfigClass&), save(), configure()

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.

Parameters
[in]groupthe configuration group index of the requested configuration files.
Returns
the number of read in configuration files.
See Also
read( ConfigClass&), save(), configure()

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.

Returns
the number of read in configuration files.
See Also
save(), configure()

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

Parameters
[in]levelthe level of the requested configuration file.
[in]configthe ConfigClass instance for which the configuration settings should be read in.
Returns
the number of read in configuration files (0 or 1).
See Also
read( int, int ), save(), configure()

References ConfigClass::configGroup(), ConfigClass::configIdent(), Str::empty(), relacs::line(), 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.

Parameters
[in]configthe ConfigClass instance for which the configuration settings should be read in.
Returns
the number of read in configuration files.
See Also
read( int ), save(), configure()

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.

Note
This function should be called before reading the configuration files.
Parameters
[in]groupthe configuration group index.
[in]identthe configuration identifier specifying a ConfigClass instance.
See Also
configure(), read(), save()

Referenced by RELACSWidget::startFirstAcquisition(), and RELACSWidget::startIdle().

void preConfigure ( int  group)

Pre-configure, i.e. call ConfigClass::preConfig() of all the ConfigClass instances from the configuration group with index group.

Note
This function should be called before reading the configuration files.
Parameters
[in]groupthe configuration group index.
See Also
configure(), read(), save()
void preConfigure ( void  )

Pre-configure, i.e. call ConfigClass::preConfig() of all ConfigClass instances.

Note
This function should be called before reading the configuration files.
See Also
configure(), read(), save()
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.

Note
This function should be called only after all configuration files have been read in.
Parameters
[in]groupthe configuration group index.
[in]identthe configuration identifier specifying a ConfigClass instance.
See Also
preConfigure(), read(), save()

Referenced by RELACSWidget::RELACSWidget(), RELACSWidget::startFirstAcquisition(), and RELACSWidget::startIdle().

void configure ( int  group)

Configure, i.e. call ConfigClass::config() of all the ConfigClass instances from the configuration group with index group.

Note
This function should be called only after all configuration files have been read in.
Parameters
[in]groupthe configuration group index.
See Also
preConfigure(), read(), save()
void configure ( void  )

Configure, i.e. call ConfigClass::config() of all ConfigClass instances.

Note
This function should be called only after all configuration files have been read in.
See Also
preConfigure(), read(), save()
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.

Parameters
[in]groupthe configuration group index.
[in]filethe name (full path) of the file.
See Also
setSaveStyle(), read(), configure()

References ConfigClass::Save.

Referenced by RELACSWidget::clearActivity(), RELACSWidget::saveConfig(), and RELACSWidget::startSession().

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.

Parameters
[in]groupthe configuration group index.
[in]levelthe level of the requested configuration file.
See Also
setSaveStyle(), read(), configure()

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.

Parameters
[in]groupthe configuration group index.
See Also
setSaveStyle(), read(), configure()

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.

See Also
setSaveStyle(), read(), configure()

Referenced by ConfigureClasses::save().

void setSaveStyle ( int  flags)

Set the way how the configuration is saved for the default implementation of ConfigClass::saveConfig().

Parameters
[in]flagsa combination of flags for the Options::save() function from Options.
See Also
save()
void addConfigClass ( ConfigClass cfg)
protected

Adds a class that wants to be configured to the list of classes.

Parameters
[in]cfga pointer to the configureable class.

Referenced by ConfigClass::addConfig().

void eraseConfigClass ( ConfigClass cfg)
protected

Removes a class from the list of classes.

Parameters
[in]cfga pointer to the configureable class.

Referenced by ConfigClass::~ConfigClass().

Friends And Related Function Documentation

friend class ConfigClass
friend
ostream& operator<< ( ostream &  str,
const ConfigureClasses c 
)
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 ','.

Parameters
[in]strthe output stream.
[in]cthe ConfigureClasses instance.

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