mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[commands] C++: Add CommandPtr supplier constructor to ProxyCommand (#5572)
Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
This commit is contained in:
@@ -11,13 +11,20 @@ using namespace frc2;
|
||||
ProxyCommand::ProxyCommand(wpi::unique_function<Command*()> supplier)
|
||||
: m_supplier(std::move(supplier)) {}
|
||||
|
||||
ProxyCommand::ProxyCommand(wpi::unique_function<CommandPtr()> supplier)
|
||||
: ProxyCommand([supplier = std::move(supplier),
|
||||
holder = std::optional<CommandPtr>{}]() mutable {
|
||||
holder = supplier();
|
||||
return holder->get();
|
||||
}) {}
|
||||
|
||||
ProxyCommand::ProxyCommand(Command* command)
|
||||
: m_supplier([command] { return command; }) {
|
||||
: ProxyCommand([command] { return command; }) {
|
||||
SetName(std::string{"Proxy("}.append(command->GetName()).append(")"));
|
||||
}
|
||||
|
||||
ProxyCommand::ProxyCommand(std::unique_ptr<Command> command)
|
||||
: m_supplier([command = std::move(command)] { return command.get(); }) {}
|
||||
: ProxyCommand([command = std::move(command)] { return command.get(); }) {}
|
||||
|
||||
void ProxyCommand::Initialize() {
|
||||
m_command = m_supplier();
|
||||
@@ -31,8 +38,6 @@ void ProxyCommand::End(bool interrupted) {
|
||||
m_command = nullptr;
|
||||
}
|
||||
|
||||
void ProxyCommand::Execute() {}
|
||||
|
||||
bool ProxyCommand::IsFinished() {
|
||||
// because we're between `initialize` and `end`, `m_command` is necessarily
|
||||
// not null but if called otherwise and m_command is null, it's UB, so we can
|
||||
|
||||
Reference in New Issue
Block a user