Simiplify code for CommandQueue

This commit is contained in:
Thomas Basler
2025-03-22 14:43:00 +01:00
parent 84f13f93c7
commit 3e22669031

View File

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2024 Thomas Basler and others
* Copyright (C) 2024-2025 Thomas Basler and others
*/
#include "CommandQueue.h"
#include "../inverters/InverterAbstract.h"
@@ -11,7 +11,7 @@ void CommandQueue::removeAllEntriesForInverter(InverterAbstract* inv)
std::lock_guard<std::mutex> lock(_mutex);
auto it = std::remove_if(_queue.begin(), _queue.end(),
[&inv](std::shared_ptr<CommandAbstract> v) -> bool { return v.get()->getTargetAddress() == inv->serial(); });
[&](const auto& v) { return v->getTargetAddress() == inv->serial(); });
_queue.erase(it, _queue.end());
}
@@ -20,7 +20,7 @@ void CommandQueue::removeDuplicatedEntries(std::shared_ptr<CommandAbstract> cmd)
std::lock_guard<std::mutex> lock(_mutex);
auto it = std::remove_if(_queue.begin() + 1, _queue.end(),
[&cmd](std::shared_ptr<CommandAbstract> v) -> bool {
[&](const auto& v) {
return cmd->areSameParameter(v.get())
&& cmd.get()->getQueueInsertType() == QueueInsertType::RemoveOldest;
});
@@ -32,7 +32,7 @@ void CommandQueue::replaceEntries(std::shared_ptr<CommandAbstract> cmd)
std::lock_guard<std::mutex> lock(_mutex);
std::replace_if(_queue.begin() + 1, _queue.end(),
[&cmd](std::shared_ptr<CommandAbstract> v)-> bool {
[&](const auto& v) {
return cmd.get()->getQueueInsertType() == QueueInsertType::ReplaceExistent
&& cmd->areSameParameter(v.get());
},
@@ -45,7 +45,7 @@ uint8_t CommandQueue::countSimilarCommands(std::shared_ptr<CommandAbstract> cmd)
std::lock_guard<std::mutex> lock(_mutex);
return std::count_if(_queue.begin(), _queue.end(),
[&cmd](std::shared_ptr<CommandAbstract> v) -> bool {
[&](const auto& v) {
return cmd->areSameParameter(v.get());
});
}