COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | List of all members
covise::coConfig Class Reference

#include <coConfig.h>

Collaboration diagram for covise::coConfig:
Collaboration graph
[legend]

Public Types

enum  DebugLevel { DebugOff = 0x00, DebugGetSets = 0x01, DebugAll = 0xFF }
 

Public Member Functions

coConfigEntryStringList getScopeList (const QString &section=0, const QString &variableName=0) const
 
coConfigEntryStringList getVariableList (const QString &section=0) const
 
coConfigEntryString getValue (const QString &variable, const QString &section, const QString &defaultValue) const
 
coConfigEntryString getValue (const QString &variable, const QString &section) const
 
coConfigEntryString getValue (const QString &simpleVariable) const
 
const char * getEntry (const char *simpleVariable) const
 
coConfigFloat getFloat (const QString &variable, const QString &section, float defaultValue) const
 Get a float value. More...
 
coConfigFloat getFloat (const QString &simpleVariable, float defaultValue) const
 Get a float value. More...
 
coConfigFloat getFloat (const QString &variable, const QString &section) const
 Get a float value. More...
 
coConfigFloat getFloat (const QString &simpleVariable) const
 Get a float value. More...
 
coConfigInt getInt (const QString &variable, const QString &section, int defaultValue) const
 
coConfigInt getInt (const QString &simpleVariable, int defaultValue) const
 
coConfigInt getInt (const QString &variable, const QString &section) const
 
coConfigInt getInt (const QString &simpleVariable) const
 
coConfigLong getLong (const QString &variable, const QString &section, long defaultValue) const
 
coConfigLong getLong (const QString &simpleVariable, long defaultValue) const
 
coConfigLong getLong (const QString &variable, const QString &section) const
 
coConfigLong getLong (const QString &simpleVariable) const
 
coConfigBool getBool (const QString &variable, const QString &section, bool defaultValue) const
 
coConfigBool getBool (const QString &simpleVariable, bool defaultValue) const
 
coConfigBool getBool (const QString &variable, const QString &section) const
 
coConfigBool getBool (const QString &variable, const char *section) const
 
coConfigBool getBool (const QString &simpleVariable) const
 
coConfigString getString (const QString &variable, const QString &section, const QString &defaultValue) const
 
coConfigString getString (const QString &simpleVariable) const
 
bool isOn (const QString &variable, const QString &section, bool defaultValue) const
 Checks if a variable in the configuration is set to "on". More...
 
bool isOn (const QString &variable, const QString &section) const
 Checks if a variable in the configuration is set to "on". More...
 
bool isOn (const QString &variable, const char *section) const
 
bool isOn (const QString &simpleVariable, bool defaultValue) const
 Checks if a variable in the configuration is set to "on". More...
 
bool isOn (const QString &simpleVariable) const
 Checks if a variable in the configuration is set to "on". More...
 
void setValueForHost (const QString &variable, const QString &value, const QString &section, const QString &targetHost, bool move=false, const QString &config=0, const QString &configGroup=0)
 Set a value for a variable for a host. More...
 
void setValueInConfig (const QString &variable, const QString &value, const QString &section, const QString &configGroup, const QString &config="config", bool move=false)
 Set a value for a variable in the designated config group. More...
 
void setValue (const QString &variable, const QString &value, const QString &section, const QString &config=0, bool move=false)
 Set a value for a variable. More...
 
void setValue (const QString &simpleVariable, const QString &value)
 Set a value for a simple variable in the default configuration. More...
 
bool deleteValueForHost (const QString &variable, const QString &section, const QString &targetHost, const QString &config=0, const QString &configGroup=0)
 Delete a value in the designated configuration group for a host only. More...
 
bool deleteValueInConfig (const QString &variable, const QString &section, const QString &configGroup, const QString &config="config")
 Delete a value in the designated configuration group. More...
 
bool deleteValue (const QString &variable, const QString &section, const QString &config=0)
 Delete a value from the configuration. More...
 
bool deleteValue (const QString &simpleVariable)
 Delete a value from the configuration. More...
 
bool deleteSectionForHost (const QString &section, const QString &targetHost, const QString &config=0, const QString &configGroup=0)
 Delete a section for a host in the configuration. More...
 
bool deleteSectionInConfig (const QString &section, const QString &configGroup, const QString &config="config")
 Delete a section in the configuration. More...
 
bool deleteSection (const QString &section, const QString &config=0)
 Delete a section in the configuration. More...
 
const QStringList & getHostnameList () const
 
const QString & getActiveHost () const
 
bool setActiveHost (const QString &host)
 
