* @brief eVaf configuration interface implementation
* @author Enar Vaikene
*
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
*
* This file is part of the eVaf C++ cross-platform application development framework.
*
using namespace eVaf::Common;
+namespace
+{
+ static Internal::Config * singleton = nullptr;
+}
+
iConfig * iConfig::instance()
{
- static Internal::Config singleton;
- return singleton.interface();
+ if (nullptr == singleton)
+ {
+ singleton = new Internal::Config;
+ }
+ return singleton->_interface();
}
using namespace eVaf::Common::Internal;
+void Config::destroyInstance()
+{
+ if (nullptr != singleton)
+ {
+ delete singleton;
+ singleton = nullptr;
+ }
+}
+
Config::Config()
: iConfig()
{
// Register the iConfig interface
iRegistry::instance()->registerInterface("iConfig", this);
+
+ EVAF_INFO("%s-Config created", VER_MODULE_NAME_STR);
}
Config::~Config()
{
done();
+ EVAF_INFO("%s-Config destroyed", VER_MODULE_NAME_STR);
}
-iConfig * Config::interface() const
+iConfig * Config::_interface() const
{
return evafQueryInterface<iConfig>("iConfig");
}
if (file.isEmpty() || file == "*")
file = iApp::instance()->name();
- IniFile * ini = 0;
+ IniFile * ini = nullptr;
// Is this INI file already opened?
QHash<QString, IniFile *>::const_iterator it = mIniFiles.constFind(file);
}
// Read the value
- return ini->getValue(name, defaultValue);
+ return ini->getValue(name.toLocal8Bit(), defaultValue);
}
bool Config::setValue(QString const & paramName, QVariant const & value, bool commit)
if (file.isEmpty() || file == "*")
file = iApp::instance()->name();
- IniFile * ini = 0;
+ IniFile * ini = nullptr;
// Is this INI file already opened?
QHash<QString, IniFile *>::const_iterator it = mIniFiles.constFind(file);
}
// Write the value
- if (!ini->setValue(name, value))
+ if (!ini->setValue(name.toLocal8Bit(), value))
return false;
return true;