WPILibC++  2020.3.2
ParallelRaceGroup.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 #include <vector>
18 
19 #include "frc2/command/CommandGroupBase.h"
20 #include "frc2/command/CommandHelper.h"
21 
22 namespace frc2 {
31  : public CommandHelper<CommandGroupBase, ParallelRaceGroup> {
32  public:
40  explicit ParallelRaceGroup(std::vector<std::unique_ptr<Command>>&& commands);
41 
42  template <class... Types,
43  typename = std::enable_if_t<std::conjunction_v<
44  std::is_base_of<Command, std::remove_reference_t<Types>>...>>>
45  explicit ParallelRaceGroup(Types&&... commands) {
46  AddCommands(std::forward<Types>(commands)...);
47  }
48 
49  ParallelRaceGroup(ParallelRaceGroup&& other) = default;
50 
51  // No copy constructors for command groups
52  ParallelRaceGroup(const ParallelRaceGroup&) = delete;
53 
54  // Prevent template expansion from emulating copy ctor
56 
57  template <class... Types>
58  void AddCommands(Types&&... commands) {
59  std::vector<std::unique_ptr<Command>> foo;
60  ((void)foo.emplace_back(std::make_unique<std::remove_reference_t<Types>>(
61  std::forward<Types>(commands))),
62  ...);
63  AddCommands(std::move(foo));
64  }
65 
66  void Initialize() override;
67 
68  void Execute() override;
69 
70  void End(bool interrupted) override;
71 
72  bool IsFinished() override;
73 
74  bool RunsWhenDisabled() const override;
75 
76  private:
77  void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
78 
79  std::vector<std::unique_ptr<Command>> m_commands;
80  bool m_runWhenDisabled{true};
81  bool m_finished{false};
82  bool isRunning = false;
83 };
84 } // namespace frc2
85 
86 #ifdef _WIN32
87 #pragma warning(pop)
88 #endif
frc2::ParallelRaceGroup
A CommandGroup that runs a set of commands in parallel, ending when any one of the commands ends and ...
Definition: ParallelRaceGroup.h:30
frc2::ParallelRaceGroup::RunsWhenDisabled
bool RunsWhenDisabled() const override
Whether the given command should run when the robot is disabled.
frc2::ParallelRaceGroup::Initialize
void Initialize() override
The initial subroutine of a command.
frc2::ParallelRaceGroup::ParallelRaceGroup
ParallelRaceGroup(std::vector< std::unique_ptr< Command >> &&commands)
Creates a new ParallelCommandRace.
frc2::ParallelRaceGroup::End
void End(bool interrupted) override
The action to take when the command ends.
frc2::ParallelRaceGroup::IsFinished
bool IsFinished() override
Whether the command has finished.
frc2::CommandHelper
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26
frc2::ParallelRaceGroup::Execute
void Execute() override
The main body of a command.