eVaf
eVaf::Common::iConfig Class Referenceabstract

eVaf configuration interface. More...

#include <Common/iconfig.h>

Public Member Functions

virtual QVariant getValue (QString const &paramName, QVariant const &defaultValue) const =0
 Reads a configuration parameter value. More...
 
 iConfig ()
 Interface constructor. More...
 
virtual bool setValue (QString const &paramName, QVariant const &value, bool commit=true)=0
 Writes a configuration parameter value. More...
 
virtual ~iConfig ()
 Empty virtual destructor. More...
 

Static Public Member Functions

static iConfiginstance ()
 Returns the current iConfig interface instance. More...
 

Detailed Description

eVaf configuration interface.

#include <iConfig>

The iConfig interface provides access to configuration parameters. Methods in this interface can be used to read and write configuration parameters.

The default implementation of the iConfig interface uses INI files in the eVaf::Common::iApp::etcDir() directory. Additional configuration backends can be provided by re-implementing the interface.

Configuration parameters are identified by a name in the following format:

[<backend:>][<file>]/<section>/<key> 

Where:

  • <backend:> is an optional identifier for the configuration backend. This part is ignored by the default iConfig interface implementation and is reserved for custom modules. For example, a custom module could look for the 'db:' backend identifier and store parameters in a database. Any other requests would be forwarded to the default implementation.
  • <file> is an optional configuration file name. The default iConfig interface implementation uses the file name part to locate the INI file in the eVaf::Common::iApp::etcDir() directory. If the file name part is '*' or empty, uses eVaf::Common::iApp::name() for the file name.
  • <section> is the name of the section. Section names can contain extra '/' characters to build a structured tree of configuration sections.
  • <key> is the name of the parameter.

For example:

  • 'db:local/extensions/help/module' - backend 'db:', file or database name 'local', section name 'extensions/help' and the key 'module';
  • '/extensions/help/module' - default backend, default file name, section name 'extensions/help' and the key 'module'.

Definition at line 62 of file iconfig.h.

Constructor & Destructor Documentation

eVaf::Common::iConfig::iConfig ( )
inline

Interface constructor.

Definition at line 69 of file iconfig.h.

virtual eVaf::Common::iConfig::~iConfig ( )
inlinevirtual

Empty virtual destructor.

Definition at line 72 of file iconfig.h.

Member Function Documentation

virtual QVariant eVaf::Common::iConfig::getValue ( QString const &  paramName,
QVariant const &  defaultValue 
) const
pure virtual

Reads a configuration parameter value.

Parameters
paramNameName of the parameter
defaultValueDefault value
Returns
The parameter value or the default value if the parameter cannot be found

The getValue() method returns a configuration parameter value identified by the parameter name. If the parameter cannot be read or is not found, returns the default value.

The default value is used to determine the type of the value. For example, if the default value is an integer, then the returned value is also an integer. The default iConfig interface implementation validates parameter values and makes sure that the parameter value is of the proper type. If the value cannot be converted to the proper type, returns the default value. Other implementations of the iConfig interface are encouraged to do the same.

Implemented in eVaf::Common::Internal::Config.

static iConfig* eVaf::Common::iConfig::instance ( )
static

Returns the current iConfig interface instance.

Returns
The iConfig interface

This method returns the current iConfig interface instance as shown in the following example:

QString moduleName =
eVaf::Common::iConfig::instance()->getValue("/extensions/help/module", "libHelp.so").toString();
virtual bool eVaf::Common::iConfig::setValue ( QString const &  paramName,
QVariant const &  value,
bool  commit = true 
)
pure virtual

Writes a configuration parameter value.

Parameters
paramNameName of the parameter
valueThe parameter value
commitIf true, then commits new parameter values
Returns
True if succeeded; false if not

The setValue() method writes new configuration parameter values identified by the parameter name.

The commit argument can be used to improve the performance of writing several parameter values at once. Use commit = false for all except the last parameter's write operation.

conf->setValue("/main/param1", 1, false);
conf->setValue("/main/param2", 2, false);
conf->setValue("/main/param3", 3); // Last parameter in the block

Implemented in eVaf::Common::Internal::Config.


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