diff --git a/src/core/grabber/include/grabber/device_grabber.hpp b/src/core/grabber/include/grabber/device_grabber.hpp index 1962a2eb8..eb038f29b 100644 --- a/src/core/grabber/include/grabber/device_grabber.hpp +++ b/src/core/grabber/include/grabber/device_grabber.hpp @@ -955,9 +955,9 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client { for (const auto& rule : core_configuration_->get_selected_profile().get_complex_modifications()->get_rules()) { for (const auto& manipulator : rule->get_manipulators()) { try { - auto m = manipulator::manipulator_factory::make_manipulator(manipulator.get_json(), - manipulator.get_parameters()); - for (const auto& c : manipulator.get_conditions()) { + auto m = manipulator::manipulator_factory::make_manipulator(manipulator->get_json(), + manipulator->get_parameters()); + for (const auto& c : manipulator->get_conditions()) { m->push_back_condition(manipulator::manipulator_factory::make_condition(c.get_json())); } complex_modifications_manipulator_manager_->push_back_manipulator(m); diff --git a/src/share/complex_modifications_utility.hpp b/src/share/complex_modifications_utility.hpp index 385c08398..4e80f6e6a 100644 --- a/src/share/complex_modifications_utility.hpp +++ b/src/share/complex_modifications_utility.hpp @@ -9,11 +9,11 @@ namespace complex_modifications_utility { inline std::vector lint_rule(const core_configuration::details::complex_modifications_rule& rule) { std::vector error_messages; - for (const auto& manipulator : rule.get_manipulators()) { + for (const auto& m : rule.get_manipulators()) { try { - manipulator::manipulator_factory::make_manipulator(manipulator.get_json(), - manipulator.get_parameters()); - for (const auto& c : manipulator.get_conditions()) { + manipulator::manipulator_factory::make_manipulator(m->get_json(), + m->get_parameters()); + for (const auto& c : m->get_conditions()) { manipulator::manipulator_factory::make_condition(c.get_json()); } diff --git a/src/share/core_configuration/details/profile/complex_modifications.hpp b/src/share/core_configuration/details/profile/complex_modifications.hpp index 1e67827e1..42f6a47c1 100644 --- a/src/share/core_configuration/details/profile/complex_modifications.hpp +++ b/src/share/core_configuration/details/profile/complex_modifications.hpp @@ -9,6 +9,8 @@ namespace core_configuration { namespace details { class complex_modifications final { public: + complex_modifications(const complex_modifications&) = delete; + complex_modifications(void) : complex_modifications(nlohmann::json::object(), krbn::core_configuration::error_handling::loose) { diff --git a/src/share/core_configuration/details/profile/complex_modifications_rule.hpp b/src/share/core_configuration/details/profile/complex_modifications_rule.hpp index 7ae083a17..a9138be34 100644 --- a/src/share/core_configuration/details/profile/complex_modifications_rule.hpp +++ b/src/share/core_configuration/details/profile/complex_modifications_rule.hpp @@ -23,6 +23,8 @@ class complex_modifications_rule final { nlohmann::json json_; }; + manipulator(const manipulator&) = delete; + manipulator(const nlohmann::json& json, gsl::not_null> parameters, error_handling error_handling) @@ -90,9 +92,10 @@ class complex_modifications_rule final { for (const auto& j : value) { try { - manipulators_.emplace_back(j, - parameters, - error_handling); + auto m = std::make_shared(j, + parameters, + error_handling); + manipulators_.push_back(m); } catch (const pqrs::json::unmarshal_error& e) { throw pqrs::json::unmarshal_error(fmt::format("`{0}` entry error: {1}", key, e.what())); } @@ -119,8 +122,8 @@ class complex_modifications_rule final { // Use manipulators_'s description if needed. if (description_.empty()) { for (const auto& m : manipulators_) { - if (!m.get_description().empty()) { - description_ = m.get_description(); + if (!m->get_description().empty()) { + description_ = m->get_description(); break; } } @@ -131,7 +134,7 @@ class complex_modifications_rule final { return json_; } - const std::vector& get_manipulators(void) const { + const std::vector>>& get_manipulators(void) const { return manipulators_; } @@ -141,7 +144,7 @@ class complex_modifications_rule final { private: nlohmann::json json_; - std::vector manipulators_; + std::vector>> manipulators_; std::string description_; }; diff --git a/tests/src/core_configuration/src/core_configuration_test.hpp b/tests/src/core_configuration/src/core_configuration_test.hpp index f729e0bcc..c7b572dc8 100644 --- a/tests/src/core_configuration/src/core_configuration_test.hpp +++ b/tests/src/core_configuration/src/core_configuration_test.hpp @@ -28,7 +28,7 @@ void run_core_configuration_test(void) { expect(expected == configuration.get_selected_profile().get_simple_modifications()->get_pairs()) << UT_SHOW_LINE; } { - auto manipulator = configuration.get_selected_profile().get_complex_modifications()->get_rules()[0]->get_manipulators()[0].get_json(); + auto manipulator = configuration.get_selected_profile().get_complex_modifications()->get_rules()[0]->get_manipulators()[0]->get_json(); expect("basic" == manipulator["type"]); expect("open_bracket" == manipulator["from"]["key_code"]); } @@ -77,8 +77,8 @@ void run_core_configuration_test(void) { auto complex_modifications = configuration.get_selected_profile().get_complex_modifications(); auto& rules = complex_modifications->get_rules(); expect(complex_modifications->get_parameters()->get_basic_to_if_alone_timeout_milliseconds() == 800); - expect(rules[0]->get_manipulators()[0].get_parameters()->get_basic_to_if_alone_timeout_milliseconds() == 800); - expect(rules[0]->get_manipulators()[2].get_parameters()->get_basic_to_if_alone_timeout_milliseconds() == 400); + expect(rules[0]->get_manipulators()[0]->get_parameters()->get_basic_to_if_alone_timeout_milliseconds() == 800); + expect(rules[0]->get_manipulators()[2]->get_parameters()->get_basic_to_if_alone_timeout_milliseconds() == 400); expect(rules[0]->get_description() == "Emacs bindings, etc."); expect(rules[1]->get_description() == "description test"); expect(rules[2]->get_description() == "");