WPILibC++ 2023.4.3
PerpetualCommand.h
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 <utility>
14
17
18namespace frc2 {
19/**
20 * A command that runs another command in perpetuity, ignoring that command's
21 * end conditions. While this class does not extend frc2::CommandGroupBase,
22 * it is still considered a CommandGroup, as it allows one to compose another
23 * command within it; the command instances that are passed to it cannot be
24 * added to any other groups, or scheduled individually.
25 *
26 * <p>As a rule, CommandGroups require the union of the requirements of their
27 * component commands.
28 *
29 * This class is provided by the NewCommands VendorDep
30 *
31 * @deprecated PerpetualCommand violates the assumption that execute() doesn't
32get called after isFinished() returns true -- an assumption that should be
33valid. This was unsafe/undefined behavior from the start, and RepeatCommand
34provides an easy way to achieve similar end results with slightly different (and
35safe) semantics.
36 */
37class PerpetualCommand : public CommandHelper<CommandBase, PerpetualCommand> {
38 public:
39 /**
40 * Creates a new PerpetualCommand. Will run another command in perpetuity,
41 * ignoring that command's end conditions, unless this command itself is
42 * interrupted.
43 *
44 * @param command the command to run perpetually
45 */
46 WPI_DEPRECATED(
47 "PerpetualCommand violates the assumption that execute() doesn't get "
48 "called after isFinished() returns true -- an assumption that should be "
49 "valid."
50 "This was unsafe/undefined behavior from the start, and RepeatCommand "
51 "provides an easy way to achieve similar end results with slightly "
52 "different (and safe) semantics.")
53 explicit PerpetualCommand(std::unique_ptr<Command>&& command);
54 WPI_IGNORE_DEPRECATED
55
56 /**
57 * Creates a new PerpetualCommand. Will run another command in perpetuity,
58 * ignoring that command's end conditions, unless this command itself is
59 * interrupted.
60 *
61 * @param command the command to run perpetually
62 */
63 template <class T, typename = std::enable_if_t<std::is_base_of_v<
65 WPI_DEPRECATED(
66 "PerpetualCommand violates the assumption that execute() doesn't get "
67 "called after isFinished() returns true -- an assumption that should be "
68 "valid."
69 "This was unsafe/undefined behavior from the start, and RepeatCommand "
70 "provides an easy way to achieve similar end results with slightly "
71 "different (and safe) semantics.")
72 explicit PerpetualCommand(T&& command)
73 : PerpetualCommand(std::make_unique<std::remove_reference_t<T>>(
74 std::forward<T>(command))) {}
75 WPI_UNIGNORE_DEPRECATED
76
78
79 // No copy constructors for command groups
80 PerpetualCommand(const PerpetualCommand& other) = delete;
81
82 // Prevent template expansion from emulating copy ctor
84
85 void Initialize() override;
86
87 void Execute() override;
88
89 void End(bool interrupted) override;
90
91 private:
92 std::unique_ptr<Command> m_command;
93};
94} // namespace frc2
95
96#ifdef _WIN32
97#pragma warning(pop)
98#endif
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
and restrictions which apply to each piece of software is included later in this file and or inside of the individual applicable source files The disclaimer of warranty in the WPILib license above applies to all code in and nothing in any of the other licenses gives permission to use the names of FIRST nor the names of the WPILib contributors to endorse or promote products derived from this software The following pieces of software have additional or alternate and or Google Inc All rights reserved Redistribution and use in source and binary with or without are permitted provided that the following conditions are this list of conditions and the following disclaimer *Redistributions in binary form must reproduce the above copyright this list of conditions and the following disclaimer in the documentation and or other materials provided with the distribution *Neither the name of Google Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
Definition: ThirdPartyNotices.txt:131
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:26
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:47
A command that runs another command in perpetuity, ignoring that command's end conditions.
Definition: PerpetualCommand.h:37
PerpetualCommand(const PerpetualCommand &other)=delete
PerpetualCommand(PerpetualCommand &)=delete
void Initialize() override
The initial subroutine of a command.
void Execute() override
The main body of a command.
WPI_UNIGNORE_DEPRECATED PerpetualCommand(PerpetualCommand &&other)=default
void End(bool interrupted) override
The action to take when the command ends.
A command that runs another command repeatedly, restarting it when it ends, until this command is int...
Definition: RepeatCommand.h:31
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:298
typename std::remove_reference< T >::type remove_reference_t
Definition: core.h:303
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
Definition: InstantCommand.h:14
Definition: StdDeque.h:50
constexpr T & get(wpi::array< T, N > &arr) noexcept
Definition: array.h:66