WPILibC++  2020.3.2-60-g3011ebe
FunctionalCommand.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <functional>
11 #include <initializer_list>
12 
13 #include <wpi/ArrayRef.h>
14 
15 #include "frc2/command/CommandBase.h"
16 #include "frc2/command/CommandHelper.h"
17 
18 namespace frc2 {
26 class FunctionalCommand : public CommandHelper<CommandBase, FunctionalCommand> {
27  public:
38  FunctionalCommand(std::function<void()> onInit,
39  std::function<void()> onExecute,
40  std::function<void(bool)> onEnd,
41  std::function<bool()> isFinished,
42  std::initializer_list<Subsystem*> requirements);
43 
54  FunctionalCommand(std::function<void()> onInit,
55  std::function<void()> onExecute,
56  std::function<void(bool)> onEnd,
57  std::function<bool()> isFinished,
58  wpi::ArrayRef<Subsystem*> requirements = {});
59 
60  FunctionalCommand(FunctionalCommand&& other) = default;
61 
62  FunctionalCommand(const FunctionalCommand& other) = default;
63 
64  void Initialize() override;
65 
66  void Execute() override;
67 
68  void End(bool interrupted) override;
69 
70  bool IsFinished() override;
71 
72  private:
73  std::function<void()> m_onInit;
74  std::function<void()> m_onExecute;
75  std::function<void(bool)> m_onEnd;
76  std::function<bool()> m_isFinished;
77 };
78 } // namespace frc2
frc2::FunctionalCommand::Initialize
void Initialize() override
The initial subroutine of a command.
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
frc2::FunctionalCommand::IsFinished
bool IsFinished() override
Whether the command has finished.
frc2::FunctionalCommand::Execute
void Execute() override
The main body of a command.
frc2::FunctionalCommand::End
void End(bool interrupted) override
The action to take when the command ends.
frc2::CommandHelper
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26
frc2::FunctionalCommand
A command that allows the user to pass in functions for each of the basic command methods through the...
Definition: FunctionalCommand.h:26
frc2::FunctionalCommand::FunctionalCommand
FunctionalCommand(std::function< void()> onInit, std::function< void()> onExecute, std::function< void(bool)> onEnd, std::function< bool()> isFinished, std::initializer_list< Subsystem * > requirements)
Creates a new FunctionalCommand.