const QString & getActiveCluster () const
 
bool setActiveCluster (const QString &master)
 
virtual void addConfig (const QString &filename, const QString &name, bool create=false)
 Load a configuration from a file and add it to the global configuration. More...
 
virtual void addConfig (coConfigGroup *group)
 Add a configuration group for access through the global config. More...
 
virtual void removeConfig (const QString &name)
 Removes a configuration group from the global coConfig. More...
 
void reload ()
 
bool save () const
 Save all configurations to disk. More...
 
bool save (const QString &filename) const
 Exports all configurations into a single file. More...
 
void setAdminMode (bool mode)
 Turn administrator mode on or off. More...
 
bool isAdminMode ()
 Is the administrator mode on or off. More...
 

Static Public Member Functions

static bool isDebug ()
 Check if in debug mode. More...
 
static DebugLevel getDebugLevel ()
 Get the debug level. More...
 
static void setDebugLevel (DebugLevel level)
 
static coConfiggetInstance ()
 

Protected Member Functions

 coConfig ()
 
 ~coConfig ()
 
void load ()
 

Protected Attributes

bool isGlobalConfig
 

Private Attributes

QString activeHostname
 
QStringList hostnames
 
QString activeCluster
 
QStringList masternames
 
QHash< QString, coConfigGroup * > configGroups
 
bool adminMode
 

Static Private Attributes

static coConfigconfig = 0
 
static DebugLevel debugLevel = coConfig::DebugOff
 

Member Enumeration Documentation

Enumerator
DebugOff 
DebugGetSets 
DebugAll 

Constructor & Destructor Documentation

coConfig::coConfig ( )
protected
coConfig::~coConfig ( )
protected

Member Function Documentation

void coConfig::addConfig ( const QString &  filename,
const QString &  name,
bool  create = false 
)
virtual

Load a configuration from a file and add it to the global configuration.

Parameters
filenameThe file to load. The name is searched for in the local/global config dir and COVISE_PATH
nameName of the new configuration. Has to be unique.
createIf the file does not exist, create a new, empty configuration.
void coConfig::addConfig ( coConfigGroup group)
virtual

Add a configuration group for access through the global config.

Parameters
groupThe group to add. The name of the group has to be unique.
bool coConfig::deleteSection ( const QString &  section,
const QString &  config = 0 
)

Delete a section in the configuration.

Note
This is beta. Use at you own risk and report bugs.
Parameters
sectionSection to delete.
configName of the configuration to delete this section from.
Returns
true, if something was deleted.
bool coConfig::deleteSectionForHost ( const QString &  section,
const QString &  targetHost,
const QString &  config = 0,
const QString &  configGroup = 0 
)

Delete a section for a host in the configuration.

Note
This is beta. Use at you own risk and report bugs.
Parameters
sectionSection to delete.
targetHostThe hostname of the host to be affected.
configGroupName of the configuration group to delete from.
configName of the configuration to delete this section from.
Returns
true, if something was deleted.
bool coConfig::deleteSectionInConfig ( const QString &  section,
const QString &  configGroup,
const QString &  config = "config" 
)

Delete a section in the configuration.

Note
This is beta. Use at you own risk and report bugs.
Parameters
sectionSection to delete.
configGroupName of the configuration group to delete from.
configName of the configuration to delete this section from.
Returns
true, if something was deleted.
bool coConfig::deleteValue ( const QString &  variable,
const QString &  section,
const QString &  config = 0 
)

Delete a value from the configuration.

Note
This is beta. Use at you own risk and report bugs.
Parameters
variableVariable to delete.
sectionSection, where the variable to delete is found.
configConfiguration where to delete from.
Returns
true, if something was deleted.
bool coConfig::deleteValue ( const QString &  simpleVariable)

Delete a value from the configuration.

Note
This is beta. Use at you own risk and report bugs.
Parameters
simpleVariableVariable to delete. This method deletes the variable "value"
Returns
true, if something was deleted.
bool coConfig::deleteValueForHost ( const QString &  variable,
const QString &  section,
const QString &  targetHost,
const QString &  config = 0,
const QString &  configGroup = 0 
)

Delete a value in the designated configuration group for a host only.

Note
This is beta. Use at you own risk and report bugs.
Parameters
variableVariable to delete.
sectionSection, where the variable to delete is found.
targetHostThe hostname of the host to be affected.
configConfiguration where to delete from.
configGroupName of the configuration group to delete from.
Returns
true, if something was deleted.
bool coConfig::deleteValueInConfig ( const QString &  variable,
const QString &  section,
const QString &  configGroup,
const QString &  config = "config" 
)

