WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
ConditionalCommand.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2017. 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 <string>
11 
12 #include "Commands/Command.h"
13 #include "Commands/InstantCommand.h"
14 
15 namespace frc {
16 
41 class ConditionalCommand : public Command {
42  public:
43  explicit ConditionalCommand(Command* onTrue,
44  Command* onFalse = new InstantCommand());
45  ConditionalCommand(const std::string& name, Command* onTrue,
46  Command* onFalse = new InstantCommand());
47  virtual ~ConditionalCommand() = default;
48 
49  protected:
55  virtual bool Condition() = 0;
56 
57  void _Initialize() override;
58  void _Cancel() override;
59  bool IsFinished() override;
60  void Interrupted() override;
61 
62  private:
67  Command* m_onTrue;
68 
73  Command* m_onFalse;
74 
78  Command* m_chosenCommand = nullptr;
79 };
80 
81 } // namespace frc
bool IsFinished() override
Returns whether this command is finished.
Definition: ConditionalCommand.cpp:73
This command will execute once, then finish immediately afterward.
Definition: InstantCommand.h:22
ConditionalCommand(Command *onTrue, Command *onFalse=new InstantCommand())
Creates a new ConditionalCommand with given onTrue and onFalse Commands.
Definition: ConditionalCommand.cpp:22
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't throw an exception if it is a part of a command grou...
Definition: ConditionalCommand.cpp:65
The Command class is at the very core of the entire command framework.
Definition: Command.h:52
A ConditionalCommand is a Command that starts one of two commands.
Definition: ConditionalCommand.h:41
void Interrupted() override
Called when the command ends because somebody called cancel() or another command shared the same requ...
Definition: ConditionalCommand.cpp:78