mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[commands] Add convenience factories (#4460)
Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
This commit is contained in:
@@ -105,6 +105,11 @@ CommandPtr Command::HandleInterrupt(std::function<void(void)> handler) && {
|
||||
return std::move(*this).ToPtr().HandleInterrupt(std::move(handler));
|
||||
}
|
||||
|
||||
CommandPtr Command::WithName(std::string_view name) && {
|
||||
SetName(name);
|
||||
return std::move(*this).ToPtr();
|
||||
}
|
||||
|
||||
void Command::Schedule() {
|
||||
CommandScheduler::GetInstance().Schedule(this);
|
||||
}
|
||||
@@ -129,6 +134,8 @@ std::string Command::GetName() const {
|
||||
return GetTypeName(*this);
|
||||
}
|
||||
|
||||
void Command::SetName(std::string_view name) {}
|
||||
|
||||
bool Command::IsGrouped() const {
|
||||
return m_isGrouped;
|
||||
}
|
||||
|
||||
@@ -219,6 +219,12 @@ CommandPtr CommandPtr::HandleInterrupt(std::function<void(void)> handler) && {
|
||||
});
|
||||
}
|
||||
|
||||
CommandPtr CommandPtr::WithName(std::string_view name) && {
|
||||
AssertValid();
|
||||
m_ptr->SetName(name);
|
||||
return std::move(*this);
|
||||
}
|
||||
|
||||
CommandBase* CommandPtr::get() const {
|
||||
AssertValid();
|
||||
return m_ptr.get();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "frc2/command/Subsystem.h"
|
||||
|
||||
#include "frc2/command/CommandPtr.h"
|
||||
#include "frc2/command/Commands.h"
|
||||
|
||||
using namespace frc2;
|
||||
Subsystem::~Subsystem() {
|
||||
@@ -31,3 +32,21 @@ Command* Subsystem::GetCurrentCommand() const {
|
||||
void Subsystem::Register() {
|
||||
return CommandScheduler::GetInstance().RegisterSubsystem(this);
|
||||
}
|
||||
|
||||
CommandPtr Subsystem::RunOnce(std::function<void()> action) {
|
||||
return cmd::RunOnce(std::move(action), {this});
|
||||
}
|
||||
|
||||
CommandPtr Subsystem::Run(std::function<void()> action) {
|
||||
return cmd::Run(std::move(action), {this});
|
||||
}
|
||||
|
||||
CommandPtr Subsystem::StartEnd(std::function<void()> start,
|
||||
std::function<void()> end) {
|
||||
return cmd::StartEnd(std::move(start), std::move(end), {this});
|
||||
}
|
||||
|
||||
CommandPtr Subsystem::RunEnd(std::function<void()> run,
|
||||
std::function<void()> end) {
|
||||
return cmd::RunEnd(std::move(run), std::move(end), {this});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user