mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user