WPILibC++  2020.3.2-60-g3011ebe
PerpetualCommand.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 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 #ifdef _WIN32
11 #pragma warning(push)
12 #pragma warning(disable : 4521)
13 #endif
14 
15 #include <memory>
16 #include <utility>
17 
18 #include "frc2/command/CommandBase.h"
19 #include "frc2/command/CommandGroupBase.h"
20 #include "frc2/command/CommandHelper.h"
21 
22 namespace frc2 {
33 class PerpetualCommand : public CommandHelper<CommandBase, PerpetualCommand> {
34  public:
42  explicit PerpetualCommand(std::unique_ptr<Command>&& command);
43 
51  template <class T, typename = std::enable_if_t<std::is_base_of_v<
52  Command, std::remove_reference_t<T>>>>
53  explicit PerpetualCommand(T&& command)
54  : PerpetualCommand(std::make_unique<std::remove_reference_t<T>>(
55  std::forward<T>(command))) {}
56 
57  PerpetualCommand(PerpetualCommand&& other) = default;
58 
59  // No copy constructors for command groups
60  PerpetualCommand(const PerpetualCommand& other) = delete;
61 
62  // Prevent template expansion from emulating copy ctor
64 
65  void Initialize() override;
66 
67  void Execute() override;
68 
69  void End(bool interrupted) override;
70 
71  private:
72  std::unique_ptr<Command> m_command;
73 };
74 } // namespace frc2
75 
76 #ifdef _WIN32
77 #pragma warning(pop)
78 #endif
frc2::PerpetualCommand
A command that runs another command in perpetuity, ignoring that command's end conditions.
Definition: PerpetualCommand.h:33
frc2::PerpetualCommand::Initialize
void Initialize() override
The initial subroutine of a command.
frc2::PerpetualCommand::PerpetualCommand
PerpetualCommand(std::unique_ptr< Command > &&command)
Creates a new PerpetualCommand.
frc2::PerpetualCommand::PerpetualCommand
PerpetualCommand(T &&command)
Creates a new PerpetualCommand.
Definition: PerpetualCommand.h:53
frc2::PerpetualCommand::End
void End(bool interrupted) override
The action to take when the command ends.
frc2::Command
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:52
frc2::PerpetualCommand::Execute
void Execute() override
The main body of a command.
frc2::CommandHelper
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26