Delete a value in the designated configuration group.

Note
This is beta. Use at you own risk and report bugs.
Parameters
variableVariable to delete.
sectionSection, where the variable to delete is found.
configGroupName of the configuration group to delete from.
configConfiguration where to delete from.
Returns
true, if something was deleted.
const QString & coConfig::getActiveCluster ( ) const
const QString & coConfig::getActiveHost ( ) const
coConfigBool coConfig::getBool ( const QString &  variable,
const QString &  section,
bool  defaultValue 
) const
coConfigBool coConfig::getBool ( const QString &  simpleVariable,
bool  defaultValue 
) const
coConfigBool coConfig::getBool ( const QString &  variable,
const QString &  section 
) const
coConfigBool coConfig::getBool ( const QString &  variable,
const char *  section 
) const
coConfigBool coConfig::getBool ( const QString &  simpleVariable) const
coConfig::DebugLevel coConfig::getDebugLevel ( )
static

Get the debug level.

The debug level is set via the environment variable COCONFIG_DEBUG. Allowed values are:

  • 0: off
  • 1: debug gets/sets
  • any other: debug all
Returns
The debug level
const char * coConfig::getEntry ( const char *  simpleVariable) const
coConfigFloat coConfig::getFloat ( const QString &  variable,
const QString &  section,
float  defaultValue 
) const

Get a float value.

If the variable is not found, defaultValue is returned instead.

Parameters
variableVariable to check.
sectionSection of the variable.
defaultValueDefault value to return.
Returns
The value of the variable as float or the default value if the variable was not found.
coConfigFloat coConfig::getFloat ( const QString &  simpleVariable,
float  defaultValue 
) const

Get a float value.

If the variable is not found, defaultValue is returned instead. Shortcut for getFloat("value", section, defaultValue)

Parameters
simpleVariableSection of the variable "value".
defaultValueDefault value to return.
Returns
The value of the variable as float or the default value if the variable was not found.
coConfigFloat coConfig::getFloat ( const QString &  variable,
const QString &  section 
) const

Get a float value.

Parameters
variableVariable to get.
sectionSection of the variable.
Returns
The value of the variable as float.
coConfigFloat coConfig::getFloat ( const QString &  simpleVariable) const

Get a float value.

Shortcut for getFloat("value", section)

Parameters
simpleVariableSection of the variable "value".
Returns
The value of the variable as float.
const QStringList & coConfig::getHostnameList ( ) const
static coConfig* covise::coConfig::getInstance ( )
inlinestatic
coConfigInt coConfig::getInt ( const QString &  variable,
const QString &  section,
int  defaultValue 
) const
coConfigInt coConfig::getInt ( const QString &  simpleVariable,
int  defaultValue 
) const
coConfigInt coConfig::getInt ( const QString &  variable,
const QString &  section 
) const
coConfigInt coConfig::getInt ( const QString &  simpleVariable) const
coConfigLong coConfig::getLong ( const QString &  variable,
const QString &  section,
long  defaultValue 
) const
coConfigLong coConfig::getLong ( const QString &  simpleVariable,
long  defaultValue 
) const
coConfigLong coConfig::getLong ( const QString &  variable,
const QString &  section 
) const
coConfigLong coConfig::getLong ( const QString &  simpleVariable) const
coConfigEntryStringList coConfig::getScopeList ( const QString &  section = 0,
const QString &  variableName = 0 
) const
coConfigString coConfig::getString ( const QString &  variable,
const QString &  section,
const QString &  defaultValue 
) const
coConfigString coConfig::getString ( const QString &  simpleVariable) const
coConfigEntryString coConfig::getValue ( const QString &  variable,
const QString &  section,
const QString &  defaultValue 
) const
coConfigEntryString coConfig::getValue ( const QString &  variable,
const QString &  section 
) const
coConfigEntryString coConfig::getValue ( const QString &  simpleVariable) const
coConfigEntryStringList coConfig::getVariableList ( const QString &  section = 0) const
bool coConfig::isAdminMode ( )

Is the administrator mode on or off.

If the administrative mode is on, the global configuration can be written to.

Returns
true, if the administrative mode is on.
bool coConfig::isDebug ( )
static

Check if in debug mode.

Returns
true, if any debug level is set.
See Also
coConfig::getDebugLevel()
bool coConfig::isOn ( const QString &  variable,
const QString &  section,
bool  defaultValue 
) const

Checks if a variable in the configuration is set to "on".

As "on" count the case insensitive values of on, true and 1.

