[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

@@ -11,6 +11,7 @@
#include <wpi/span.h>
#include "Trigger.h"
#include "frc2/command/CommandPtr.h"
namespace frc2 {
class Command;
@@ -47,6 +48,16 @@ class Button : public Trigger {
*/
Button WhenPressed(Command* command);
/**
* Binds a command to start when the button is pressed. Transfers
* command ownership to the button scheduler, so the user does not have to
* worry about lifespan.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
*/
Button WhenPressed(CommandPtr&& command);
/**
* Binds a command to start when the button is pressed. Transfers
* command ownership to the button scheduler, so the user does not have to
@@ -91,6 +102,16 @@ class Button : public Trigger {
*/
Button WhileHeld(Command* command);
/**
* Binds a command to be started repeatedly while the button is pressed, and
* canceled when it is released. Transfers command ownership to the button
* scheduler, so the user does not have to worry about lifespan.
*
* @param command The command to bind.
* @return The button, for chained calls.
*/
Button WhileHeld(CommandPtr&& command);
/**
* Binds a command to be started repeatedly while the button is pressed, and
* canceled when it is released. Transfers command ownership to the button
@@ -135,6 +156,16 @@ class Button : public Trigger {
*/
Button WhenHeld(Command* command);
/**
* Binds a command to be started when the button is pressed, and canceled
* when it is released. Transfers command ownership to the button scheduler,
* so the user does not have to worry about lifespan.
*
* @param command The command to bind.
* @return The button, for chained calls.
*/
Button WhenHeld(CommandPtr&& command);
/**
* Binds a command to be started when the button is pressed, and canceled
* when it is released. Transfers command ownership to the button scheduler,
@@ -161,6 +192,16 @@ class Button : public Trigger {
*/
Button WhenReleased(Command* command);
/**
* Binds a command to start when the button is pressed. Transfers
* command ownership to the button scheduler, so the user does not have to
* worry about lifespan.
*
* @param command The command to bind.
* @return The button, for chained calls.
*/
Button WhenReleased(CommandPtr&& command);
/**
* Binds a command to start when the button is pressed. Transfers
* command ownership to the button scheduler, so the user does not have to
@@ -205,6 +246,16 @@ class Button : public Trigger {
*/
Button ToggleWhenPressed(Command* command);
/**
* Binds a command to start when the button is pressed, and be canceled when
* it is pessed again. Transfers command ownership to the button scheduler,
* so the user does not have to worry about lifespan.
*
* @param command The command to bind.
* @return The button, for chained calls.
*/
Button ToggleWhenPressed(CommandPtr&& command);
/**
* Binds a command to start when the button is pressed, and be canceled when
* it is pessed again. Transfers command ownership to the button scheduler,

View File

@@ -69,6 +69,15 @@ class Trigger : public frc::BooleanEvent {
*/
Trigger WhenActive(Command* command);
/**
* Binds a command to start when the trigger becomes active. Moves
* command ownership to the button scheduler.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
*/
Trigger WhenActive(CommandPtr&& command);
/**
* Binds a command to start when the trigger becomes active. Transfers
* command ownership to the button scheduler, so the user does not have to
@@ -116,6 +125,16 @@ class Trigger : public frc::BooleanEvent {
*/
Trigger WhileActiveContinous(Command* command);
/**
* Binds a command to be started repeatedly while the trigger is active, and
* canceled when it becomes inactive. Moves command ownership to the button
* scheduler.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
*/
Trigger WhileActiveContinous(CommandPtr&& command);
/**
* Binds a command to be started repeatedly while the trigger is active, and
* canceled when it becomes inactive. Transfers command ownership to the
@@ -164,6 +183,16 @@ class Trigger : public frc::BooleanEvent {
*/
Trigger WhileActiveOnce(Command* command);
/**
* Binds a command to be started when the trigger becomes active, and
* canceled when it becomes inactive. Moves command ownership to the button
* scheduler.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
*/
Trigger WhileActiveOnce(CommandPtr&& command);
/**
* Binds a command to be started when the trigger becomes active, and
* canceled when it becomes inactive. Transfers command ownership to the
@@ -195,6 +224,15 @@ class Trigger : public frc::BooleanEvent {
*/
Trigger WhenInactive(Command* command);
/**
* Binds a command to start when the trigger becomes inactive. Moves
* command ownership to the button scheduler.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
*/
Trigger WhenInactive(CommandPtr&& command);
/**
* Binds a command to start when the trigger becomes inactive. Transfers
* command ownership to the button scheduler, so the user does not have to
@@ -242,6 +280,16 @@ class Trigger : public frc::BooleanEvent {
*/
Trigger ToggleWhenActive(Command* command);
/**
* Binds a command to start when the trigger becomes active, and be canceled
* when it again becomes active. Moves command ownership to the button
* scheduler.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
*/
Trigger ToggleWhenActive(CommandPtr&& command);
/**
* Binds a command to start when the trigger becomes active, and be canceled
* when it again becomes active. Transfers command ownership to the button