[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

@@ -5,6 +5,7 @@
#include <memory>
#include "CommandTestBase.h"
#include "frc2/command/CommandPtr.h"
#include "frc2/command/InstantCommand.h"
#include "frc2/command/ProxyScheduleCommand.h"
#include "frc2/command/WaitUntilCommand.h"
@@ -51,10 +52,10 @@ TEST_F(ProxyScheduleCommandTest, OwningCommandSchedule) {
bool scheduled = false;
ProxyScheduleCommand command(
std::make_unique<InstantCommand>([&scheduled] { scheduled = true; }));
CommandPtr command =
InstantCommand([&scheduled] { scheduled = true; }).AsProxy();
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_TRUE(scheduled);
@@ -65,15 +66,15 @@ TEST_F(ProxyScheduleCommandTest, OwningCommandEnd) {
bool finished = false;
ProxyScheduleCommand command(
std::make_unique<WaitUntilCommand>([&finished] { return finished; }));
CommandPtr command =
WaitUntilCommand([&finished] { return finished; }).AsProxy();
scheduler.Schedule(&command);
scheduler.Schedule(command);
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));
EXPECT_TRUE(scheduler.IsScheduled(command));
finished = true;
scheduler.Run();
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
EXPECT_FALSE(scheduler.IsScheduled(command));
}