]>
vaikene.ee Git - evaf/blob - src/libs/Common/iconfig.h
3157eb69673aedc095be6ac874fd32ecd704051c
2 * @file Common/iconfig.h
3 * @brief eVaf configuration interface
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __COMMON_ICONFIG_H
21 # define __COMMON_ICONFIG_H
23 #include "libcommon.h"
33 * eVaf configuration interface.
34 * @code#include <iConfig>@endcode
36 * The iConfig interface provides access to configuration parameters. Methods in this interface can be
37 * used to read and write configuration parameters.
39 * The default implementation of the iConfig interface uses INI files in the eVaf::Common::iApp::instance()->etcDir()
40 * directory. Additional configuration backends can be provided by re-implementing the interface.
42 * Configuration parameters are identified by a name in the following format:
43 * [\<backend:\>][\<file\>]/\<section\>/\<key\>
46 * @li \<backend:\> is an optional identifier for the configuration backend. This part is ignored by the default
47 * iConfig interface implementation and is reserved for custom modules. For example, a custom module could look
48 * for the 'db:' backend identifier and store parameters in a database. Any other requests would be forwarded to
49 * the default implementation.
50 * @li \<file\> is an optional configuration file name. The default iConfig interface implementation uses the file
51 * name part to locate the INI file in the eVaf::Common::iApp::instance()->etcDir() directory. If the file name part
52 * is '*' or empty, uses eVaf::Common::iApp::instance()->name() for the file name.
53 * @li \<section\> is the name of the section. Section names can contain extra '/' characters to build a structured
54 * tree of configuration sections.
55 * @li \<key\> is the name of the key.
58 * @li 'db:local/extensions/help/module' - backend 'db:', file or database name 'local', section name 'extensions/help' and
60 * @li '/extensions/help/module' - default backend, default file name, section name 'extensions/help' and the key 'module'.
62 class COMMON_EXPORT iConfig
: public QObject
68 /// Interface constructor
69 iConfig() : QObject() {}
71 /// Empty virtual destructor
75 * Returns the current iConfig interface instance
76 * @return The iConfig interface
78 * This method returns the current iConfig interface instance as shown in the following example:
80 * QString moduleName = eVaf::Common::iConfig::instance()->getValue("/extensions/help/module", "libHelp.so").toString();
83 static iConfig
* instance();
86 * Reads a configuration parameter value
87 * @param paramName Name of the parameter
88 * @param defaultValue Default value
89 * @return The parameter value or the default value if the parameter cannot be found
91 * The getValue() method returns a configuration parameter value identified by the parameter name. If the parameter
92 * cannot be read or is not found, returns the default value.
94 * The default value is used to determine the type of the value. For example, if the default value is an integer, then
95 * the returned value is also an integer. The default iConfig interface implementation validates parameter values and
96 * makes sure that the parameter value is of the proper type. If the value cannot be converted to the proper type,
97 * returns the default value. Other implementations of the iConfig interface are encouraged to do the same.
99 virtual QVariant
getValue(QString
const & paramName
, QVariant
const & defaultValue
) const = 0;
102 * Writes a configuration parameter value
103 * @param paramName Name of the parameter
104 * @param value The parameter value
105 * @param commit If true, then commits new parameter values
106 * @return True if succeeded; false if not
108 * The setValue() method writes new configuration parameter values identified by the parameter name.
110 * The commit argument can be used to improve the performance of writing several parameter values at once. Use
111 * commit = false for all except the last parameter's write operation.
113 * iConfig * conf = eVaf::Common::iConfig::instance();
114 * conf->setValue("/main/param1", 1, false);
115 * conf->setValue("/main/param2", 2, false);
116 * conf->setValue("/main/param3", 3); // Last parameter in the block
119 virtual bool setValue(QString
const & paramName
, QVariant
const & value
, bool commit
= true) = 0;
124 } // namespace eVaf::Common