[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

@@ -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;