WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
DeferredCommand.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 * Defers Command construction to runtime. Runs the command returned by a
17 * supplier when this command is initialized, and ends when it ends. Useful for
18 * performing runtime tasks before creating a new command. If this command is
19 * interrupted, it will cancel the command.
20 *
21 * Note that the supplier <i>must</i> create a new Command each call. For
22 * selecting one of a preallocated set of commands, use SelectCommand.
23 *
24 * <p>This class is provided by the NewCommands VendorDep
25 */
26class DeferredCommand : public CommandHelper<Command, DeferredCommand> {
27 public:
28 /**
29 * Creates a new DeferredCommand that directly runs the supplied command when
30 * initialized, and ends when it ends. Useful for lazily creating commands
31 * when the DeferredCommand is initialized, such as if the supplied command
32 * depends on runtime state. The supplier will be called each time this
33 * command is initialized. The supplier <i>must</i> create a new Command each
34 * call.
35 *
36 * @param supplier The command supplier
37 * @param requirements The command requirements.
38 *
39 */
41 Requirements requirements);
42
43 DeferredCommand(DeferredCommand&& other) = default;
44
45 void Initialize() override;
46
47 void Execute() override;
48
49 void End(bool interrupted) override;
50
51 bool IsFinished() override;
52
54
55 private:
57 std::unique_ptr<Command> m_command;
58};
59} // namespace wpi::cmd
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition CommandPtr.hpp:28
void InitSendable(wpi::util::SendableBuilder &builder) override
void Execute() override
bool IsFinished() override
DeferredCommand(DeferredCommand &&other)=default
void End(bool interrupted) override
void Initialize() override
DeferredCommand(wpi::util::unique_function< CommandPtr()> supplier, Requirements requirements)
Creates a new DeferredCommand that directly runs the supplied command when initialized,...
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition Requirements.hpp:20
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
Definition CommandNiDsStadiaController.hpp:15