WPILibC++  2020.3.2
InstantCommand.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 {
24 class InstantCommand : public CommandHelper<CommandBase, InstantCommand> {
25  public:
33  InstantCommand(std::function<void()> toRun,
34  std::initializer_list<Subsystem*> requirements);
35 
43  InstantCommand(std::function<void()> toRun,
44  wpi::ArrayRef<Subsystem*> requirements = {});
45 
46  InstantCommand(InstantCommand&& other) = default;
47 
48  InstantCommand(const InstantCommand& other) = default;
49 
55 
56  void Initialize() override;
57 
58  bool IsFinished() final;
59 
60  private:
61  std::function<void()> m_toRun;
62 };
63 } // namespace frc2
frc2::InstantCommand::IsFinished
bool IsFinished() final
Whether the command has finished.
frc2::InstantCommand
A Command that runs instantly; it will initialize, execute once, and end on the same iteration of the...
Definition: InstantCommand.h:24
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
frc2::InstantCommand::Initialize
void Initialize() override
The initial subroutine of a command.
frc2::CommandHelper
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26
frc2::InstantCommand::InstantCommand
InstantCommand()
Creates a new InstantCommand with a Runnable that does nothing.