WPILibC++  2021.3.1
StartEndCommand.h
1 // Copyright (c) FIRST and other WPILib contributors.
2 // Open Source Software; you can modify and/or share it under the terms of
3 // the WPILib BSD license file in the root directory of this project.
4 
5 #pragma once
6 
7 #include <functional>
8 #include <initializer_list>
9 
10 #include <wpi/ArrayRef.h>
11 
12 #include "frc2/command/CommandBase.h"
13 #include "frc2/command/CommandHelper.h"
14 
15 namespace frc2 {
23 class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
24  public:
33  StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
34  std::initializer_list<Subsystem*> requirements);
35 
44  StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
45  wpi::ArrayRef<Subsystem*> requirements = {});
46 
47  StartEndCommand(StartEndCommand&& other) = default;
48 
49  StartEndCommand(const StartEndCommand& other);
50 
51  void Initialize() override;
52 
53  void End(bool interrupted) override;
54 
55  protected:
56  std::function<void()> m_onInit;
57  std::function<void()> m_onEnd;
58 };
59 } // 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::StartEndCommand
StartEndCommand(std::function< void()> onInit, std::function< void()> onEnd, wpi::ArrayRef< Subsystem * > requirements={})
Creates a new StartEndCommand.
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:23
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 initialized, and another runnable when it ends.
Definition: StartEndCommand.h:23
frc2::StartEndCommand::StartEndCommand
StartEndCommand(std::function< void()> onInit, std::function< void()> onEnd, std::initializer_list< Subsystem * > requirements)
Creates a new StartEndCommand.