Skip to content

Commit

Permalink
Use Requirements struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Oct 2, 2023
1 parent ac8907f commit 858860d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 82 deletions.
14 changes: 2 additions & 12 deletions wpilibNewCommands/src/main/native/cpp/frc2/command/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,12 @@ CommandPtr cmd::Either(CommandPtr&& onTrue, CommandPtr&& onFalse,
}

CommandPtr cmd::Defer(wpi::unique_function<Command*()> supplier,
std::span<Subsystem* const> requirements) {
return DeferredCommand(std::move(supplier), requirements).ToPtr();
}

CommandPtr cmd::Defer(wpi::unique_function<Command*()> supplier,
std::initializer_list<Subsystem*> requirements) {
return DeferredCommand(std::move(supplier), requirements).ToPtr();
}

CommandPtr cmd::Defer(wpi::unique_function<CommandPtr()> supplier,
std::span<Subsystem* const> requirements) {
Requirements requirements) {
return DeferredCommand(std::move(supplier), requirements).ToPtr();
}

CommandPtr cmd::Defer(wpi::unique_function<CommandPtr()> supplier,
std::initializer_list<Subsystem*> requirements) {
Requirements requirements) {
return DeferredCommand(std::move(supplier), requirements).ToPtr();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,13 @@
using namespace frc2;

DeferredCommand::DeferredCommand(wpi::unique_function<Command*()> supplier,
std::span<Subsystem* const> requirements)
Requirements requirements)
: m_supplier{std::move(supplier)} {
AddRequirements(requirements);
}

DeferredCommand::DeferredCommand(wpi::unique_function<Command*()> supplier,
std::initializer_list<Subsystem*> requirements)
: m_supplier{std::move(supplier)} {
AddRequirements(requirements);
}

DeferredCommand::DeferredCommand(wpi::unique_function<CommandPtr()> supplier,
std::span<Subsystem* const> requirements)
: DeferredCommand(
[lambdaSupplier = std::move(supplier),
holder = std::optional<CommandPtr>{}]() mutable {
holder = lambdaSupplier();
return holder->get();
},
requirements) {}

DeferredCommand::DeferredCommand(wpi::unique_function<CommandPtr()> supplier,
std::initializer_list<Subsystem*> requirements)
Requirements requirements)
: DeferredCommand(
[lambdaSupplier = std::move(supplier),
holder = std::optional<CommandPtr>{}]() mutable {
Expand Down
24 changes: 2 additions & 22 deletions wpilibNewCommands/src/main/native/include/frc2/command/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,7 @@ CommandPtr Select(std::function<Key()> selector,
*/
[[nodiscard]]
CommandPtr Defer(wpi::unique_function<Command*()> supplier,
std::span<Subsystem* const> 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<Command*()> supplier,
std::initializer_list<Subsystem*> 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<CommandPtr()> supplier,
std::span<Subsystem* const> requirements);
Requirements requirements);

/**
* Runs the command supplied by the supplier.
Expand All @@ -180,7 +160,7 @@ CommandPtr Defer(wpi::unique_function<CommandPtr()> supplier,
*/
[[nodiscard]]
CommandPtr Defer(wpi::unique_function<CommandPtr()> supplier,
std::initializer_list<Subsystem*> requirements);
Requirements requirements);

/**
* Constructs a command that schedules the command returned from the supplier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -39,35 +40,7 @@ class DeferredCommand : public CommandHelper<Command, DeferredCommand> {
*
*/
DeferredCommand(wpi::unique_function<Command*()> supplier,
std::span<Subsystem* const> 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 <i>must</i> create a new Command each
* call.
*
* @param supplier The command supplier
* @param requirements The command requirements.
*
*/
DeferredCommand(wpi::unique_function<Command*()> supplier,
std::initializer_list<Subsystem*> 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 <i>must</i> create a new Command each
* call.
*
* @param supplier The command supplier
* @param requirements The command requirements.
*
*/
DeferredCommand(wpi::unique_function<CommandPtr()> supplier,
std::span<Subsystem* const> requirements);
Requirements requirements);

/**
* Creates a new DeferredCommand that runs the supplied command when
Expand All @@ -81,7 +54,7 @@ class DeferredCommand : public CommandHelper<Command, DeferredCommand> {
*
*/
DeferredCommand(wpi::unique_function<CommandPtr()> supplier,
std::initializer_list<Subsystem*> requirements);
Requirements requirements);

DeferredCommand(DeferredCommand&& other) = default;

Expand Down

0 comments on commit 858860d

Please sign in to comment.