[commands] Change grouping decorator impl to flatten nested group structures (#3335)

This commit is contained in:
Starlight220
2021-06-14 02:05:14 +03:00
committed by GitHub
parent b422665a3c
commit ef4ea84cb5
12 changed files with 126 additions and 17 deletions

View File

@@ -107,7 +107,7 @@ class Command {
* @param duration the timeout duration
* @return the command with the timeout added
*/
ParallelRaceGroup WithTimeout(units::second_t duration) &&;
virtual ParallelRaceGroup WithTimeout(units::second_t duration) &&;
/**
* Decorates this command with an interrupt condition. If the specified
@@ -118,7 +118,7 @@ class Command {
* @param condition the interrupt condition
* @return the command with the interrupt condition added
*/
ParallelRaceGroup WithInterrupt(std::function<bool()> condition) &&;
virtual ParallelRaceGroup WithInterrupt(std::function<bool()> condition) &&;
/**
* Decorates this command with a runnable to run before this command starts.
@@ -127,7 +127,7 @@ class Command {
* @param requirements the required subsystems
* @return the decorated command
*/
SequentialCommandGroup BeforeStarting(
virtual SequentialCommandGroup BeforeStarting(
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) &&;
@@ -138,7 +138,7 @@ class Command {
* @param requirements the required subsystems
* @return the decorated command
*/
SequentialCommandGroup BeforeStarting(
virtual SequentialCommandGroup BeforeStarting(
std::function<void()> toRun,
wpi::span<Subsystem* const> requirements = {}) &&;
@@ -149,7 +149,7 @@ class Command {
* @param requirements the required subsystems
* @return the decorated command
*/
SequentialCommandGroup AndThen(
virtual SequentialCommandGroup AndThen(
std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements) &&;
@@ -160,7 +160,7 @@ class Command {
* @param requirements the required subsystems
* @return the decorated command
*/
SequentialCommandGroup AndThen(
virtual SequentialCommandGroup AndThen(
std::function<void()> toRun,
wpi::span<Subsystem* const> requirements = {}) &&;
@@ -170,7 +170,7 @@ class Command {
*
* @return the decorated command
*/
PerpetualCommand Perpetually() &&;
virtual PerpetualCommand Perpetually() &&;
/**
* Decorates this command to run "by proxy" by wrapping it in a
@@ -180,7 +180,7 @@ class Command {
*
* @return the decorated command
*/
ProxyScheduleCommand AsProxy();
virtual ProxyScheduleCommand AsProxy();
/**
* Schedules this command.

View File

@@ -65,6 +65,8 @@ class PerpetualCommand : public CommandHelper<CommandBase, PerpetualCommand> {
void End(bool interrupted) override;
PerpetualCommand Perpetually() && override;
private:
std::unique_ptr<Command> m_command;
};

View File

@@ -84,6 +84,15 @@ class SequentialCommandGroup
bool RunsWhenDisabled() const override;
SequentialCommandGroup BeforeStarting(
std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {}) &&
override;
SequentialCommandGroup AndThen(std::function<void()> toRun,
wpi::ArrayRef<Subsystem*> requirements = {}) &&
override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;