From 858860d24f7b766329076ed984a3a3755abb7fa7 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Mon, 2 Oct 2023 15:19:42 -0400 Subject: [PATCH] Use Requirements struct --- .../main/native/cpp/frc2/command/Commands.cpp | 14 ++------ .../cpp/frc2/command/DeferredCommand.cpp | 20 ++--------- .../native/include/frc2/command/Commands.h | 24 ++------------ .../include/frc2/command/DeferredCommand.h | 33 ++----------------- 4 files changed, 9 insertions(+), 82 deletions(-) diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp index 7b91432cde7..3b4f14ccff9 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp @@ -84,22 +84,12 @@ CommandPtr cmd::Either(CommandPtr&& onTrue, CommandPtr&& onFalse, } CommandPtr cmd::Defer(wpi::unique_function supplier, - std::span requirements) { - return DeferredCommand(std::move(supplier), requirements).ToPtr(); -} - -CommandPtr cmd::Defer(wpi::unique_function supplier, - std::initializer_list requirements) { - return DeferredCommand(std::move(supplier), requirements).ToPtr(); -} - -CommandPtr cmd::Defer(wpi::unique_function supplier, - std::span requirements) { + Requirements requirements) { return DeferredCommand(std::move(supplier), requirements).ToPtr(); } CommandPtr cmd::Defer(wpi::unique_function supplier, - std::initializer_list requirements) { + Requirements requirements) { return DeferredCommand(std::move(supplier), requirements).ToPtr(); } diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/DeferredCommand.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/DeferredCommand.cpp index 530d086508c..30c2c3e2456 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/DeferredCommand.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/DeferredCommand.cpp @@ -11,29 +11,13 @@ using namespace frc2; DeferredCommand::DeferredCommand(wpi::unique_function supplier, - std::span requirements) + Requirements requirements) : m_supplier{std::move(supplier)} { AddRequirements(requirements); } -DeferredCommand::DeferredCommand(wpi::unique_function supplier, - std::initializer_list requirements) - : m_supplier{std::move(supplier)} { - AddRequirements(requirements); -} - -DeferredCommand::DeferredCommand(wpi::unique_function supplier, - std::span requirements) - : DeferredCommand( - [lambdaSupplier = std::move(supplier), - holder = std::optional{}]() mutable { - holder = lambdaSupplier(); - return holder->get(); - }, - requirements) {} - DeferredCommand::DeferredCommand(wpi::unique_function supplier, - std::initializer_list requirements) + Requirements requirements) : DeferredCommand( [lambdaSupplier = std::move(supplier), holder = std::optional{}]() mutable { diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h index 5855001c0a9..e26d4b01cc7 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/Commands.h @@ -150,27 +150,7 @@ CommandPtr Select(std::function selector, */ [[nodiscard]] CommandPtr Defer(wpi::unique_function supplier, - std::span requirements); - -/** - * Runs the command supplied by the supplier. - * - * @param supplier the command supplier - * @param requirements the set of requirements for this command - */ -[[nodiscard]] -CommandPtr Defer(wpi::unique_function supplier, - std::initializer_list requirements); - -/** - * Runs the command supplied by the supplier. - * - * @param supplier the command supplier - * @param requirements the set of requirements for this command - */ -[[nodiscard]] -CommandPtr Defer(wpi::unique_function supplier, - std::span requirements); + Requirements requirements); /** * Runs the command supplied by the supplier. @@ -180,7 +160,7 @@ CommandPtr Defer(wpi::unique_function supplier, */ [[nodiscard]] CommandPtr Defer(wpi::unique_function supplier, - std::initializer_list requirements); + Requirements requirements); /** * Constructs a command that schedules the command returned from the supplier diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/DeferredCommand.h b/wpilibNewCommands/src/main/native/include/frc2/command/DeferredCommand.h index c8aa783f514..23bf214a572 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/DeferredCommand.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/DeferredCommand.h @@ -12,6 +12,7 @@ #include "frc2/command/Command.h" #include "frc2/command/CommandHelper.h" #include "frc2/command/PrintCommand.h" +#include "frc2/command/Requirements.h" namespace frc2 { /** @@ -39,35 +40,7 @@ class DeferredCommand : public CommandHelper { * */ DeferredCommand(wpi::unique_function supplier, - std::span requirements); - - /** - * Creates a new DeferredCommand that runs the supplied command when - * initialized, and ends when it ends. Useful for lazily - * creating commands at runtime. The supplier will be called each time this - * command is initialized. The supplier must create a new Command each - * call. - * - * @param supplier The command supplier - * @param requirements The command requirements. - * - */ - DeferredCommand(wpi::unique_function supplier, - std::initializer_list requirements); - - /** - * Creates a new DeferredCommand that runs the supplied command when - * initialized, and ends when it ends. Useful for lazily - * creating commands at runtime. The supplier will be called each time this - * command is initialized. The supplier must create a new Command each - * call. - * - * @param supplier The command supplier - * @param requirements The command requirements. - * - */ - DeferredCommand(wpi::unique_function supplier, - std::span requirements); + Requirements requirements); /** * Creates a new DeferredCommand that runs the supplied command when @@ -81,7 +54,7 @@ class DeferredCommand : public CommandHelper { * */ DeferredCommand(wpi::unique_function supplier, - std::initializer_list requirements); + Requirements requirements); DeferredCommand(DeferredCommand&& other) = default;