mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-03-06 14:27:43 +00:00
Improved thread safety for Settings.
Also moved some data from the global namespace to an anonymous namespace.
This commit is contained in:
parent
6bc4a09c9b
commit
81d6f0fd30
es-core/src
|
@ -19,8 +19,8 @@
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
Settings* Settings::sInstance = nullptr;
|
namespace
|
||||||
|
{
|
||||||
// These values are NOT saved to es_settings.xml since they're not set via
|
// These values are NOT saved to es_settings.xml since they're not set via
|
||||||
// the in-program settings menu. Most can be set using command-line arguments,
|
// the in-program settings menu. Most can be set using command-line arguments,
|
||||||
// but some are debug flags that are either hardcoded or set by internal debug
|
// but some are debug flags that are either hardcoded or set by internal debug
|
||||||
|
@ -59,6 +59,7 @@ std::vector<std::string> settingsSkipSaving
|
||||||
"ScraperFilter"
|
"ScraperFilter"
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
{
|
{
|
||||||
|
@ -67,20 +68,10 @@ Settings::Settings()
|
||||||
loadFile();
|
loadFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings* Settings::getInstance()
|
std::shared_ptr<Settings> Settings::getInstance()
|
||||||
{
|
{
|
||||||
if (sInstance == nullptr)
|
static std::shared_ptr<Settings> instance{std::shared_ptr<Settings>(new Settings)};
|
||||||
sInstance = new Settings();
|
return instance;
|
||||||
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Settings::deinit()
|
|
||||||
{
|
|
||||||
if (sInstance) {
|
|
||||||
delete sInstance;
|
|
||||||
sInstance = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::setDefaults()
|
void Settings::setDefaults()
|
||||||
|
|
|
@ -11,14 +11,14 @@
|
||||||
#define ES_CORE_SETTINGS_H
|
#define ES_CORE_SETTINGS_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// This is a singleton for storing settings.
|
// This is a singleton for storing settings.
|
||||||
class Settings
|
class Settings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Settings* getInstance();
|
static std::shared_ptr<Settings> getInstance();
|
||||||
static void deinit();
|
|
||||||
|
|
||||||
void loadFile();
|
void loadFile();
|
||||||
void saveFile();
|
void saveFile();
|
||||||
|
@ -39,8 +39,6 @@ public:
|
||||||
bool setString(const std::string& name, const std::string& value);
|
bool setString(const std::string& name, const std::string& value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Settings* sInstance;
|
|
||||||
|
|
||||||
Settings();
|
Settings();
|
||||||
|
|
||||||
// Clear everything and load default values.
|
// Clear everything and load default values.
|
||||||
|
|
Loading…
Reference in a new issue