WPILibC++  2019.1.1-beta-1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <wpi/Twine.h>
11 
12 #include "frc/commands/Command.h"
13 
14 namespace frc {
15 
35 class ConditionalCommand : public Command {
36  public:
43  explicit ConditionalCommand(Command* onTrue, Command* onFalse = nullptr);
44 
52  ConditionalCommand(const wpi::Twine& name, Command* onTrue,
53  Command* onFalse = nullptr);
54 
55  virtual ~ConditionalCommand() = default;
56 
58  ConditionalCommand& operator=(ConditionalCommand&&) = default;
59 
60  protected:
66  virtual bool Condition() = 0;
67 
68  void _Initialize() override;
69  void _Cancel() override;
70  bool IsFinished() override;
71  void _Interrupted() override;
72 
73  private:
74  // The Command to execute if Condition() returns true
75  Command* m_onTrue;
76 
77  // The Command to execute if Condition() returns false
78  Command* m_onFalse;
79 
80  // Stores command chosen by condition
81  Command* m_chosenCommand = nullptr;
82 };
83 
84 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
bool IsFinished() override
Returns whether this command is finished.
void _Cancel() override
This works like Cancel(), except that it doesn't throw an exception if it is a part of a command grou...
ConditionalCommand(Command *onTrue, Command *onFalse=nullptr)
Creates a new ConditionalCommand with given onTrue and onFalse Commands.
virtual bool Condition()=0
The Condition to test to determine which Command to run.
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:35
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79