]> vaikene.ee Git - evaf/blobdiff - src/libs/Common/config.cpp
Mac OS changes and switched to c++11.
[evaf] / src / libs / Common / config.cpp
index 5303bb86e8747ea84b3e55fb21b0bea389b9e976..7ddc61ea9829b4270203fabfba61d143b0505abb 100644 (file)
@@ -3,7 +3,7 @@
  * @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();
 }
 
 
@@ -41,6 +49,15 @@ iConfig * iConfig::instance()
 
 using namespace eVaf::Common::Internal;
 
+void Config::destroyInstance()
+{
+    if (nullptr != singleton)
+    {
+        delete singleton;
+        singleton = nullptr;
+    }
+}
+
 Config::Config()
     : iConfig()
 {
@@ -48,11 +65,14 @@ Config::Config()
 
     // 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
@@ -101,7 +121,7 @@ QVariant Config::getValue(QString const & paramName, QVariant const & defaultVal
     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);
@@ -176,7 +196,7 @@ bool Config::writeValue(QString const & paramName, QVariant const & value)
     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);