Skip to content

Commit

Permalink
Add proxy factory to Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Sep 2, 2023
1 parent 8e2465f commit 5d4c9e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public static Command print(String message) {
return new PrintCommand(message);
}

/**
* Constructs a command that schedules the supplied command when initialized, and ends when it is
* no longer scheduled.
*
* @param supplier the command supplier
* @return the command
* @see ProxyCommand
*/
public static Command proxy(Supplier<Command> supplier) {
return new ProxyCommand(supplier);
}

// Idling Commands

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "frc2/command/ParallelDeadlineGroup.h"
#include "frc2/command/ParallelRaceGroup.h"
#include "frc2/command/PrintCommand.h"
#include "frc2/command/ProxyCommand.h"
#include "frc2/command/RunCommand.h"
#include "frc2/command/SequentialCommandGroup.h"
#include "frc2/command/WaitCommand.h"
Expand Down Expand Up @@ -86,6 +87,14 @@ CommandPtr cmd::Print(std::string_view msg) {
return PrintCommand(msg).ToPtr();
}

CommandPtr cmd::Proxy(wpi::unique_function<Command*()> supplier) {
return ProxyCommand(std::move(supplier)).ToPtr();
}

CommandPtr cmd::Proxy(wpi::unique_function<CommandPtr()> supplier) {
return ProxyCommand(std::move(supplier)).ToPtr();
}

CommandPtr cmd::Wait(units::second_t duration) {
return WaitCommand(duration).ToPtr();
}
Expand Down
16 changes: 16 additions & 0 deletions wpilibNewCommands/src/main/native/include/frc2/command/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ CommandPtr RunEnd(std::function<void()> run, std::function<void()> end,
[[nodiscard]]
CommandPtr Print(std::string_view msg);

/**
* Constructs a command that schedules the supplied command when initialized,
* and ends when it is no longer scheduled
*
* @param supplier the command supplier
*/
[[nodiscard]] CommandPtr Proxy(wpi::unique_function<Command*()> supplier);

/**
* Constructs a command that schedules the supplied command when initialized,
* and ends when it is no longer scheduled
*
* @param supplier the command supplier
*/
[[nodiscard]] CommandPtr Proxy(wpi::unique_function<CommandPtr()> supplier);

// Idling Commands

/**
Expand Down

0 comments on commit 5d4c9e1

Please sign in to comment.