Skip to content

Commit

Permalink
Delete copy constructor of complex_modifications, manipulator
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jun 30, 2024
1 parent 2c6bae0 commit 28e58f4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/core/grabber/include/grabber/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/share/complex_modifications_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace complex_modifications_utility {
inline std::vector<std::string> lint_rule(const core_configuration::details::complex_modifications_rule& rule) {
std::vector<std::string> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class complex_modifications_rule final {
nlohmann::json json_;
};

manipulator(const manipulator&) = delete;

manipulator(const nlohmann::json& json,
gsl::not_null<std::shared_ptr<const core_configuration::details::complex_modifications_parameters>> parameters,
error_handling error_handling)
Expand Down Expand Up @@ -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<manipulator>(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()));
}
Expand All @@ -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;
}
}
Expand All @@ -131,7 +134,7 @@ class complex_modifications_rule final {
return json_;
}

const std::vector<manipulator>& get_manipulators(void) const {
const std::vector<gsl::not_null<std::shared_ptr<manipulator>>>& get_manipulators(void) const {
return manipulators_;
}

Expand All @@ -141,7 +144,7 @@ class complex_modifications_rule final {

private:
nlohmann::json json_;
std::vector<manipulator> manipulators_;
std::vector<gsl::not_null<std::shared_ptr<manipulator>>> manipulators_;
std::string description_;
};

Expand Down
6 changes: 3 additions & 3 deletions tests/src/core_configuration/src/core_configuration_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}
Expand Down Expand Up @@ -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() == "");
Expand Down

0 comments on commit 28e58f4

Please sign in to comment.