WPILibC++  2020.3.2
StartEndCommand.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 StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
27  public:
36  StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
37  std::initializer_list<Subsystem*> requirements);
38 
47  StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
48  wpi::ArrayRef<Subsystem*> requirements = {});
49 
50  StartEndCommand(StartEndCommand&& other) = default;
51 
52  StartEndCommand(const StartEndCommand& other);
53 
54  void Initialize() override;
55 
56  void End(bool interrupted) override;
57 
58  protected:
59  std::function<void()> m_onInit;
60  std::function<void()> m_onEnd;
61 };
62 } // namespace frc2
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
frc2::StartEndCommand::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::StartEndCommand::End
void End(bool interrupted) override
The action to take when the command ends.
frc2::StartEndCommand
A command that runs a given runnable when it is initalized, and another runnable when it ends.
Definition: StartEndCommand.h:26
frc2::StartEndCommand::StartEndCommand
StartEndCommand(std::function< void()> onInit, std::function< void()> onEnd, std::initializer_list< Subsystem * > requirements)
Creates a new StartEndCommand.