diff --git a/src/share/core_configuration/configuration_json_helper.hpp b/src/share/core_configuration/configuration_json_helper.hpp index 8df6d77c8..7204a080c 100644 --- a/src/share/core_configuration/configuration_json_helper.hpp +++ b/src/share/core_configuration/configuration_json_helper.hpp @@ -9,6 +9,7 @@ namespace configuration_json_helper { class base_t { public: virtual ~base_t() = default; + virtual const std::string& get_key(void) const = 0; virtual void update_value(const nlohmann::json& json) = 0; virtual void update_json(nlohmann::json& json) const = 0; }; @@ -24,6 +25,14 @@ class value_t final : public base_t { default_value_(default_value) { } + const std::string& get_key(void) const override { + return key_; + } + + T& get_value(void) const { + return value_; + } + void update_value(const nlohmann::json& json) override { if (auto v = pqrs::json::find(json, key_)) { value_ = *v; @@ -53,6 +62,10 @@ class object_t final : public base_t { value_(value) { } + const std::string& get_key(void) const override { + return key_; + } + void update_value(const nlohmann::json& json) override { if (auto v = pqrs::json::find_object(json, key_)) { value_ = std::make_unique(v->value()); diff --git a/src/share/core_configuration/core_configuration.hpp b/src/share/core_configuration/core_configuration.hpp index aeb6ef01e..9df11b661 100644 --- a/src/share/core_configuration/core_configuration.hpp +++ b/src/share/core_configuration/core_configuration.hpp @@ -37,7 +37,7 @@ class core_configuration final { : json_(nlohmann::json::object()), loaded_(false), global_configuration_(std::make_unique(nlohmann::json::object())), - machine_specific_(nlohmann::json::object()) { + machine_specific_(std::make_unique(nlohmann::json::object())) { helper_values_.push_back(std::make_unique>("global", global_configuration_)); @@ -67,7 +67,7 @@ class core_configuration final { } if (auto v = pqrs::json::find_object(json_, "machine_specific")) { - machine_specific_ = details::machine_specific(v->value()); + machine_specific_ = std::make_unique(v->value()); } if (auto v = pqrs::json::find_array(json_, "profiles")) { @@ -104,7 +104,7 @@ class core_configuration final { } { - auto j = machine_specific_.to_json(); + auto j = machine_specific_->to_json(); if (!j.empty()) { json["machine_specific"] = j; } else { @@ -127,10 +127,10 @@ class core_configuration final { } const details::machine_specific& get_machine_specific(void) const { - return machine_specific_; + return *machine_specific_; } details::machine_specific& get_machine_specific(void) { - return machine_specific_; + return *machine_specific_; } const std::vector& get_profiles(void) const { @@ -267,7 +267,7 @@ class core_configuration final { bool loaded_; std::unique_ptr global_configuration_; - details::machine_specific machine_specific_; + std::unique_ptr machine_specific_; std::vector profiles_; std::vector> helper_values_; }; diff --git a/src/share/core_configuration/details/machine_specific.hpp b/src/share/core_configuration/details/machine_specific.hpp index 038bccaeb..78ddcb675 100644 --- a/src/share/core_configuration/details/machine_specific.hpp +++ b/src/share/core_configuration/details/machine_specific.hpp @@ -13,6 +13,8 @@ class machine_specific final { public: static constexpr bool enable_multitouch_extension_default_value = false; + entry(const entry&) = delete; + entry(const nlohmann::json& json) : json_(json), enable_multitouch_extension_(enable_multitouch_extension_default_value) { @@ -50,6 +52,8 @@ class machine_specific final { std::vector> helper_values_; }; + machine_specific(const machine_specific&) = delete; + machine_specific(const nlohmann::json& json) : json_(json) { pqrs::json::requires_object(json, "json");