diff options
Diffstat (limited to 'lib/configuration')
-rw-r--r-- | lib/configuration/configuration.cpp | 13 | ||||
-rw-r--r-- | lib/configuration/configuration.h | 2 | ||||
-rw-r--r-- | lib/configuration/test/main.cpp | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp index 75f863c..6686520 100644 --- a/lib/configuration/configuration.cpp +++ b/lib/configuration/configuration.cpp @@ -17,7 +17,7 @@ #include <QStandardPaths> #endif -static std::unique_ptr<Configuration> s_conf; +static Configuration *s_conf = nullptr; Configuration::Configuration() : use_global(true) @@ -131,14 +131,19 @@ void Configuration::read(std::basic_istream<char> &input) } } -void Configuration::move_global(std::unique_ptr<Configuration> &&conf) +bool Configuration::make_global() { - s_conf = std::move(conf); + if(use_global || s_conf != nullptr) { + return false; + } + + s_conf = this; + return true; } Configuration *Configuration::instance() { - return s_conf.get(); + return s_conf; } std::ostream &operator<<(std::ostream &out, const Configuration &obj) diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index cd3c244..c2400b6 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -126,7 +126,7 @@ public: return T{}; } - static void move_global(std::unique_ptr<Configuration> && conf); + bool make_global(); private: static Configuration *instance(); diff --git a/lib/configuration/test/main.cpp b/lib/configuration/test/main.cpp index fa04f10..06f7cb0 100644 --- a/lib/configuration/test/main.cpp +++ b/lib/configuration/test/main.cpp @@ -151,7 +151,7 @@ SCENARIO("Configuration") output << *global_conf; REQUIRE(output.str() == "name=global\nnumber=123\ntoggle=true\n"); - Configuration::move_global(std::move(global_conf)); + global_conf->make_global(); Configuration g; REQUIRE(g.value<std::string>("name")); REQUIRE(g.value<std::string>("name").value() == "global"); |