[commands] C++ unique_ptr migration (#4319)

Add a CommandPtr with an internal unique_ptr to enable not needing to move the underlying classes, which is error-prone due to the potential for lambda captures.
This commit is contained in:
Starlight220
2022-10-06 01:19:28 +03:00
committed by GitHub
parent 3b81cf6c35
commit 60e29627c0
18 changed files with 644 additions and 133 deletions

View File

@@ -19,6 +19,7 @@
#include <wpi/sendable/SendableRegistry.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandPtr.h"
#include "frc2/command/Subsystem.h"
using namespace frc2;
@@ -173,6 +174,10 @@ void CommandScheduler::Schedule(std::initializer_list<Command*> commands) {
}
}
void CommandScheduler::Schedule(const CommandPtr& command) {
Schedule(command.get());
}
void CommandScheduler::Run() {
if (m_impl->disabled) {
return;
@@ -326,6 +331,10 @@ void CommandScheduler::Cancel(Command* command) {
m_watchdog.AddEpoch(command->GetName() + ".End(true)");
}
void CommandScheduler::Cancel(const CommandPtr& command) {
Cancel(command.get());
}
void CommandScheduler::Cancel(wpi::span<Command* const> commands) {
for (auto command : commands) {
Cancel(command);
@@ -370,6 +379,10 @@ bool CommandScheduler::IsScheduled(const Command* command) const {
return m_impl->scheduledCommands.contains(command);
}
bool CommandScheduler::IsScheduled(const CommandPtr& command) const {
return m_impl->scheduledCommands.contains(command.get());
}
Command* CommandScheduler::Requiring(const Subsystem* subsystem) const {
auto find = m_impl->requirements.find(subsystem);
if (find != m_impl->requirements.end()) {