mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +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:
@@ -13,6 +13,11 @@ Button Button::WhenPressed(Command* command) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenPressed(CommandPtr&& command) {
|
||||
WhenActive(std::move(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenPressed(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
WhenActive(std::move(toRun), requirements);
|
||||
@@ -30,6 +35,11 @@ Button Button::WhileHeld(Command* command) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhileHeld(CommandPtr&& command) {
|
||||
WhileActiveContinous(std::move(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhileHeld(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
WhileActiveContinous(std::move(toRun), requirements);
|
||||
@@ -47,11 +57,21 @@ Button Button::WhenHeld(Command* command) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenHeld(CommandPtr&& command) {
|
||||
WhileActiveOnce(std::move(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenReleased(Command* command) {
|
||||
WhenInactive(command);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenReleased(CommandPtr&& command) {
|
||||
WhenInactive(std::move(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::WhenReleased(std::function<void()> toRun,
|
||||
std::initializer_list<Subsystem*> requirements) {
|
||||
WhenInactive(std::move(toRun), requirements);
|
||||
@@ -69,6 +89,11 @@ Button Button::ToggleWhenPressed(Command* command) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::ToggleWhenPressed(CommandPtr&& command) {
|
||||
ToggleWhenActive(std::move(command));
|
||||
return *this;
|
||||
}
|
||||
|
||||
Button Button::CancelWhenPressed(Command* command) {
|
||||
CancelWhenActive(command);
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user