WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
ProxyCommand.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#include <memory>
8
13
14namespace wpi::cmd {
15/**
16 * Schedules a given command when this command is initialized and ends when it
17 * ends, but does not directly run it. Use this for including a command in a
18 * composition without adding its requirements, <strong>but only if you know
19 * what you are doing. If you are unsure, see <a
20 * href="https://docs.wpilib.org/en/stable/docs/software/commandbased/command-compositions.html#scheduling-other-commands">the
21 * WPILib docs</a> for a complete explanation of proxy semantics.</strong> Do
22 * not proxy a command from a subsystem already required by the composition, or
23 * else the composition will cancel itself when the proxy is reached. If this
24 * command is interrupted, it will cancel the command.
25 *
26 * <p>This class is provided by the NewCommands VendorDep
27 */
28class ProxyCommand : public CommandHelper<Command, ProxyCommand> {
29 public:
30 /**
31 * Creates a new ProxyCommand that schedules the supplied command when
32 * initialized, and ends when it is no longer scheduled. Use this for lazily
33 * creating <strong>proxied</strong> commands at runtime. Proxying should only
34 * be done to escape from composition requirement semantics, so if only
35 * initialization time command construction is needed, use {@link
36 * DeferredCommand} instead.
37 *
38 * @param supplier the command supplier
39 * @deprecated This constructor's similarity to {@link DeferredCommand} is
40 * confusing and opens potential footguns for users who do not fully
41 * understand the semantics and implications of proxying, but who simply want
42 * runtime construction. Users who do know what they are doing and need a
43 * supplier-constructed proxied command should instead defer a proxy command.
44 * @see DeferredCommand
45 */
47 [[deprecated("Defer a proxy command instead.")]]
49
50 /**
51 * Creates a new ProxyCommand that schedules the supplied command when
52 * initialized, and ends when it is no longer scheduled. Use this for lazily
53 * creating <strong>proxied</strong> commands at runtime. Proxying should only
54 * be done to escape from composition requirement semantics, so if only
55 * initialization time command construction is needed, use {@link
56 * DeferredCommand} instead.
57 *
58 * @param supplier the command supplier
59 * @deprecated This constructor's similarity to {@link DeferredCommand} is
60 * confusing and opens potential footguns for users who do not fully
61 * understand the semantics and implications of proxying, but who simply want
62 * runtime construction. Users who do know what they are doing and need a
63 * supplier-constructed proxied command should instead defer a proxy command.
64 * @see DeferredCommand
65 */
66 [[deprecated("Defer a proxy command instead.")]]
69
70 /**
71 * Creates a new ProxyCommand that schedules the given command when
72 * initialized, and ends when it is no longer scheduled.
73 *
74 * @param command the command to run by proxy
75 */
76 explicit ProxyCommand(Command* command);
77
78 /**
79 * Creates a new ProxyCommand that schedules the given command when
80 * initialized, and ends when it is no longer scheduled.
81 *
82 * <p>Note that this constructor passes ownership of the given command to the
83 * returned ProxyCommand.
84 *
85 * @param command the command to schedule
86 */
87 explicit ProxyCommand(std::unique_ptr<Command> command);
88
89 ProxyCommand(ProxyCommand&& other) = default;
90
91 void Initialize() override;
92
93 void End(bool interrupted) override;
94
95 bool IsFinished() override;
96
98
99 private:
100 wpi::util::unique_function<Command*()> m_supplier;
101 Command* m_command = nullptr;
102};
103} // namespace wpi::cmd
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
A state machine representing a complete action to be performed by the robot.
Definition Command.hpp:41
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition CommandPtr.hpp:28
void InitSendable(wpi::util::SendableBuilder &builder) override
WPI_IGNORE_DEPRECATED ProxyCommand(wpi::util::unique_function< Command *()> supplier)
Creates a new ProxyCommand that schedules the supplied command when initialized, and ends when it is ...
WPI_UNIGNORE_DEPRECATED ProxyCommand(Command *command)
Creates a new ProxyCommand that schedules the given command when initialized, and ends when it is no ...
void Initialize() override
ProxyCommand(ProxyCommand &&other)=default
ProxyCommand(wpi::util::unique_function< CommandPtr()> supplier)
Creates a new ProxyCommand that schedules the supplied command when initialized, and ends when it is ...
void End(bool interrupted) override
bool IsFinished() override
ProxyCommand(std::unique_ptr< Command > command)
Creates a new ProxyCommand that schedules the given command when initialized, and ends when it is no ...
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
unique_function is a type-erasing functor similar to std::function.
Definition FunctionExtras.hpp:57
#define WPI_IGNORE_DEPRECATED
Definition deprecated.hpp:15
#define WPI_UNIGNORE_DEPRECATED
Definition deprecated.hpp:26
Definition CommandNiDsStadiaController.hpp:15