WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
ParallelRaceGroup.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#ifdef _WIN32
8#pragma warning(push)
9#pragma warning(disable : 4521)
10#endif
11
12#include <memory>
13#include <type_traits>
14#include <utility>
15#include <vector>
16
19
20namespace wpi::cmd {
21/**
22 * A composition that runs a set of commands in parallel, ending when any one of
23 * the commands ends and interrupting all the others.
24 *
25 * <p>The rules for command compositions apply: command instances that are
26 * passed to it are owned by the composition and cannot be added to any other
27 * composition or scheduled individually, and the composition requires all
28 * subsystems its components require.
29 *
30 * This class is provided by the NewCommands VendorDep
31 */
32class ParallelRaceGroup : public CommandHelper<Command, ParallelRaceGroup> {
33 public:
34 /**
35 * Creates a new ParallelCommandRace. The given commands will be executed
36 * simultaneously, and will "race to the finish" - the first command to finish
37 * ends the entire command, with all other commands being interrupted.
38 *
39 * @param commands the commands to include in this composition.
40 */
41 explicit ParallelRaceGroup(std::vector<std::unique_ptr<Command>>&& commands);
42
43 template <wpi::util::DecayedDerivedFrom<Command>... Commands>
44 explicit ParallelRaceGroup(Commands&&... commands) {
45 AddCommands(std::forward<Commands>(commands)...);
46 }
47
49
50 // No copy constructors for command groups
52
53 // Prevent template expansion from emulating copy ctor
55
56 /**
57 * Adds the given commands to the group.
58 *
59 * @param commands Commands to add to the group.
60 */
61 template <wpi::util::DecayedDerivedFrom<Command>... Commands>
62 void AddCommands(Commands&&... commands) {
63 std::vector<std::unique_ptr<Command>> foo;
64 ((void)foo.emplace_back(std::make_unique<std::decay_t<Commands>>(
65 std::forward<Commands>(commands))),
66 ...);
67 AddCommands(std::move(foo));
68 }
69
70 void Initialize() final;
71
72 void Execute() final;
73
74 void End(bool interrupted) final;
75
76 bool IsFinished() final;
77
78 bool RunsWhenDisabled() const override;
79
80 Command::InterruptionBehavior GetInterruptionBehavior() const override;
81
82 private:
83 void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
84
85 std::vector<std::unique_ptr<Command>> m_commands;
86 bool m_runWhenDisabled{true};
87 Command::InterruptionBehavior m_interruptBehavior{
89 bool m_finished{false};
90 bool isRunning = false;
91};
92} // namespace wpi::cmd
93
94#ifdef _WIN32
95#pragma warning(pop)
96#endif
A state machine representing a complete action to be performed by the robot.
Definition Command.hpp:41
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition Command.hpp:173
@ kCancelIncoming
This command continues, and the incoming command is not scheduled.
Definition Command.hpp:182
ParallelRaceGroup(ParallelRaceGroup &)=delete
bool RunsWhenDisabled() const override
ParallelRaceGroup(std::vector< std::unique_ptr< Command > > &&commands)
Creates a new ParallelCommandRace.
ParallelRaceGroup(const ParallelRaceGroup &)=delete
void End(bool interrupted) final
ParallelRaceGroup(Commands &&... commands)
Definition ParallelRaceGroup.hpp:44
ParallelRaceGroup(ParallelRaceGroup &&other)=default
Command::InterruptionBehavior GetInterruptionBehavior() const override
void AddCommands(Commands &&... commands)
Adds the given commands to the group.
Definition ParallelRaceGroup.hpp:62
Definition StringMap.hpp:773
Definition CommandNiDsStadiaController.hpp:15