WPILibC++ 2024.3.2
ProxyCommand.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#include <memory>
8
10
13
14namespace frc2 {
15/**
16 * Schedules the given command when this command is initialized, and ends when
17 * it ends. Useful for forking off from CommandGroups. If this command is
18 * interrupted, it will cancel the command.
19 *
20 * <p>This class is provided by the NewCommands VendorDep
21 */
22class ProxyCommand : public CommandHelper<Command, ProxyCommand> {
23 public:
24 /**
25 * Creates a new ProxyCommand that schedules the supplied command when
26 * initialized, and ends when it is no longer scheduled. Useful for lazily
27 * creating commands at runtime.
28 *
29 * @param supplier the command supplier
30 */
32
33 /**
34 * Creates a new ProxyCommand that schedules the supplied command when
35 * initialized, and ends when it is no longer scheduled. Useful for lazily
36 * creating commands at runtime.
37 *
38 * @param supplier the command supplier
39 */
41
42 /**
43 * Creates a new ProxyCommand that schedules the given command when
44 * initialized, and ends when it is no longer scheduled.
45 *
46 * @param command the command to run by proxy
47 */
48 explicit ProxyCommand(Command* command);
49
50 /**
51 * Creates a new ProxyCommand that schedules the given command when
52 * initialized, and ends when it is no longer scheduled.
53 *
54 * <p>Note that this constructor passes ownership of the given command to the
55 * returned ProxyCommand.
56 *
57 * @param command the command to schedule
58 */
59 explicit ProxyCommand(std::unique_ptr<Command> command);
60
61 ProxyCommand(ProxyCommand&& other) = default;
62
63 void Initialize() override;
64
65 void End(bool interrupted) override;
66
67 bool IsFinished() override;
68
69 void InitSendable(wpi::SendableBuilder& builder) override;
70
71 private:
72 wpi::unique_function<Command*()> m_supplier;
73 Command* m_command = nullptr;
74};
75} // namespace frc2
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:27
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:41
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition: CommandPtr.h:29
Schedules the given command when this command is initialized, and ends when it ends.
Definition: ProxyCommand.h:22
ProxyCommand(Command *command)
Creates a new ProxyCommand that schedules the given command when initialized, and ends when it is no ...
ProxyCommand(std::unique_ptr< Command > command)
Creates a new ProxyCommand that schedules the given command when initialized, and ends when it is no ...
ProxyCommand(wpi::unique_function< Command *()> supplier)
Creates a new ProxyCommand that schedules the supplied command when initialized, and ends when it is ...
void Initialize() override
void InitSendable(wpi::SendableBuilder &builder) override
bool IsFinished() override
ProxyCommand(ProxyCommand &&other)=default
void End(bool interrupted) override
ProxyCommand(wpi::unique_function< CommandPtr()> supplier)
Creates a new ProxyCommand that schedules the supplied command when initialized, and ends when it is ...
Helper class for building Sendable dashboard representations.
Definition: SendableBuilder.h:21
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:57
Definition: TrapezoidProfileSubsystem.h:12