WPILibC++  unspecified
ConditionalCommand.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 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 <llvm/Twine.h>
11 
12 #include "Commands/Command.h"
13 #include "Commands/InstantCommand.h"
14 
15 namespace frc {
16 
33 class ConditionalCommand : public Command {
34  public:
35  explicit ConditionalCommand(Command* onTrue, Command* onFalse = nullptr);
36  ConditionalCommand(const llvm::Twine& name, Command* onTrue,
37  Command* onFalse = nullptr);
38  virtual ~ConditionalCommand() = default;
39 
40  protected:
46  virtual bool Condition() = 0;
47 
48  void _Initialize() override;
49  void _Cancel() override;
50  bool IsFinished() override;
51  void Interrupted() override;
52 
53  private:
54  // The Command to execute if Condition() returns true
55  Command* m_onTrue;
56 
57  // The Command to execute if Condition() returns false
58  Command* m_onFalse;
59 
60  // Stores command chosen by condition
61  Command* m_chosenCommand = nullptr;
62 };
63 
64 } // namespace frc
Definition: RobotController.cpp:14
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
bool IsFinished() override
Returns whether this command is finished.
Definition: ConditionalCommand.cpp:78
ConditionalCommand(Command *onTrue, Command *onFalse=nullptr)
Creates a new ConditionalCommand with given onTrue and onFalse Commands.
Definition: ConditionalCommand.cpp:31
virtual bool Condition()=0
The Condition to test to determine which Command to run.
void _Cancel() override
This works like Cancel(), except that it doesn&#39;t throw an exception if it is a part of a command grou...
Definition: ConditionalCommand.cpp:70
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
A ConditionalCommand is a Command that starts one of two commands.
Definition: ConditionalCommand.h:33
void Interrupted() override
Called when the command ends because somebody called Cancel() or another command shared the same requ...
Definition: ConditionalCommand.cpp:83