Parameters
variableVariable to check.
sectionSection of the variable.
defaultValueDefault value to return.
Returns
true, if the variable has above values, false if not, defaultValue if the variable does not exist.
bool coConfig::isOn ( const QString &  variable,
const QString &  section 
) const

Checks if a variable in the configuration is set to "on".

As "on" count the case insensitive values of on, true and 1.

Parameters
variableVariable to check.
sectionSection of the variable.
Returns
true, if the variable has above values, false if not or the variable does not exist.
bool coConfig::isOn ( const QString &  variable,
const char *  section 
) const
bool coConfig::isOn ( const QString &  simpleVariable,
bool  defaultValue 
) const

Checks if a variable in the configuration is set to "on".

As "on" count the case insensitive values of on, true and 1. It is a shortcut for isOn("value", section, defaultValue)

Parameters
simpleVariableSection of the variable "value".
defaultValueDefault value to return.
Returns
true, if the variable has above values, false if not, defaultValue if the variable does not exist.
bool coConfig::isOn ( const QString &  simpleVariable) const

Checks if a variable in the configuration is set to "on".

As "on" count the case insensitive values of on, true and 1. It is a shortcut for isOn("value", section)

Parameters
simpleVariableSection of the variable "value".
Returns
true, if the variable has above values, false if not or the variable does not exist.
void coConfig::load ( )
protected
void coConfig::reload ( )
void coConfig::removeConfig ( const QString &  name)
virtual

Removes a configuration group from the global coConfig.

Parameters
nameName of the configuration.
bool coConfig::save ( ) const

Save all configurations to disk.

Before calling this method, all changes are just in memory.

Note
You have to turn on the administrative mode if you want to save the global configuration.
Returns
true, if all files were saved successfully.
bool coConfig::save ( const QString &  filename) const

Exports all configurations into a single file.

Returns
true, if the configuration was exported successfully.
bool coConfig::setActiveCluster ( const QString &  master)
bool coConfig::setActiveHost ( const QString &  host)
void coConfig::setAdminMode ( bool  mode)

Turn administrator mode on or off.

It is only possible to write to the global configuration after turning this on.

Note
You can only turn on the administrative mode if you have write access to the global configuration files.
Parameters
modeNew administrative mode.
static void covise::coConfig::setDebugLevel ( DebugLevel  level)
inlinestatic
void coConfig::setValue ( const QString &  variable,
const QString &  value,
const QString &  section,
const QString &  config = 0,
bool  move = false 
)

Set a value for a variable.

The actual configuration used can be provided as parameter or automatically determined; in the latter case, this is the configuration the entry already resides in or config.local if it resides in the global configuration or not at all.

Parameters
variableVariable to set.
valueValue to set to.
sectionSection of the variable to set.
configConfiguration to set the variable in. For defaults see above
moveDelete the value from its old location *not implemented yet*
void coConfig::setValue ( const QString &  simpleVariable,
const QString &  value 
)

Set a value for a simple variable in the default configuration.

The actual configuration used is automatically determined and is the configuration the entry already resides in or config.local if it resides in the global configuration or not at all.

Parameters
simpleVariableSection of the variable to set. The variable itself is called "value"
valueValue to set to.
void coConfig::setValueForHost ( const QString &  variable,
const QString &  value,
const QString &  section,
const QString &  targetHost,
bool  move = false,
const QString &  config = 0,
const QString &  configGroup = 0 
)

Set a value for a variable for a host.

Parameters
targetHostHost to set the value for.
configGroupConfiguration group to set the value in.

For other parameters, see coConfig::setValue(const QString & variable, const QString & value, const QString & section, const QString & config, bool move).

void coConfig::setValueInConfig ( const QString &  variable,
const QString &  value,
const QString &  section,
const QString &  configGroup,
const QString &  config = "config",
bool  move = false 
)

Set a value for a variable in the designated config group.

Parameters
configGroupConfiguration group to set the value in.

For other parameters, see coConfig::setValue(const QString & variable, const QString & value, const QString & section, const QString & config, bool move).

Member Data Documentation

QString covise::coConfig::activeCluster
private
QString covise::coConfig::activeHostname
private
bool covise::coConfig::adminMode
private
coConfig * coConfig::config = 0
staticprivate
QHash<QString, coConfigGroup *> covise::coConfig::configGroups
private
coConfig::DebugLevel coConfig::debugLevel = coConfig::DebugOff
staticprivate
QStringList covise::coConfig::hostnames
private
bool covise::coConfig::isGlobalConfig
protected
QStringList covise::coConfig::masternames
private

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