mirror of
https://github.com/tbnobody/OpenDTU.git
synced 2025-12-11 01:10:20 +01:00
Simiplify code for CommandQueue
This commit is contained in:
@@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user